Skip to content

Commit 12a258c

Browse files
peffgitster
authored andcommitted
reject @{-1} not at beginning of object name
Something like foo@{-1} is nonsensical, as the @{-N} syntax is reserved for "the Nth last branch", and is not an actual reflog selector. We should not feed such nonsense to approxidate at all. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d46a830 commit 12a258c

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

sha1_name.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,10 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
399399
unsigned long co_time;
400400
int co_tz, co_cnt;
401401

402+
/* a @{-N} placed anywhere except the start is an error */
403+
if (str[at+2] == '-')
404+
return -1;
405+
402406
/* Is it asking for N-th entry, or approxidate? */
403407
for (i = nth = 0; 0 <= nth && i < reflog_len; i++) {
404408
char ch = str[at+2+i];

t/t1508-at-combinations.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ check "@{u}" upstream-two
4545
check "@{u}@{1}" upstream-one
4646
check "@{-1}@{u}" master-two
4747
check "@{-1}@{u}@{1}" master-one
48-
fail nonsense "@{u}@{-1}"
48+
nonsense "@{u}@{-1}"
4949
nonsense "@{1}@{u}"
5050

5151
test_done

0 commit comments

Comments
 (0)