1
- require 'optparse'
1
+ # frozen_string_literal: true
2
+ require "optparse"
2
3
3
4
module GitChain
4
5
module Commands
@@ -19,7 +20,7 @@ def run(options)
19
20
chain = GitChain ::Models ::Chain . from_config ( options [ :chain_name ] )
20
21
raise ( Abort , "Chain '#{ options [ :chain_name ] } ' does not exist." ) if chain . empty?
21
22
22
- log_names = chain . branch_names . map { |b | "{{cyan:#{ b } }}" } . join ( ' -> ' )
23
+ log_names = chain . branch_names . map { |b | "{{cyan:#{ b } }}" } . join ( " -> " )
23
24
puts_debug ( "Rebasing chain {{info:#{ chain . name } }} [#{ log_names } ]" )
24
25
25
26
branches_to_rebase = chain . branches [ 1 ..-1 ]
@@ -29,33 +30,31 @@ def run(options)
29
30
updates = 0
30
31
31
32
branches_to_rebase . each do |branch |
32
- begin
33
- parent_sha = Git . rev_parse ( branch . parent_branch )
34
- if parent_sha == branch . branch_point
35
- puts_debug ( "Branch {{info:#{ branch . name } }} is already up-to-date." )
36
- next
37
- end
38
-
39
- updates += 1
40
-
41
- if parent_sha != branch . branch_point && forwardable_branch_point? ( branch )
42
- puts_info ( "Auto-forwarding #{ branch . name } to #{ branch . parent_branch } " )
43
- Git . set_config ( "branch.#{ branch . name } .branchPoint" , parent_sha )
44
- branch . branch_point = parent_sha
45
- end
46
-
47
- args = [ "rebase" , "--keep-empty" , "--onto" , branch . parent_branch , branch . branch_point , branch . name ]
48
- puts_debug_git ( *args )
49
- Git . exec ( *args )
50
- Git . set_config ( "branch.#{ branch . name } .branchPoint" , parent_sha , scope : :local )
51
- # validate the parameters
52
- rescue GitChain ::Git ::Failure => e
53
- puts_warning ( e . message )
54
-
55
- puts_error ( "Cannot merge #{ branch . name } onto #{ branch . parent_branch } ." )
56
- puts_error ( "Fix the rebase and run {{command:git chain rebase}} again." )
57
- raise ( AbortSilent )
33
+ parent_sha = Git . rev_parse ( branch . parent_branch )
34
+ if parent_sha == branch . branch_point
35
+ puts_debug ( "Branch {{info:#{ branch . name } }} is already up-to-date." )
36
+ next
58
37
end
38
+
39
+ updates += 1
40
+
41
+ if parent_sha != branch . branch_point && forwardable_branch_point? ( branch )
42
+ puts_info ( "Auto-forwarding #{ branch . name } to #{ branch . parent_branch } " )
43
+ Git . set_config ( "branch.#{ branch . name } .branchPoint" , parent_sha )
44
+ branch . branch_point = parent_sha
45
+ end
46
+
47
+ args = [ "rebase" , "--keep-empty" , "--onto" , branch . parent_branch , branch . branch_point , branch . name ]
48
+ puts_debug_git ( *args )
49
+ Git . exec ( *args )
50
+ Git . set_config ( "branch.#{ branch . name } .branchPoint" , parent_sha , scope : :local )
51
+ # validate the parameters
52
+ rescue GitChain ::Git ::Failure => e
53
+ puts_warning ( e . message )
54
+
55
+ puts_error ( "Cannot merge #{ branch . name } onto #{ branch . parent_branch } ." )
56
+ puts_error ( "Fix the rebase and run {{command:git chain rebase}} again." )
57
+ raise ( AbortSilent )
59
58
end
60
59
61
60
if updates . positive?
0 commit comments