Skip to content

Commit 2868ffe

Browse files
committed
fix(push): report modified patches in output
Somewhere along the way, `stg push` stopped correctly reporting to the user when the pushed patch(es) were updated during the push. With this change, when a push causes a new commit to be made for a patch, that patch will be reported in the user-facing output as "(modified)" unless a superceding "(empty)", "(merged)", or "(conflict)" status applies. Fixes: #464
1 parent 3d98d9d commit 2868ffe

File tree

2 files changed

+66
-5
lines changed

2 files changed

+66
-5
lines changed

src/stack/transaction/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,6 @@ impl<'repo> StackTransaction<'repo> {
10901090
conflicts: false,
10911091
})?;
10921092
self.current_tree_id = tree_id;
1093-
push_status = PushStatus::Modified;
10941093
tree_id
10951094
}
10961095
Ok(false) => {
@@ -1131,10 +1130,12 @@ impl<'repo> StackTransaction<'repo> {
11311130
// execute() performs the checkout. Setting the transaction head
11321131
// here ensures that the real stack top will be checked-out.
11331132
self.updated_head = Some(commit.clone());
1134-
} else if push_status != PushStatus::AlreadyMerged
1135-
&& new_tree_id == new_parent_ref.tree()
1136-
{
1137-
push_status = PushStatus::Empty;
1133+
} else if push_status != PushStatus::AlreadyMerged {
1134+
if new_tree_id == new_parent_ref.tree() {
1135+
push_status = PushStatus::Empty;
1136+
} else {
1137+
push_status = PushStatus::Modified;
1138+
}
11381139
}
11391140

11401141
self.updated_patches

t/t1204-push-updated.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/sh
2+
3+
test_description='Test push that must be updated due to previous patch with same changes.'
4+
5+
. ./test-lib.sh
6+
7+
test_expect_success 'Setup patches' '
8+
echo "foo" >foo.txt &&
9+
git add foo.txt &&
10+
git commit -m "initial" &&
11+
stg init &&
12+
cat >foo.txt <<-\EOF &&
13+
foo
14+
.
15+
bar
16+
.
17+
EOF
18+
stg new -rm "p0" &&
19+
cat >foo.txt <<-\EOF &&
20+
foo
21+
.
22+
BAR
23+
bar
24+
.
25+
baz
26+
EOF
27+
stg new -rm "p1"
28+
'
29+
30+
test_expect_success 'Push unmodified patches' '
31+
stg pop -a &&
32+
stg push -a >out &&
33+
cat >expected <<-\EOF &&
34+
+ p0
35+
> p1
36+
EOF
37+
test_cmp expected out
38+
'
39+
40+
test_expect_success 'Move hunk to p0' '
41+
stg goto p0 &&
42+
cat >foo.txt <<-\EOF &&
43+
foo
44+
.
45+
BAR
46+
bar
47+
.
48+
EOF
49+
stg refresh
50+
'
51+
52+
test_expect_success 'Push indicates p1 was modified' '
53+
cat >expected <<-\EOF &&
54+
> p1 (modified)
55+
EOF
56+
stg push p1 >out &&
57+
test_cmp expected out
58+
'
59+
60+
test_done

0 commit comments

Comments
 (0)