Skip to content

Commit

Permalink
refs: return conflict error when checking packed refs
Browse files Browse the repository at this point in the history
The TRANSACTION_NAME_CONFLICT error code refers to a failure to create a
ref due to a name conflict with another ref. An example of this is a
directory/file conflict such as ref names A/B and A.

"git fetch" uses this error code to more accurately describe the error
by recommending to the user that they try running "git remote prune" to
remove any old refs that are deleted by the remote which would clear up
any directory/file conflicts.

This helpful error message is not displayed when the conflicted ref is
stored in packed refs. This change fixes this by ensuring error return
code consistency in `lock_raw_ref`.

Signed-off-by: Ivan Tse <[email protected]>
  • Loading branch information
ivantsepp committed May 3, 2024
1 parent d4cc1ec commit 58b2cda
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion refs/files-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,10 @@ static int lock_raw_ref(struct files_ref_store *refs,
*/
if (refs_verify_refname_available(
refs->packed_ref_store, refname,
extras, NULL, err))
extras, NULL, err)) {
ret = TRANSACTION_NAME_CONFLICT;
goto error_return;
}
}

ret = 0;
Expand Down
16 changes: 16 additions & 0 deletions t/t5510-fetch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,22 @@ test_expect_success 'branchname D/F conflict resolved by --prune' '
test_cmp expect actual
'

test_expect_success 'branchname D/F conflict rejected with targeted error message' '
git clone . df-conflict-error &&
git branch dir_conflict &&
(
cd df-conflict-error &&
git update-ref refs/remotes/origin/dir_conflict/file HEAD &&
test_must_fail git fetch 2>../err &&
git pack-refs --all &&
test_must_fail git fetch 2>../err-packed
) &&
test_grep "error: some local refs could not be updated; try running" err &&
test_grep " '\''git remote prune origin'\'' to remove any old, conflicting branches" err &&
test_grep "error: some local refs could not be updated; try running" err-packed &&
test_grep " '\''git remote prune origin'\'' to remove any old, conflicting branches" err-packed
'

test_expect_success 'fetching a one-level ref works' '
test_commit extra &&
git reset --hard HEAD^ &&
Expand Down

0 comments on commit 58b2cda

Please sign in to comment.