Merge branch 'hn/reflog-tests'
Prepare tests on ref API to help testing reftable backends. * hn/reflog-tests: refs/debug: trim trailing LF from reflog message test-ref-store: tweaks to for-each-reflog-ent format t1405: check for_each_reflog_ent_reverse() more thoroughly test-ref-store: don't add newline to reflog message show-branch: show reflog message
This commit is contained in:
commit
250ca49b4f
@ -761,6 +761,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
|
||||
char *logmsg;
|
||||
char *nth_desc;
|
||||
const char *msg;
|
||||
char *end;
|
||||
timestamp_t timestamp;
|
||||
int tz;
|
||||
|
||||
@ -770,11 +771,12 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
|
||||
reflog = i;
|
||||
break;
|
||||
}
|
||||
msg = strchr(logmsg, '\t');
|
||||
if (!msg)
|
||||
msg = "(none)";
|
||||
else
|
||||
msg++;
|
||||
|
||||
end = strchr(logmsg, '\n');
|
||||
if (end)
|
||||
*end = '\0';
|
||||
|
||||
msg = (*logmsg == '\0') ? "(none)" : logmsg;
|
||||
reflog_msg[i] = xstrfmt("(%s) %s",
|
||||
show_date(timestamp, tz,
|
||||
DATE_MODE(RELATIVE)),
|
||||
|
@ -284,6 +284,7 @@ static int debug_print_reflog_ent(struct object_id *old_oid,
|
||||
int ret;
|
||||
char o[GIT_MAX_HEXSZ + 1] = "null";
|
||||
char n[GIT_MAX_HEXSZ + 1] = "null";
|
||||
char *msgend = strchrnul(msg, '\n');
|
||||
if (old_oid)
|
||||
oid_to_hex_r(o, old_oid);
|
||||
if (new_oid)
|
||||
@ -291,8 +292,10 @@ static int debug_print_reflog_ent(struct object_id *old_oid,
|
||||
|
||||
ret = dbg->fn(old_oid, new_oid, committer, timestamp, tz, msg,
|
||||
dbg->cb_data);
|
||||
trace_printf_key(&trace_refs, "reflog_ent %s (ret %d): %s -> %s, %s %ld \"%s\"\n",
|
||||
dbg->refname, ret, o, n, committer, (long int)timestamp, msg);
|
||||
trace_printf_key(&trace_refs,
|
||||
"reflog_ent %s (ret %d): %s -> %s, %s %ld \"%.*s\"\n",
|
||||
dbg->refname, ret, o, n, committer,
|
||||
(long int)timestamp, (int)(msgend - msg), msg);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -152,9 +152,9 @@ static int each_reflog(struct object_id *old_oid, struct object_id *new_oid,
|
||||
const char *committer, timestamp_t timestamp,
|
||||
int tz, const char *msg, void *cb_data)
|
||||
{
|
||||
printf("%s %s %s %"PRItime" %d %s\n",
|
||||
oid_to_hex(old_oid), oid_to_hex(new_oid),
|
||||
committer, timestamp, tz, msg);
|
||||
printf("%s %s %s %" PRItime " %+05d%s%s", oid_to_hex(old_oid),
|
||||
oid_to_hex(new_oid), committer, timestamp, tz,
|
||||
*msg == '\n' ? "" : "\t", msg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -321,8 +321,9 @@ $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000 Switch
|
||||
$B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000
|
||||
EOF
|
||||
test_expect_success "verifying $m's log (logged by touch)" '
|
||||
test_when_finished "rm -rf .git/$m .git/logs expect" &&
|
||||
test_cmp expect .git/logs/$m
|
||||
test_when_finished "git update-ref -d $m && rm -rf .git/logs actual expect" &&
|
||||
test-tool ref-store main for-each-reflog-ent $m >actual &&
|
||||
test_cmp actual expect
|
||||
'
|
||||
|
||||
test_expect_success "create $m (logged by config)" '
|
||||
@ -350,8 +351,9 @@ $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 +0000 Switch
|
||||
$B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000
|
||||
EOF
|
||||
test_expect_success "verifying $m's log (logged by config)" '
|
||||
test_when_finished "rm -f .git/$m .git/logs/$m expect" &&
|
||||
test_cmp expect .git/logs/$m
|
||||
test_when_finished "git update-ref -d $m && rm -rf .git/logs actual expect" &&
|
||||
test-tool ref-store main for-each-reflog-ent $m >actual &&
|
||||
test_cmp actual expect
|
||||
'
|
||||
|
||||
test_expect_success 'set up for querying the reflog' '
|
||||
@ -467,7 +469,8 @@ $h_OTHER $h_FIXED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151040 +0000 co
|
||||
$h_FIXED $h_MERGED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151100 +0000 commit (merge): Merged initial commit and a later commit.
|
||||
EOF
|
||||
test_expect_success 'git commit logged updates' '
|
||||
test_cmp expect .git/logs/$m
|
||||
test-tool ref-store main for-each-reflog-ent $m >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
unset h_TEST h_OTHER h_FIXED h_MERGED
|
||||
|
||||
|
@ -89,13 +89,13 @@ test_expect_success 'for_each_reflog()' '
|
||||
test_expect_success 'for_each_reflog_ent()' '
|
||||
$RUN for-each-reflog-ent HEAD >actual &&
|
||||
head -n1 actual | grep one &&
|
||||
tail -n2 actual | head -n1 | grep recreate-main
|
||||
tail -n1 actual | grep recreate-main
|
||||
'
|
||||
|
||||
test_expect_success 'for_each_reflog_ent_reverse()' '
|
||||
$RUN for-each-reflog-ent-reverse HEAD >actual &&
|
||||
head -n1 actual | grep recreate-main &&
|
||||
tail -n2 actual | head -n1 | grep one
|
||||
tail -n1 actual | grep one
|
||||
'
|
||||
|
||||
test_expect_success 'reflog_exists(HEAD)' '
|
||||
|
@ -75,13 +75,13 @@ test_expect_success 'for_each_reflog()' '
|
||||
test_expect_success 'for_each_reflog_ent()' '
|
||||
$RUN for-each-reflog-ent HEAD >actual &&
|
||||
head -n1 actual | grep first &&
|
||||
tail -n2 actual | head -n1 | grep main.to.new
|
||||
tail -n1 actual | grep main.to.new
|
||||
'
|
||||
|
||||
test_expect_success 'for_each_reflog_ent_reverse()' '
|
||||
$RUN for-each-reflog-ent-reverse HEAD >actual &&
|
||||
head -n1 actual | grep main.to.new &&
|
||||
tail -n2 actual | head -n1 | grep first
|
||||
tail -n1 actual | grep first
|
||||
'
|
||||
|
||||
test_expect_success 'reflog_exists(HEAD)' '
|
||||
|
@ -4,6 +4,9 @@ test_description='test show-branch'
|
||||
|
||||
. ./test-lib.sh
|
||||
|
||||
# arbitrary reference time: 2009-08-30 19:20:00
|
||||
GIT_TEST_DATE_NOW=1251660000; export GIT_TEST_DATE_NOW
|
||||
|
||||
test_expect_success 'setup' '
|
||||
test_commit initial &&
|
||||
for i in $(test_seq 1 10)
|
||||
@ -146,4 +149,16 @@ test_expect_success 'show branch --merge-base with N arguments' '
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'show branch --reflog=2' '
|
||||
sed "s/^> //" >expect <<-\EOF &&
|
||||
> ! [refs/heads/branch10@{0}] (4 years, 5 months ago) commit: branch10
|
||||
> ! [refs/heads/branch10@{1}] (4 years, 5 months ago) commit: branch10
|
||||
> --
|
||||
> + [refs/heads/branch10@{0}] branch10
|
||||
> ++ [refs/heads/branch10@{1}] initial
|
||||
EOF
|
||||
git show-branch --reflog=2 >actual &&
|
||||
test_cmp actual expect
|
||||
'
|
||||
|
||||
test_done
|
||||
|
Loading…
Reference in New Issue
Block a user