Skip to content

Commit 53cae9e

Browse files
committed
Merge branch 'wc/find-commit-with-pattern-on-detached-head'
"git rev-parse ':/substring'" did not consider the history leading only to HEAD when looking for a commit with the given substring, when the HEAD is detached. This has been fixed. * wc/find-commit-with-pattern-on-detached-head: sha1-name.c: for ":/", find detached HEAD commits
2 parents 18a86f3 + 6b3351e commit 53cae9e

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

Documentation/revisions.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ existing tag object.
184184
A colon, followed by a slash, followed by a text, names
185185
a commit whose commit message matches the specified regular expression.
186186
This name returns the youngest matching commit which is
187-
reachable from any ref. The regular expression can match any part of the
187+
reachable from any ref, including HEAD.
188+
The regular expression can match any part of the
188189
commit message. To match messages starting with a string, one can use
189190
e.g. ':/^foo'. The special sequence ':/!' is reserved for modifiers to what
190191
is matched. ':/!-foo' performs a negative match, while ':/!!foo' matches a

sha1-name.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,6 +1650,7 @@ static int get_oid_with_context_1(const char *name,
16501650
struct commit_list *list = NULL;
16511651

16521652
for_each_ref(handle_one_ref, &list);
1653+
head_ref(handle_one_ref, &list);
16531654
commit_list_sort_by_date(&list);
16541655
return get_oid_oneline(name + 2, oid, list);
16551656
}

t/t4208-log-magic-pathspec.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,32 @@ test_expect_success '"git log :/a -- " should not be ambiguous' '
2525
git log :/a --
2626
'
2727

28+
test_expect_success '"git log :/detached -- " should find a commit only in HEAD' '
29+
test_when_finished "git checkout master" &&
30+
git checkout --detach &&
31+
# Must manually call `test_tick` instead of using `test_commit`,
32+
# because the latter additionally creates a tag, which would make
33+
# the commit reachable not only via HEAD.
34+
test_tick &&
35+
git commit --allow-empty -m detached &&
36+
test_tick &&
37+
git commit --allow-empty -m something-else &&
38+
git log :/detached --
39+
'
40+
41+
test_expect_success '"git log :/detached -- " should not find an orphaned commit' '
42+
test_must_fail git log :/detached --
43+
'
44+
45+
test_expect_success '"git log :/detached -- " should find HEAD only of own worktree' '
46+
git worktree add other-tree HEAD &&
47+
git -C other-tree checkout --detach &&
48+
test_tick &&
49+
git -C other-tree commit --allow-empty -m other-detached &&
50+
git -C other-tree log :/other-detached -- &&
51+
test_must_fail git log :/other-detached --
52+
'
53+
2854
test_expect_success '"git log -- :/a" should not be ambiguous' '
2955
git log -- :/a
3056
'

0 commit comments

Comments
 (0)