@@ -76,14 +76,10 @@ fn simple_straightline_commits() {
76
76
let td = assert_fs:: TempDir :: new ( ) . unwrap ( ) ;
77
77
git_init ( & td) ;
78
78
79
- for n in & [ "a" , "b" ] {
80
- git_file_commit ( n, & td) ;
81
- }
79
+ git_commits ( & [ "a" , "b" ] , & td) ;
82
80
git ( & [ "checkout" , "-b" , "changes" ] , & td) ;
83
81
git ( & [ "branch" , "-u" , "main" ] , & td) ;
84
- for n in & [ "target" , "d" ] {
85
- git_file_commit ( & n, & td) ;
86
- }
82
+ git_commits ( & [ "target" , "d" ] , & td) ;
87
83
88
84
let log = git_log ( & td) ;
89
85
assert_eq ! (
@@ -122,14 +118,10 @@ fn test_no_commit_in_range() {
122
118
let td = assert_fs:: TempDir :: new ( ) . unwrap ( ) ;
123
119
git_init ( & td) ;
124
120
125
- for n in & [ "a" , "b" , "c" , "d" ] {
126
- git_file_commit ( n, & td) ;
127
- }
121
+ git_commits ( & [ "a" , "b" , "c" , "d" ] , & td) ;
128
122
git ( & [ "checkout" , "-b" , "changes" , ":/c" ] , & td) ;
129
123
git ( & [ "branch" , "-u" , "main" ] , & td) ;
130
- for n in & [ "target" , "f" , "g" ] {
131
- git_file_commit ( & n, & td) ;
132
- }
124
+ git_commits ( & [ "target" , "f" , "g" ] , & td) ;
133
125
134
126
let out = git_log ( & td) ;
135
127
assert_eq ! (
171
163
) ;
172
164
}
173
165
166
+ #[ test]
167
+ fn retarget_branches_in_range ( ) {
168
+ let td = assert_fs:: TempDir :: new ( ) . unwrap ( ) ;
169
+ git_init ( & td) ;
170
+
171
+ git_commits ( & [ "a" , "b" ] , & td) ;
172
+ git ( & [ "checkout" , "-b" , "intermediate" ] , & td) ;
173
+ git_commits ( & [ "target" , "c" , "d" ] , & td) ;
174
+
175
+ git ( & [ "checkout" , "-b" , "changes" ] , & td) ;
176
+ git_commits ( & [ "e" , "f" ] , & td) ;
177
+
178
+ let expected = "\
179
+ * f HEAD -> changes
180
+ * e
181
+ * d intermediate
182
+ * c
183
+ * target
184
+ * b main
185
+ * a
186
+ " ;
187
+ let out = git_log ( & td) ;
188
+ assert_eq ! ( out, expected, "log:\n {}\n expected:\n {}" , out, expected) ;
189
+
190
+ td. child ( "new" ) . touch ( ) . unwrap ( ) ;
191
+ git ( & [ "add" , "new" ] , & td) ;
192
+
193
+ fixup ( & td) . args ( & [ "-P" , "target" ] ) . assert ( ) . success ( ) ;
194
+
195
+ let ( files, err) = git_changed_files ( "target" , & td) ;
196
+
197
+ assert_eq ! (
198
+ files,
199
+ "\
200
+ file_target
201
+ new
202
+ " ,
203
+ "out: {} err: {}" ,
204
+ files,
205
+ err
206
+ ) ;
207
+
208
+ // should be identical to before
209
+ let out = git_log ( & td) ;
210
+ assert_eq ! ( out, expected, "\n actual:\n {}\n expected:\n {}" , out, expected) ;
211
+ }
212
+
174
213
///////////////////////////////////////////////////////////////////////////////
175
214
// Helpers
176
215
216
+ fn git_commits ( ids : & [ & str ] , tempdir : & assert_fs:: TempDir ) {
217
+ for n in ids {
218
+ git_file_commit ( n, & tempdir) ;
219
+ }
220
+ }
221
+
177
222
fn git_init ( tempdir : & assert_fs:: TempDir ) {
178
223
git ( & [ "init" , "--initial-branch=main" ] , & tempdir) ;
179
224
git ( & [ "config" , "user.email" , "[email protected] " ] , & tempdir
) ;
0 commit comments