fast-import: don't allow to note on empty branch

'reset' command makes fast-import start a branch from scratch. It's name is kept in lookup table but it's sha1 is null_sha1 (special value). 'notemodify' command can be used to add a note on branch head given it's name. lookup_branch() is used it that case and it doesn't check for null_sha1. So fast-import writes a note for null_sha1 object instead of giving a error. Add a check to deny adding a note on empty branch and add a corresponding test. Signed-off-by: Dmitry Ivankov <divanorama@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Dmitry Ivankov committed Sep 23, 2011 at 01:47 UTC 0bc69881a611c582f3b89a475882161d83c56494
2 files changed +19
fast-import.c
+2
@@ -2416,6 +2416,8 @@ static void note_change_n(struct branch *b, unsigned char old_fanout)
2416 /* <committish> */
2417 s = lookup_branch(p);
2418 if (s) {
2419 + if (is_null_sha1(s->sha1))
2420 + die("Can't add a note on empty branch.");
2421 hashcpy(commit_sha1, s->sha1);
2422 } else if (*p == ':') {
2423 uintmax_t commit_mark = strtoumax(p + 1, NULL, 10);
t/t9300-fast-import.sh
+17
@@ -1987,6 +1987,23 @@ test_expect_success \
1987 'Q: verify second note for second commit' \
1988 'git cat-file blob refs/notes/foobar:$commit2 >actual && test_cmp expect actual'
1989
1990 +cat >input <<EOF
1991 +reset refs/heads/Q0
1992 +
1993 +commit refs/heads/note-Q0
1994 +committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1995 +data <<COMMIT
1996 +Note for an empty branch.
1997 +COMMIT
1998 +
1999 +N inline refs/heads/Q0
2000 +data <<NOTE
2001 +some note
2002 +NOTE
2003 +EOF
2004 +test_expect_success \
2005 + 'Q: deny note on empty branch' \
2006 + 'test_must_fail git fast-import <input'
2007 ###
2008 ### series R (feature and option)
2009 ###