checkout.c: use ref_exists instead of file_exist
Change checkout.c to check if a ref exists instead of checking if a loose ref file exists when deciding if to delete an orphaned log file. Otherwise, if a ref only exists as a packed ref without a corresponding loose ref for the currently checked out branch, we risk that the reflog will be deleted when we switch to a different branch. Update the reflog tests to check for this bug. The following reproduces the bug: $ git init-db $ git config core.logallrefupdates true $ git commit -m Initial --allow-empty [master (root-commit) bb11abe] Initial $ git reflog master [8561dcb master@{0}: commit (initial): Initial] $ find .git/{refs,logs} -type f | grep master [.git/refs/heads/master] [.git/logs/refs/heads/master] $ git branch foo $ git pack-refs --all $ find .git/{refs,logs} -type f | grep master [.git/logs/refs/heads/master] $ git checkout foo $ find .git/{refs,logs} -type f | grep master ... reflog file is missing ... $ git reflog master ... nothing ... Signed-off-by: Ronnie Sahlberg <sahlberg@google.com> Acked-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
4da588357a
commit
482b8f3208
@ -245,4 +245,12 @@ test_expect_success 'gc.reflogexpire=false' '
|
||||
|
||||
'
|
||||
|
||||
test_expect_success 'checkout should not delete log for packed ref' '
|
||||
test $(git reflog master | wc -l) = 4 &&
|
||||
git branch foo &&
|
||||
git pack-refs --all &&
|
||||
git checkout foo &&
|
||||
test $(git reflog master | wc -l) = 4
|
||||
'
|
||||
|
||||
test_done
|
||||
|
Reference in New Issue
Block a user