Skip to content

Commit

Permalink
Merge branch 'js/git-path-head-dot-lock-fix' into pu
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 Oct 21, 2019
2 parents a9dbe2a + 9f9459b commit 38fe1fc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
4 changes: 2 additions & 2 deletions path.c
Expand Up @@ -268,7 +268,7 @@ static int trie_find(struct trie *root, const char *key, match_fn fn,
int result;
struct trie *child;

if (!*key) {
if (!*key || !strcmp(key, ".lock")) {
/* we have reached the end of the key */
if (root->value && !root->len)
return fn(key, root->value, baton);
Expand All @@ -288,7 +288,7 @@ static int trie_find(struct trie *root, const char *key, match_fn fn,

/* Matched the entire compressed section */
key += i;
if (!*key)
if (!*key || !strcmp(key, ".lock"))
/* End of key */
return fn(key, root->value, baton);

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
15 changes: 15 additions & 0 deletions t/t1500-rev-parse.sh
Expand Up @@ -117,6 +117,21 @@ test_expect_success 'git-path inside sub-dir' '
test_cmp expect actual
'

test_expect_success 'git-path in worktree' '
test_tick &&
git commit --allow-empty -m empty &&
git worktree add --detach wt &&
test_write_lines >expect \
"$(pwd)/.git/worktrees/wt/logs/HEAD" \
"$(pwd)/.git/worktrees/wt/logs/HEAD.lock" \
"$(pwd)/.git/worktrees/wt/index" \
"$(pwd)/.git/worktrees/wt/index.lock" &&
git -C wt rev-parse >actual \
--git-path logs/HEAD --git-path logs/HEAD.lock \
--git-path index --git-path index.lock &&
test_cmp expect actual
'

test_expect_success 'rev-parse --is-shallow-repository in shallow repo' '
test_commit test_commit &&
echo true >expect &&
Expand Down

0 comments on commit 38fe1fc

Please sign in to comment.