fetch: set remote/HEAD if it does not exist
When cloning a repository remote/HEAD is created, but when the user creates a repository with git init, and later adds a remote, remote/HEAD is only created if the user explicitly runs a variant of "remote set-head". Attempt to set remote/HEAD during fetch, if the user does not have it already set. Silently ignore any errors. Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
9963746c84
commit
3f763ddf28
@ -75,6 +75,30 @@ test_expect_success "fetch test for-merge" '
|
||||
cut -f -2 .git/FETCH_HEAD >actual &&
|
||||
test_cmp expected actual'
|
||||
|
||||
test_expect_success "fetch test remote HEAD" '
|
||||
cd "$D" &&
|
||||
cd two &&
|
||||
git fetch &&
|
||||
git rev-parse --verify refs/remotes/origin/HEAD &&
|
||||
git rev-parse --verify refs/remotes/origin/main &&
|
||||
head=$(git rev-parse refs/remotes/origin/HEAD) &&
|
||||
branch=$(git rev-parse refs/remotes/origin/main) &&
|
||||
test "z$head" = "z$branch"'
|
||||
|
||||
test_expect_success "fetch test remote HEAD change" '
|
||||
cd "$D" &&
|
||||
cd two &&
|
||||
git switch -c other &&
|
||||
git push -u origin other &&
|
||||
git rev-parse --verify refs/remotes/origin/HEAD &&
|
||||
git rev-parse --verify refs/remotes/origin/main &&
|
||||
git rev-parse --verify refs/remotes/origin/other &&
|
||||
git remote set-head origin other &&
|
||||
git fetch &&
|
||||
head=$(git rev-parse refs/remotes/origin/HEAD) &&
|
||||
branch=$(git rev-parse refs/remotes/origin/other) &&
|
||||
test "z$head" = "z$branch"'
|
||||
|
||||
test_expect_success 'fetch --prune on its own works as expected' '
|
||||
cd "$D" &&
|
||||
git clone . prune &&
|
||||
|
Reference in New Issue
Block a user