Skip to content

Commit

Permalink
Merge branch 'js/git-path-head-dot-lock-fix' into jch
Browse files Browse the repository at this point in the history
"git rev-parse --git-path HEAD.lock" did not give the right path
when run in a secondary worktree.

* js/git-path-head-dot-lock-fix:
  git_path(): handle `.lock` files correctly
  t1400: wrap setup code in test case
  • Loading branch information
gitster committed Nov 12, 2019
2 parents 5b4c2ff + 76a53d6 commit befc330
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
6 changes: 6 additions & 0 deletions path.c
Expand Up @@ -11,6 +11,7 @@
#include "path.h"
#include "packfile.h"
#include "object-store.h"
#include "lockfile.h"

static int get_st_mode_bits(const char *path, int *mode)
{
Expand Down Expand Up @@ -362,9 +363,14 @@ static void update_common_dir(struct strbuf *buf, int git_dir_len,
const char *common_dir)
{
char *base = buf->buf + git_dir_len;
int has_lock_suffix = strbuf_strip_suffix(buf, LOCK_SUFFIX);

init_common_trie();
if (trie_find(&common_trie, base, check_common, NULL) > 0)
replace_dir(buf, git_dir_len, common_dir);

if (has_lock_suffix)
strbuf_addstr(buf, LOCK_SUFFIX);
}

void report_linked_checkout_garbage(void)
Expand Down
2 changes: 2 additions & 0 deletions t/t0060-path-utils.sh
Expand Up @@ -285,8 +285,10 @@ test_git_path GIT_OBJECT_DIRECTORY=foo objects/foo foo/foo
test_git_path GIT_OBJECT_DIRECTORY=foo objects2 .git/objects2
test_expect_success 'setup common repository' 'git --git-dir=bar init'
test_git_path GIT_COMMON_DIR=bar index .git/index
test_git_path GIT_COMMON_DIR=bar index.lock .git/index.lock
test_git_path GIT_COMMON_DIR=bar HEAD .git/HEAD
test_git_path GIT_COMMON_DIR=bar logs/HEAD .git/logs/HEAD
test_git_path GIT_COMMON_DIR=bar logs/HEAD.lock .git/logs/HEAD.lock
test_git_path GIT_COMMON_DIR=bar logs/refs/bisect/foo .git/logs/refs/bisect/foo
test_git_path GIT_COMMON_DIR=bar logs/refs bar/logs/refs
test_git_path GIT_COMMON_DIR=bar logs/refs/ bar/logs/refs/
Expand Down
18 changes: 10 additions & 8 deletions t/t1400-update-ref.sh
Expand Up @@ -344,14 +344,16 @@ test_expect_success "verifying $m's log (logged by config)" '
test_cmp expect .git/logs/$m
'

git update-ref $m $D
cat >.git/logs/$m <<EOF
$Z $C $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500
$C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150350 -0500
$A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500
$F $Z $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500
$Z $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 -0500
EOF
test_expect_success 'set up for querying the reflog' '
git update-ref $m $D &&
cat >.git/logs/$m <<-EOF
$Z $C $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500
$C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150350 -0500
$A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500
$F $Z $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500
$Z $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 -0500
EOF
'

ed="Thu, 26 May 2005 18:32:00 -0500"
gd="Thu, 26 May 2005 18:33:00 -0500"
Expand Down

0 comments on commit befc330

Please sign in to comment.