Skip to content

Commit 306d7e5

Browse files
committed
Merge branch 'js/maint-reflog-beyond-horizon'
* js/maint-reflog-beyond-horizon: t1503: fix broken test_must_fail calls rev-parse: tests git rev-parse --verify master@{n}, for various n sha1_name.c: use warning in preference to fprintf(stderr rev-parse: exit with non-zero status if ref@{n} is not valid.
2 parents c208e05 + ba9eab7 commit 306d7e5

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

sha1_name.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ static int get_sha1_1(const char *name, int len, unsigned char *sha1);
342342

343343
static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
344344
{
345-
static const char *warning = "warning: refname '%.*s' is ambiguous.\n";
345+
static const char *warn_msg = "refname '%.*s' is ambiguous.";
346346
char *real_ref = NULL;
347347
int refs_found = 0;
348348
int at, reflog_len;
@@ -390,7 +390,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
390390
return -1;
391391

392392
if (warn_ambiguous_refs && refs_found > 1)
393-
fprintf(stderr, warning, len, str);
393+
warning(warn_msg, len, str);
394394

395395
if (reflog_len) {
396396
int nth, i;
@@ -426,14 +426,14 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
426426
if (read_ref_at(real_ref, at_time, nth, sha1, NULL,
427427
&co_time, &co_tz, &co_cnt)) {
428428
if (at_time)
429-
fprintf(stderr,
430-
"warning: Log for '%.*s' only goes "
431-
"back to %s.\n", len, str,
429+
warning("Log for '%.*s' only goes "
430+
"back to %s.", len, str,
432431
show_date(co_time, co_tz, DATE_RFC2822));
433-
else
434-
fprintf(stderr,
435-
"warning: Log for '%.*s' only has "
436-
"%d entries.\n", len, str, co_cnt);
432+
else {
433+
free(real_ref);
434+
die("Log for '%.*s' only has %d entries.",
435+
len, str, co_cnt);
436+
}
437437
}
438438
}
439439

t/t1503-rev-parse-verify.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,15 @@ test_expect_success 'use --default' '
104104
test_must_fail git rev-parse --verify --default bar
105105
'
106106

107+
test_expect_success 'master@{n} for various n' '
108+
N=$(git reflog | wc -l) &&
109+
Nm1=$((N-1)) &&
110+
Np1=$((N+1)) &&
111+
git rev-parse --verify master@{0} &&
112+
git rev-parse --verify master@{1} &&
113+
git rev-parse --verify master@{$Nm1} &&
114+
test_must_fail git rev-parse --verify master@{$N} &&
115+
test_must_fail git rev-parse --verify master@{$Np1}
116+
'
117+
107118
test_done

t/t1506-rev-parse-diagnosis.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,13 @@ test_expect_success 'incorrect file in :path and :N:path' '
6666
grep "fatal: Path '"'"'disk-only.txt'"'"' exists on disk, but not in the index." error
6767
'
6868

69+
test_expect_success 'invalid @{n} reference' '
70+
test_must_fail git rev-parse master@{99999} >output 2>error &&
71+
test -z "$(cat output)" &&
72+
grep "fatal: Log for [^ ]* only has [0-9][0-9]* entries." error &&
73+
test_must_fail git rev-parse --verify master@{99999} >output 2>error &&
74+
test -z "$(cat output)" &&
75+
grep "fatal: Log for [^ ]* only has [0-9][0-9]* entries." error
76+
'
77+
6978
test_done

0 commit comments

Comments
 (0)