Skip to content

Commit 97e0b25

Browse files
temp(on disk fixup): Try to fix abandoned branches
This is just a hack to fix one specific test failure. I haven't dug into it, but I assume there is something more interesting happening than the one case I'm patching with `branch -f ...`
1 parent caad2c7 commit 97e0b25

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

git-branchless-lib/src/core/rewrite/plan.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ impl ToString for RebaseCommand {
154154
.iter()
155155
.map(|oid| format!("fixup {oid}"))
156156
.collect::<Vec<String>>();
157-
let mut cleanups = vec![];
158157

159158
// Since 0ca8681, the intermediate commits created as each
160159
// fixup is applied are left behind in the smartlog. This
@@ -177,14 +176,14 @@ impl ToString for RebaseCommand {
177176
// We have to add some additional steps to make sure the
178177
// smartlog and commit metadata are left as the user
179178
// expects.
180-
if pick_oid != original_commit_oid {
179+
let cleanups = if pick_oid != original_commit_oid {
181180
// See above comment related to 0ca8681
182181
picks.insert(
183182
1,
184183
"exec git branchless hook-skip-upstream-applied-commit $(git rev-parse HEAD)".to_string()
185184
);
186185

187-
cleanups = vec![
186+
vec![
188187
// Hide the final squashed commit
189188
"exec git branchless hook-skip-upstream-applied-commit $(git rev-parse HEAD)".to_string(),
190189

@@ -196,8 +195,14 @@ impl ToString for RebaseCommand {
196195
// Finally, register the new final commit as the
197196
// rewritten version of original_commit_oid
198197
format!("exec git branchless hook-skip-upstream-applied-commit {original_commit_oid} $(git rev-parse HEAD)")
199-
];
200-
}
198+
]
199+
} else {
200+
vec![
201+
// HACK force move branches that used to point at original_commit_oid to new HEAD
202+
// FIXME Yuck! The for loop works by word, not by line; will not work for branches w/ spaces ... is that a thing?
203+
format!("exec for BRANCH in $(git branch --points-at {original_commit_oid}); do git branch --force \"$BRANCH\" HEAD; done"),
204+
]
205+
};
201206

202207
picks
203208
.iter()

git-branchless/tests/test_move.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5726,7 +5726,7 @@ fn test_move_fixup_multiple_disconnected_into_ancestor() -> eyre::Result<()> {
57265726
"-x",
57275727
&format!("{}+{}", test3_oid, test5_oid),
57285728
"-d",
5729-
&test1_oid.to_string(),
5729+
"test",
57305730
],
57315731
// Use the same mocked system time as the destination commit to coax
57325732
// the commit hashs to match their in-mem counterparts.
@@ -5740,7 +5740,7 @@ fn test_move_fixup_multiple_disconnected_into_ancestor() -> eyre::Result<()> {
57405740
insta::assert_snapshot!(stdout, @r###"
57415741
O f777ecc (master) create initial.txt
57425742
|
5743-
o 38caaaf create test.txt
5743+
o 38caaaf (test) create test.txt
57445744
|
57455745
o 6783c86 update 2 test.txt
57465746
|
@@ -5750,7 +5750,7 @@ fn test_move_fixup_multiple_disconnected_into_ancestor() -> eyre::Result<()> {
57505750
"###);
57515751

57525752
// diff for "create test.txt"
5753-
let diff = git.get_trimmed_diff("test.txt", "38caaaf")?;
5753+
let diff = git.get_trimmed_diff("test.txt", "test")?;
57545754
insta::assert_snapshot!(diff, @r###"
57555755
@@ -0,0 +1,8 @@
57565756
+# Section A

0 commit comments

Comments
 (0)