Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
git-show: do not segfault when showing a bad tag
Browse files Browse the repository at this point in the history
When a tag points at a bad or nonexistent object, we should diagnose the
breakage and exit.  An earlier commit 4f3dcc2 (Fix 'git show' on signed
tag of signed tag of commit, 2008-07-01) lost this check and made it
segfault instead; not good.

This fixes it.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
gitster committed Dec 15, 2008
1 parent 544ddb0 commit d2dadfe
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
8 changes: 7 additions & 1 deletion builtin-log.c
Expand Up @@ -356,7 +356,13 @@ int cmd_show(int argc, const char **argv, const char *prefix)
t->tag,
diff_get_color_opt(&rev.diffopt, DIFF_RESET));
ret = show_object(o->sha1, 1, &rev);
objects[i].item = parse_object(t->tagged->sha1);
if (ret)
break;
o = parse_object(t->tagged->sha1);
if (!o)
ret = error("Could not read object %s",
sha1_to_hex(t->tagged->sha1));
objects[i].item = o;
i--;
break;
}
Expand Down
20 changes: 20 additions & 0 deletions t/t7007-show.sh
@@ -0,0 +1,20 @@
#!/bin/sh

test_description='git show'

. ./test-lib.sh

test_expect_success setup '
echo hello world >foo &&
H=$(git hash-object -w foo) &&
git tag -a foo-tag -m "Tags $H" $H &&
HH=$(expr "$H" : "\(..\)") &&
H38=$(expr "$H" : "..\(.*\)") &&
rm -f .git/objects/$HH/$H38
'

test_expect_success 'showing a tag that point at a missing object' '
test_must_fail git --no-pager show foo-tag
'

test_done

0 comments on commit d2dadfe

Please sign in to comment.