Skip to content

Commit 9339fca

Browse files
ivantseppgitster
authored andcommitted
refs: return conflict error when checking packed refs
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]> Acked-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 786a3e4 commit 9339fca

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

refs/files-backend.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,8 +794,10 @@ static int lock_raw_ref(struct files_ref_store *refs,
794794
*/
795795
if (refs_verify_refname_available(
796796
refs->packed_ref_store, refname,
797-
extras, NULL, err))
797+
extras, NULL, err)) {
798+
ret = TRANSACTION_NAME_CONFLICT;
798799
goto error_return;
800+
}
799801
}
800802

801803
ret = 0;

t/t5510-fetch.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,22 @@ test_expect_success 'branchname D/F conflict resolved by --prune' '
10911091
test_cmp expect actual
10921092
'
10931093

1094+
test_expect_success 'branchname D/F conflict rejected with targeted error message' '
1095+
git clone . df-conflict-error &&
1096+
git branch dir_conflict &&
1097+
(
1098+
cd df-conflict-error &&
1099+
git update-ref refs/remotes/origin/dir_conflict/file HEAD &&
1100+
test_must_fail git fetch 2>err &&
1101+
test_grep "error: some local refs could not be updated; try running" err &&
1102+
test_grep " ${SQ}git remote prune origin${SQ} to remove any old, conflicting branches" err &&
1103+
git pack-refs --all &&
1104+
test_must_fail git fetch 2>err-packed &&
1105+
test_grep "error: some local refs could not be updated; try running" err-packed &&
1106+
test_grep " ${SQ}git remote prune origin${SQ} to remove any old, conflicting branches" err-packed
1107+
)
1108+
'
1109+
10941110
test_expect_success 'fetching a one-level ref works' '
10951111
test_commit extra &&
10961112
git reset --hard HEAD^ &&

0 commit comments

Comments
 (0)