Skip to content

Commit dd26eff

Browse files
committed
Improved error when push conflicts with untracked
When pushing a patch that adds a file that conflicts with an untracked file in the working tree, the error stated "Index/worktree dirty" without further elaboration. The error message from `git merge-recursive` is now displayed. This message indicates the particular untracked files that prevent the push's merge from completing. Also add test cases to ensure this behavior. Addresses #193
1 parent 0d9d175 commit dd26eff

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

src/stack/transaction.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,9 +1149,9 @@ impl<'repo> StackTransaction<'repo> {
11491149
push_status = PushStatus::Conflict;
11501150
ours
11511151
}
1152-
Err(_) => {
1152+
Err(e) => {
11531153
return Err(Error::TransactionHalt {
1154-
msg: "Index/worktree dirty".to_string(),
1154+
msg: format!("{e:#}"),
11551155
conflicts: false,
11561156
}
11571157
.into())

t/t1212-push-untracked.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/sh
2+
3+
test_description='Test push conflicting with untracked files'
4+
5+
. ./test-lib.sh
6+
7+
test_expect_success 'Initialize the StGit repository' '
8+
stg init
9+
'
10+
11+
test_expect_success 'Use pop --spill' '
12+
echo aaa > a.txt &&
13+
echo bbb > b.txt &&
14+
stg add a.txt b.txt &&
15+
stg new -rm patch
16+
stg pop --spill &&
17+
git reset &&
18+
stg add b.txt &&
19+
stg new -rm add-b &&
20+
conflict stg push 2>err &&
21+
grep "untracked working tree files would be overwritten by merge" err &&
22+
grep "a.txt" err &&
23+
stg delete add-b &&
24+
rm -f a.txt b.txt
25+
'
26+
27+
test_expect_success 'Use pop and manually create untracked file' '
28+
echo aaa > a.txt &&
29+
command_error stg push 2>err &&
30+
grep "Untracked working tree file .a\.txt. would be overwritten by merge" err
31+
'
32+
33+
test_done

0 commit comments

Comments
 (0)