diff options
author | Ronnie Sahlberg <sahlberg@google.com> | 2014-05-06 15:45:53 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-05-08 14:31:44 -0700 |
commit | 482b8f3208e797f00db58edd7ff0d67275e898f5 (patch) | |
tree | 5d06db528220f8e9e4fc64cdb243a2103fc3cf23 | |
parent | 4da588357a4a8b73f6a8d9c24435dabee74d0a7e (diff) | |
download | git-482b8f3208e797f00db58edd7ff0d67275e898f5.tar.gz git-482b8f3208e797f00db58edd7ff0d67275e898f5.tar.xz |
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>
-rw-r--r-- | builtin/checkout.c | 5 | ||||
-rwxr-xr-x | t/t1410-reflog.sh | 8 |
2 files changed, 9 insertions, 4 deletions
diff --git a/builtin/checkout.c b/builtin/checkout.c index d3fc3a853..c4db4ca93 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -651,10 +651,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts, } } if (old->path && old->name) { - char ref_file[PATH_MAX]; - - git_snpath(ref_file, sizeof(ref_file), "%s", old->path); - if (!file_exists(ref_file) && reflog_exists(old->path)) + if (!ref_exists(old->path) && reflog_exists(old->path)) delete_reflog(old->path); } } diff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh index 236b13a3a..8cab06f90 100755 --- a/t/t1410-reflog.sh +++ b/t/t1410-reflog.sh @@ -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 |