remote set-head: better output for --auto

Currently, set-head --auto will print a message saying "remote/HEAD set
to branch", which implies something was changed.

Change the output of --auto, so the output actually reflects what was
done: a) set a previously unset HEAD, b) change HEAD because remote
changed or c) no updates. As edge cases, if HEAD is changed from
a previous symbolic reference that was not a remote branch, explicitly
call attention to this fact, and also notify the user if the previous
reference was not a symbolic reference.

Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Bence Ferdinandy
2024-11-22 13:28:47 +01:00
committed by Junio C Hamano
parent 4f07c45e25
commit dfe86fa06b
2 changed files with 109 additions and 13 deletions

View File

@ -444,12 +444,63 @@ test_expect_success REFFILES 'set-head --auto failure' '
)
'
test_expect_success 'set-head --auto detects creation' '
(
cd test &&
git update-ref --no-deref -d refs/remotes/origin/HEAD &&
git remote set-head --auto origin >output &&
echo "${SQ}origin/HEAD${SQ} is now created and points to ${SQ}main${SQ}" >expect &&
test_cmp expect output
)
'
test_expect_success 'set-head --auto to update a non symbolic ref' '
(
cd test &&
git update-ref --no-deref -d refs/remotes/origin/HEAD &&
git update-ref refs/remotes/origin/HEAD HEAD &&
HEAD=$(git log --pretty="%H") &&
git remote set-head --auto origin >output &&
echo "${SQ}origin/HEAD${SQ} was detached at ${SQ}${HEAD}${SQ} and now points to ${SQ}main${SQ}" >expect &&
test_cmp expect output
)
'
test_expect_success 'set-head --auto detects no change' '
(
cd test &&
git remote set-head --auto origin >output &&
echo "${SQ}origin/HEAD${SQ} is unchanged and points to ${SQ}main${SQ}" >expect &&
test_cmp expect output
)
'
test_expect_success 'set-head --auto detects change' '
(
cd test &&
git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/ahead &&
git remote set-head --auto origin >output &&
echo "${SQ}origin/HEAD${SQ} has changed from ${SQ}ahead${SQ} and now points to ${SQ}main${SQ}" >expect &&
test_cmp expect output
)
'
test_expect_success 'set-head --auto detects strange ref' '
(
cd test &&
git symbolic-ref refs/remotes/origin/HEAD refs/heads/main &&
git remote set-head --auto origin >output &&
echo "${SQ}origin/HEAD${SQ} used to point to ${SQ}refs/heads/main${SQ} (which is not a remote branch), but now points to ${SQ}main${SQ}" >expect &&
test_cmp expect output
)
'
test_expect_success 'set-head --auto has no problem w/multiple HEADs' '
(
cd test &&
git fetch two "refs/heads/*:refs/remotes/two/*" &&
git remote set-head --auto two >output 2>&1 &&
echo "two/HEAD set to main" >expect &&
echo "${SQ}two/HEAD${SQ} is now created and points to ${SQ}main${SQ}" >expect &&
test_cmp expect output
)
'
@ -468,6 +519,16 @@ test_expect_success 'set-head explicit' '
)
'
test_expect_success 'set-head --auto reports change' '
(
cd test &&
git remote set-head origin side2 &&
git remote set-head --auto origin >output 2>&1 &&
echo "${SQ}origin/HEAD${SQ} has changed from ${SQ}side2${SQ} and now points to ${SQ}main${SQ}" >expect &&
test_cmp expect output
)
'
cat >test/expect <<EOF
Pruning origin
URL: $(pwd)/one