... | ... |
@@ -1406,7 +1406,9 @@ sub parse_ls_tree_line { |
1406 | 1406 |
} |
1407 | 1407 |
|
1408 | 1408 |
sub import_branch { |
1409 |
- my ($self, $user, $project, $branch, $remote_user, $remote_project, $remote_branch) = @_; |
|
1409 |
+ my ($self, $user, $project, $branch, $remote_user, $remote_project, $remote_branch, $opt) = @_; |
|
1410 |
+ |
|
1411 |
+ my $force = $opt->{force}; |
|
1410 | 1412 |
|
1411 | 1413 |
# Git pull |
1412 | 1414 |
my $remote_rep = $self->rep($remote_user, $remote_project); |
... | ... |
@@ -1415,16 +1417,11 @@ sub import_branch { |
1415 | 1417 |
$project, |
1416 | 1418 |
'fetch', |
1417 | 1419 |
$remote_rep, |
1418 |
- "refs/heads/$remote_branch:refs/heads/$branch" |
|
1420 |
+ ($force ? '+' : '') . "refs/heads/$remote_branch:refs/heads/$branch" |
|
1419 | 1421 |
); |
1420 |
- open my $fh, '-|', @cmd |
|
1421 |
- or croak 'Open git fetch failed'; |
|
1422 | 1422 |
|
1423 |
- # Output |
|
1424 |
- local $/ = "\0"; |
|
1425 |
- my $content = $self->_dec(scalar <$fh>); |
|
1426 |
- warn $content; |
|
1427 |
- close $fh or croak "Can't read git fetch result"; |
|
1423 |
+ system(@cmd) == 0 |
|
1424 |
+ or croak 'Open git fetch for import_branch failed'; |
|
1428 | 1425 |
} |
1429 | 1426 |
|
1430 | 1427 |
sub search_bin { |
... | ... |
@@ -6,8 +6,6 @@ |
6 | 6 |
|
7 | 7 |
# Branches |
8 | 8 |
my $git = app->git; |
9 |
- my $branches = $git->branches($user, $project); |
|
10 |
- my $branch_names = [map { $_->{name} } @$branches]; |
|
11 | 9 |
my $remote_branches = $git->branches($remote_user, $remote_project); |
12 | 10 |
my $remote_branch_names = [map { $_->{name} } @$remote_branches]; |
13 | 11 |
|
... | ... |
@@ -36,6 +34,9 @@ |
36 | 34 |
], |
37 | 35 |
remote_branch => [ |
38 | 36 |
['not_blank' => 'Remote branch name is empty.'] |
37 |
+ ], |
|
38 |
+ force => {require => 0} => [ |
|
39 |
+ 'any' |
|
39 | 40 |
] |
40 | 41 |
]; |
41 | 42 |
my $vresult = app->validator->validate($params, $rule); |
... | ... |
@@ -43,31 +44,42 @@ |
43 | 44 |
if ($vresult->is_ok) { |
44 | 45 |
my $safe_params = $vresult->data; |
45 | 46 |
|
47 |
+ # Valid paramters |
|
46 | 48 |
my $user = $safe_params->{user}; |
47 | 49 |
my $project = $safe_params->{project}; |
48 | 50 |
my $branch = $safe_params->{branch}; |
49 | 51 |
my $remote_user = $safe_params->{remote_user}; |
50 | 52 |
my $remote_project = $safe_params->{remote_project}; |
51 | 53 |
my $remote_branch = $safe_params->{remote_branch}; |
54 |
+ my $force = $safe_params->{force}; |
|
52 | 55 |
|
53 |
- eval { |
|
54 |
- $git->import_branch( |
|
55 |
- $user, |
|
56 |
- $project, |
|
57 |
- $branch, |
|
58 |
- $remote_user, |
|
59 |
- $remote_project, |
|
60 |
- $remote_branch |
|
61 |
- ); |
|
62 |
- }; |
|
56 |
+ # Check branch name |
|
57 |
+ my $branches = $git->branches($user, $project); |
|
63 | 58 |
|
64 |
- if ($@) { |
|
65 |
- $errors = ['Internal Error']; |
|
59 |
+ if (!$force && grep { $branch eq $_->{name} } @$branches) { |
|
60 |
+ $errors = ["Branch \"$branch\" is already exists. If you want to import this branch, check force option."]; |
|
66 | 61 |
} |
67 | 62 |
else { |
68 |
- flash(message => "Success: import \"$remote_user / $remote_project / $remote_branch\" into \"$user / $project / $branch\""); |
|
69 |
- $self->redirect_to('current'); |
|
70 |
- return; |
|
63 |
+ eval { |
|
64 |
+ $git->import_branch( |
|
65 |
+ $user, |
|
66 |
+ $project, |
|
67 |
+ $branch, |
|
68 |
+ $remote_user, |
|
69 |
+ $remote_project, |
|
70 |
+ $remote_branch, |
|
71 |
+ {force => $force} |
|
72 |
+ ); |
|
73 |
+ }; |
|
74 |
+ |
|
75 |
+ if ($@) { |
|
76 |
+ $errors = ['Internal Error']; |
|
77 |
+ } |
|
78 |
+ else { |
|
79 |
+ flash(message => "Success: " . ($force ? 'force ' : '') . "import \"$remote_user / $remote_project / $remote_branch\" into \"$user / $project / $branch\""); |
|
80 |
+ $self->redirect_to('current'); |
|
81 |
+ return; |
|
82 |
+ } |
|
71 | 83 |
} |
72 | 84 |
} |
73 | 85 |
else { |
... | ... |
@@ -118,9 +130,19 @@ |
118 | 130 |
%= text_field 'branch', placeholder => "Branch name", style => "margin-top:12px;width:250px"; |
119 | 131 |
<button name="copy-branch-name", class="btn" style="font-size:12px; padding-left:3px;padding-right:3px;color:#666">Copy Branch Name</button> |
120 | 132 |
</div> |
121 |
- <div> |
|
122 |
- %= submit_button 'Import', style => "width:100px;margin-top:10px;", class => "btn"; |
|
123 |
- </div> |
|
133 |
+ <table style="width:100%"> |
|
134 |
+ <tr> |
|
135 |
+ <td style="width:80px;text-align:right"> |
|
136 |
+ %= submit_button 'Import', class => "btn"; |
|
137 |
+ </td> |
|
138 |
+ <td style="width:20px;"> |
|
139 |
+ <%= check_box force => 1 %> |
|
140 |
+ </td> |
|
141 |
+ <td style="font-size:13px;padding-top:7px;text-align:left"> |
|
142 |
+ Force |
|
143 |
+ </td> |
|
144 |
+ </tr> |
|
145 |
+ </table> |
|
124 | 146 |
</div> |
125 | 147 |
</div> |
126 | 148 |
<div class="span1"> |