Skip to content

Commit bd10c45

Browse files
committed
Merge branch 'ps/report-failure-from-git-stash' into maint-2.43
"git stash" sometimes was silent even when it failed due to unwritable index file, which has been corrected. * ps/report-failure-from-git-stash: builtin/stash: report failure to write to index
2 parents 07fa383 + d2058cb commit bd10c45

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed

builtin/stash.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ static void unstage_changes_unless_new(struct object_id *orig_tree)
520520
repo_hold_locked_index(the_repository, &lock, LOCK_DIE_ON_ERROR);
521521
if (write_locked_index(&the_index, &lock,
522522
COMMIT_LOCK | SKIP_IF_UNCHANGED))
523-
die(_("Unable to write index."));
523+
die(_("could not write index"));
524524
}
525525

526526
static int do_apply_stash(const char *prefix, struct stash_info *info,
@@ -537,7 +537,7 @@ static int do_apply_stash(const char *prefix, struct stash_info *info,
537537
repo_read_index_preload(the_repository, NULL, 0);
538538
if (repo_refresh_and_write_index(the_repository, REFRESH_QUIET, 0, 0,
539539
NULL, NULL, NULL))
540-
return -1;
540+
return error(_("could not write index"));
541541

542542
if (write_index_as_tree(&c_tree, &the_index, get_index_file(), 0,
543543
NULL))
@@ -1364,7 +1364,7 @@ static int do_create_stash(const struct pathspec *ps, struct strbuf *stash_msg_b
13641364
repo_read_index_preload(the_repository, NULL, 0);
13651365
if (repo_refresh_and_write_index(the_repository, REFRESH_QUIET, 0, 0,
13661366
NULL, NULL, NULL) < 0) {
1367-
ret = -1;
1367+
ret = error(_("could not write index"));
13681368
goto done;
13691369
}
13701370

@@ -1555,7 +1555,7 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
15551555

15561556
if (repo_refresh_and_write_index(the_repository, REFRESH_QUIET, 0, 0,
15571557
NULL, NULL, NULL)) {
1558-
ret = -1;
1558+
ret = error(_("could not write index"));
15591559
goto done;
15601560
}
15611561

t/t3903-stash.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,4 +1516,56 @@ test_expect_success 'restore untracked files even when we hit conflicts' '
15161516
)
15171517
'
15181518

1519+
test_expect_success 'stash create reports a locked index' '
1520+
test_when_finished "rm -rf repo" &&
1521+
git init repo &&
1522+
(
1523+
cd repo &&
1524+
test_commit A A.file &&
1525+
echo change >A.file &&
1526+
touch .git/index.lock &&
1527+
1528+
cat >expect <<-EOF &&
1529+
error: could not write index
1530+
EOF
1531+
test_must_fail git stash create 2>err &&
1532+
test_cmp expect err
1533+
)
1534+
'
1535+
1536+
test_expect_success 'stash push reports a locked index' '
1537+
test_when_finished "rm -rf repo" &&
1538+
git init repo &&
1539+
(
1540+
cd repo &&
1541+
test_commit A A.file &&
1542+
echo change >A.file &&
1543+
touch .git/index.lock &&
1544+
1545+
cat >expect <<-EOF &&
1546+
error: could not write index
1547+
EOF
1548+
test_must_fail git stash push 2>err &&
1549+
test_cmp expect err
1550+
)
1551+
'
1552+
1553+
test_expect_success 'stash apply reports a locked index' '
1554+
test_when_finished "rm -rf repo" &&
1555+
git init repo &&
1556+
(
1557+
cd repo &&
1558+
test_commit A A.file &&
1559+
echo change >A.file &&
1560+
git stash push &&
1561+
touch .git/index.lock &&
1562+
1563+
cat >expect <<-EOF &&
1564+
error: could not write index
1565+
EOF
1566+
test_must_fail git stash apply 2>err &&
1567+
test_cmp expect err
1568+
)
1569+
'
1570+
15191571
test_done

0 commit comments

Comments
 (0)