Skip to content

Commit 9455397

Browse files
hanyang-tonygitster
authored andcommitted
read-cache: report lock error when refreshing index
In the repo_refresh_and_write_index of read-cache.c, we return -1 to indicate that writing the index to disk failed. However, callers do not use this information. Commands such as stash print "could not write index" and then exit, which does not help to discover the exact problem. We can let repo_hold_locked_index print the error message if the locking failed. Signed-off-by: Han Young <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 16bd9f2 commit 9455397

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

read-cache.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1456,7 +1456,8 @@ int repo_refresh_and_write_index(struct repository *repo,
14561456
struct lock_file lock_file = LOCK_INIT;
14571457
int fd, ret = 0;
14581458

1459-
fd = repo_hold_locked_index(repo, &lock_file, 0);
1459+
fd = repo_hold_locked_index(repo, &lock_file,
1460+
gentle ? 0 : LOCK_REPORT_ON_ERROR);
14601461
if (!gentle && fd < 0)
14611462
return -1;
14621463
if (refresh_index(repo->index, refresh_flags, pathspec, seen, header_msg))

t/t3903-stash.sh

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,11 +1549,9 @@ test_expect_success 'stash create reports a locked index' '
15491549
echo change >A.file &&
15501550
touch .git/index.lock &&
15511551
1552-
cat >expect <<-EOF &&
1553-
error: could not write index
1554-
EOF
15551552
test_must_fail git stash create 2>err &&
1556-
test_cmp expect err
1553+
test_grep "error: could not write index" err &&
1554+
test_grep "error: Unable to create '.*index.lock'" err
15571555
)
15581556
'
15591557

@@ -1566,11 +1564,9 @@ test_expect_success 'stash push reports a locked index' '
15661564
echo change >A.file &&
15671565
touch .git/index.lock &&
15681566
1569-
cat >expect <<-EOF &&
1570-
error: could not write index
1571-
EOF
15721567
test_must_fail git stash push 2>err &&
1573-
test_cmp expect err
1568+
test_grep "error: could not write index" err &&
1569+
test_grep "error: Unable to create '.*index.lock'" err
15741570
)
15751571
'
15761572

@@ -1584,11 +1580,9 @@ test_expect_success 'stash apply reports a locked index' '
15841580
git stash push &&
15851581
touch .git/index.lock &&
15861582
1587-
cat >expect <<-EOF &&
1588-
error: could not write index
1589-
EOF
15901583
test_must_fail git stash apply 2>err &&
1591-
test_cmp expect err
1584+
test_grep "error: could not write index" err &&
1585+
test_grep "error: Unable to create '.*index.lock'" err
15921586
)
15931587
'
15941588

0 commit comments

Comments
 (0)