@@ -15,6 +15,12 @@ pub fn merge_upstream_rebase(
15
15
scope_time ! ( "merge_upstream_rebase" ) ;
16
16
17
17
let repo = utils:: repo ( repo_path) ?;
18
+ if super :: get_branch_name_repo ( & repo) ? != branch_name {
19
+ return Err ( Error :: Generic ( String :: from (
20
+ "can only rebase in head branch" ,
21
+ ) ) ) ;
22
+ }
23
+
18
24
let branch = repo. find_branch ( branch_name, BranchType :: Local ) ?;
19
25
let upstream = branch. upstream ( ) ?;
20
26
let upstream_commit = upstream. get ( ) . peel_to_commit ( ) ?;
@@ -24,36 +30,34 @@ pub fn merge_upstream_rebase(
24
30
let branch_commit = branch. get ( ) . peel_to_commit ( ) ?;
25
31
let annotated_branch =
26
32
repo. find_annotated_commit ( branch_commit. id ( ) ) ?;
33
+ dbg ! ( annotated_branch. id( ) ) ;
27
34
28
- let rebase = repo. rebase (
29
- Some ( & annotated_branch) ,
30
- Some ( & annotated_upstream) ,
31
- None ,
32
- None ,
33
- ) ?;
35
+ let mut rebase =
36
+ repo. rebase ( None , Some ( & annotated_upstream) , None , None ) ?;
34
37
35
38
let signature =
36
39
crate :: sync:: commit:: signature_allow_undefined_name ( & repo) ?;
37
40
38
- for e in rebase {
39
- let _op = e?;
40
- // dbg!(op.id());
41
- // dbg!(op.kind());
42
- }
41
+ while let Some ( op) = rebase. next ( ) {
42
+ let op = op?;
43
+ dbg ! ( op. id( ) ) ;
43
44
44
- let mut rebase = repo. open_rebase ( None ) ?;
45
+ if repo. index ( ) ?. has_conflicts ( ) {
46
+ rebase. abort ( ) ?;
47
+ return Err ( Error :: Generic ( String :: from (
48
+ "conflicts while merging" ,
49
+ ) ) ) ;
50
+ }
45
51
46
- if repo. index ( ) ?. has_conflicts ( ) {
47
- rebase. abort ( ) ?;
52
+ let commit = rebase. commit ( None , & signature, None ) ?;
53
+ dbg ! ( commit) ;
54
+ }
48
55
49
- Err ( Error :: Generic ( String :: from ( "conflicts while merging" ) ) )
50
- } else {
51
- rebase. commit ( None , & signature, None ) ?;
56
+ rebase. finish ( Some ( & signature) ) ?;
52
57
53
- rebase . finish ( Some ( & signature ) ) ?;
58
+ repo . index ( ) ? . read ( true ) ?;
54
59
55
- Ok ( ( ) )
56
- }
60
+ Ok ( ( ) )
57
61
}
58
62
59
63
#[ cfg( test) ]
@@ -97,9 +101,13 @@ mod test {
97
101
let _commit1 =
98
102
write_commit_file ( & clone1, "test.txt" , "test" , "commit1" ) ;
99
103
104
+ assert_eq ! ( clone1. head_detached( ) . unwrap( ) , false ) ;
105
+
100
106
push ( clone1_dir, "origin" , "master" , false , None , None )
101
107
. unwrap ( ) ;
102
108
109
+ assert_eq ! ( clone1. head_detached( ) . unwrap( ) , false ) ;
110
+
103
111
// clone2
104
112
105
113
let ( clone2_dir, clone2) =
@@ -114,9 +122,13 @@ mod test {
114
122
"commit2" ,
115
123
) ;
116
124
125
+ assert_eq ! ( clone2. head_detached( ) . unwrap( ) , false ) ;
126
+
117
127
push ( clone2_dir, "origin" , "master" , false , None , None )
118
128
. unwrap ( ) ;
119
129
130
+ assert_eq ! ( clone2. head_detached( ) . unwrap( ) , false ) ;
131
+
120
132
// clone1
121
133
122
134
let _commit3 = write_commit_file (
@@ -126,6 +138,8 @@ mod test {
126
138
"commit3" ,
127
139
) ;
128
140
141
+ assert_eq ! ( clone1. head_detached( ) . unwrap( ) , false ) ;
142
+
129
143
//lets fetch from origin
130
144
let bytes =
131
145
fetch_origin ( clone1_dir, "master" , None , None ) . unwrap ( ) ;
@@ -141,12 +155,13 @@ mod test {
141
155
142
156
// debug_cmd_print(clone1_dir, "git log");
143
157
158
+ assert_eq ! ( clone1. head_detached( ) . unwrap( ) , false ) ;
159
+
144
160
merge_upstream_rebase ( clone1_dir, "master" ) . unwrap ( ) ;
145
161
146
162
debug_cmd_print ( clone1_dir, "git log" ) ;
147
163
148
164
let state = crate :: sync:: repo_state ( clone1_dir) . unwrap ( ) ;
149
-
150
165
assert_eq ! ( state, RepoState :: Clean ) ;
151
166
152
167
let commits = get_commit_msgs ( & clone1) ;
@@ -158,6 +173,8 @@ mod test {
158
173
String :: from( "commit1" )
159
174
]
160
175
) ;
176
+
177
+ assert_eq ! ( clone1. head_detached( ) . unwrap( ) , false ) ;
161
178
}
162
179
163
180
#[ test]
0 commit comments