Skip to content

Commit a2b0451

Browse files
committed
Merge branch 'js/git-path-head-dot-lock-fix'
"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
2 parents 0be5caf + 76a53d6 commit a2b0451

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

path.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "path.h"
1212
#include "packfile.h"
1313
#include "object-store.h"
14+
#include "lockfile.h"
1415

1516
static int get_st_mode_bits(const char *path, int *mode)
1617
{
@@ -362,9 +363,14 @@ static void update_common_dir(struct strbuf *buf, int git_dir_len,
362363
const char *common_dir)
363364
{
364365
char *base = buf->buf + git_dir_len;
366+
int has_lock_suffix = strbuf_strip_suffix(buf, LOCK_SUFFIX);
367+
365368
init_common_trie();
366369
if (trie_find(&common_trie, base, check_common, NULL) > 0)
367370
replace_dir(buf, git_dir_len, common_dir);
371+
372+
if (has_lock_suffix)
373+
strbuf_addstr(buf, LOCK_SUFFIX);
368374
}
369375

370376
void report_linked_checkout_garbage(void)

t/t0060-path-utils.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,10 @@ test_git_path GIT_OBJECT_DIRECTORY=foo objects/foo foo/foo
285285
test_git_path GIT_OBJECT_DIRECTORY=foo objects2 .git/objects2
286286
test_expect_success 'setup common repository' 'git --git-dir=bar init'
287287
test_git_path GIT_COMMON_DIR=bar index .git/index
288+
test_git_path GIT_COMMON_DIR=bar index.lock .git/index.lock
288289
test_git_path GIT_COMMON_DIR=bar HEAD .git/HEAD
289290
test_git_path GIT_COMMON_DIR=bar logs/HEAD .git/logs/HEAD
291+
test_git_path GIT_COMMON_DIR=bar logs/HEAD.lock .git/logs/HEAD.lock
290292
test_git_path GIT_COMMON_DIR=bar logs/refs/bisect/foo .git/logs/refs/bisect/foo
291293
test_git_path GIT_COMMON_DIR=bar logs/refs bar/logs/refs
292294
test_git_path GIT_COMMON_DIR=bar logs/refs/ bar/logs/refs/

t/t1400-update-ref.sh

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -344,14 +344,16 @@ test_expect_success "verifying $m's log (logged by config)" '
344344
test_cmp expect .git/logs/$m
345345
'
346346

347-
git update-ref $m $D
348-
cat >.git/logs/$m <<EOF
349-
$Z $C $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500
350-
$C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150350 -0500
351-
$A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500
352-
$F $Z $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500
353-
$Z $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 -0500
354-
EOF
347+
test_expect_success 'set up for querying the reflog' '
348+
git update-ref $m $D &&
349+
cat >.git/logs/$m <<-EOF
350+
$Z $C $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500
351+
$C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150350 -0500
352+
$A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500
353+
$F $Z $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500
354+
$Z $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 -0500
355+
EOF
356+
'
355357

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

0 commit comments

Comments
 (0)