reset $pathspec: exit with code 0 if successful
"git reset $pathspec" currently exits with a non-zero exit code if the worktree is dirty after resetting, which is inconsistent with reset without pathspec, and it makes it harder to know whether the command really failed. Change it to exit with code 0 regardless of whether the worktree is dirty so that non-zero indicates an error. This makes the 4 "disambiguation" test cases in t7102 clearer since they all used to "fail", 3 of which "failed" due to changes in the work tree. Now only the ambiguous one fails. Signed-off-by: Martin von Zweigbergk <martinvonz@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Martin von Zweigbergk committed
Jan 14, 2013 at 21:47 UTC
d94c5e2fa24dce13a3dc1ba178f381cb09bb0853
3 files changed
+16
-12
builtin/reset.c
+3
-5
@@ -119,19 +119,17 @@ static void print_new_head_line(struct commit *commit)
119
120
static int update_index_refresh(int fd, struct lock_file *index_lock, int flags)
121
{
122
- int result;
123
-
122
if (!index_lock) {
123
index_lock = xcalloc(1, sizeof(struct lock_file));
124
fd = hold_locked_index(index_lock, 1);
125
}
126
129
- result = refresh_index(&the_index, (flags), NULL, NULL,
130
- _("Unstaged changes after reset:")) ? 1 : 0;
127
+ refresh_index(&the_index, (flags), NULL, NULL,
128
+ _("Unstaged changes after reset:"));
129
if (write_cache(fd, active_cache, active_nr) ||
130
commit_locked_index(index_lock))
131
return error ("Could not refresh index");
134
- return result;
132
+ return 0;
133
}
134
135
static void update_index_from_diff(struct diff_queue_struct *q,
t/t2013-checkout-submodule.sh
+1
-1
@@ -23,7 +23,7 @@ test_expect_success '"reset <submodule>" updates the index' '
23
git update-index --refresh &&
24
git diff-files --quiet &&
25
git diff-index --quiet --cached HEAD &&
26
- test_must_fail git reset HEAD^ submodule &&
26
+ git reset HEAD^ submodule &&
27
test_must_fail git diff-files --quiet &&
28
git reset submodule &&
29
git diff-files --quiet
t/t7102-reset.sh
+12
-6
@@ -388,7 +388,8 @@ test_expect_success 'test --mixed <paths>' '
388
echo 4 > file4 &&
389
echo 5 > file1 &&
390
git add file1 file3 file4 &&
391
- test_must_fail git reset HEAD -- file1 file2 file3 &&
391
+ git reset HEAD -- file1 file2 file3 &&
392
+ test_must_fail git diff --quiet &&
393
git diff > output &&
394
test_cmp output expect &&
395
git diff --cached > output &&
@@ -402,7 +403,8 @@ test_expect_success 'test resetting the index at give paths' '
403
>sub/file2 &&
404
git update-index --add sub/file1 sub/file2 &&
405
T=$(git write-tree) &&
405
- test_must_fail git reset HEAD sub/file2 &&
406
+ git reset HEAD sub/file2 &&
407
+ test_must_fail git diff --quiet &&
408
U=$(git write-tree) &&
409
echo "$T" &&
410
echo "$U" &&
@@ -440,7 +442,8 @@ test_expect_success 'resetting specific path that is unmerged' '
442
echo "100644 $F3 3 file2"
443
} | git update-index --index-info &&
444
git ls-files -u &&
443
- test_must_fail git reset HEAD file2 &&
445
+ git reset HEAD file2 &&
446
+ test_must_fail git diff --quiet &&
447
git diff-index --exit-code --cached HEAD
448
'
449
@@ -449,7 +452,8 @@ test_expect_success 'disambiguation (1)' '
452
git reset --hard &&
453
>secondfile &&
454
git add secondfile &&
452
- test_must_fail git reset secondfile &&
455
+ git reset secondfile &&
456
+ test_must_fail git diff --quiet -- secondfile &&
457
test -z "$(git diff --cached --name-only)" &&
458
test -f secondfile &&
459
test ! -s secondfile
@@ -474,7 +478,8 @@ test_expect_success 'disambiguation (3)' '
478
>secondfile &&
479
git add secondfile &&
480
rm -f secondfile &&
477
- test_must_fail git reset HEAD secondfile &&
481
+ git reset HEAD secondfile &&
482
+ test_must_fail git diff --quiet &&
483
test -z "$(git diff --cached --name-only)" &&
484
test ! -f secondfile
485
@@ -486,7 +491,8 @@ test_expect_success 'disambiguation (4)' '
491
>secondfile &&
492
git add secondfile &&
493
rm -f secondfile &&
489
- test_must_fail git reset -- secondfile &&
494
+ git reset -- secondfile &&
495
+ test_must_fail git diff --quiet &&
496
test -z "$(git diff --cached --name-only)" &&
497
test ! -f secondfile
498
'