git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] fast-import: don't allow to tag empty branch

From
Dmitry Ivankov <divanorama@gmail.com>
Date
Sep 22, 2011, 19:47 UTC
Message-ID
<1316720825-32552-2-git-send-email-divanorama@gmail.com>
In-Reply-To
<1316720825-32552-1-git-send-email-divanorama@gmail.com>

'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). 'tag' command can be used to tag a branch by it's name. lookup_branch() is used it that case and it doesn't check for null_sha1. So fast-import writes a tag for null_sha1 object instead of giving a error.

Add a check to deny tagging an empty branch and add a corresponding test.
Signed-off-by: Dmitry Ivankov <divanorama@gmail.com>
---
 fast-import.c          |    2 ++
 t/t9300-fast-import.sh |   12 ++++++++++++
 2 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/fast-import.c b/fast-import.c
index 742e7da..c44cc11 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -2717,6 +2717,8 @@ static void parse_new_tag(void)
 	from = strchr(command_buf.buf, ' ') + 1;
 	s = lookup_branch(from);
 	if (s) {
+		if (is_null_sha1(s->sha1))
+			die("Can't tag an empty branch.");
 		hashcpy(sha1, s->sha1);
 		type = OBJ_COMMIT;
 	} else if (*from == ':') {
diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
index 1a6c066..0b97d7a 100755
--- a/t/t9300-fast-import.sh
+++ b/t/t9300-fast-import.sh
@@ -820,6 +820,18 @@ test_expect_success \
 	'test 1 = `git rev-list J | wc -l` &&
 	 test 0 = `git ls-tree J | wc -l`'
 
+cat >input <<INPUT_END
+reset refs/heads/J2
+
+tag wrong_tag
+from refs/heads/J2
+data <<EOF
+Tag branch that was reset.
+EOF
+INPUT_END
+test_expect_success \
+	'J: tag must fail on empty branch' \
+	'test_must_fail git fast-import <input'
 ###
 ### series K
 ###
-- 
1.7.3.4
Previous: Dmitry IvankovNext: Sverre Rabbelier
Message 2 of 5 in “fast-import: empty/reset branch bugs”
  1. 0/2 fast-import: empty/reset branch bugsDmitry Ivankov, Sep 22, 2011
  2. 1/2 fast-import: don't allow to tag empty branchDmitry Ivankov, Sep 22, 2011
  3. Sverre RabbelierSep 22, 2011
  4. 2/2 fast-import: don't allow to note on empty branchDmitry Ivankov, Sep 22, 2011
  5. Sverre RabbelierSep 22, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.