summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c905e09)
raw | patch | inline | side by side (parent: c905e09)
author | Shawn O. Pearce <spearce@spearce.org> | |
Fri, 3 Aug 2007 03:37:21 +0000 (23:37 -0400) | ||
committer | Shawn O. Pearce <spearce@spearce.org> | |
Sun, 19 Aug 2007 07:38:34 +0000 (03:38 -0400) |
Michael Haggerty <mhagger@alum.mit.edu> noticed while debugging a
Git backend for cvs2svn that fast-import was barfing when he tried
to use "TAG_FIXUP" as a branch name for temporary work needed to
cleanup the tree prior to creating an annotated tag object.
The reason we were rejecting the branch name was check_ref_format()
returns -2 when there are less than 2 '/' characters in the input
name. TAG_FIXUP has 0 '/' characters, but is technically just as
valid of a ref as HEAD and MERGE_HEAD, so we really should permit it
(and any other similar looking name) during import.
New test cases have been added to make sure we still detect very
wrong branch names (e.g. containing [ or starting with .) and yet
still permit reasonable names (e.g. TAG_FIXUP).
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Git backend for cvs2svn that fast-import was barfing when he tried
to use "TAG_FIXUP" as a branch name for temporary work needed to
cleanup the tree prior to creating an annotated tag object.
The reason we were rejecting the branch name was check_ref_format()
returns -2 when there are less than 2 '/' characters in the input
name. TAG_FIXUP has 0 '/' characters, but is technically just as
valid of a ref as HEAD and MERGE_HEAD, so we really should permit it
(and any other similar looking name) during import.
New test cases have been added to make sure we still detect very
wrong branch names (e.g. containing [ or starting with .) and yet
still permit reasonable names (e.g. TAG_FIXUP).
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
fast-import.c | patch | blob | history | |
t/t9300-fast-import.sh | patch | blob | history |
diff --git a/fast-import.c b/fast-import.c
index b28f90dc226e9955b60c6c3ac477701b977081cc..7e136a616e7a50018f4101f72d84beb376df43a0 100644 (file)
--- a/fast-import.c
+++ b/fast-import.c
if (b)
die("Invalid attempt to create duplicate branch: %s", name);
- if (check_ref_format(name))
+ switch (check_ref_format(name)) {
+ case 0: break; /* its valid */
+ case -2: break; /* valid, but too few '/', allow anyway */
+ default:
die("Branch name doesn't conform to GIT standards: %s", name);
+ }
b = pool_calloc(1, sizeof(struct branch));
b->name = pool_strdup(name);
diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
index 6f95305bf461c2659392d3ee6a77a5360c833c37..dac6135b22716bf8f39dfeb6ffd75cbdcf3ae22d 100755 (executable)
--- a/t/t9300-fast-import.sh
+++ b/t/t9300-fast-import.sh
'git-fast-import <input'
rm -f .git/objects/pack_* .git/objects/index_*
+cat >input <<INPUT_END
+commit .badbranchname
+committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+data <<COMMIT
+corrupt
+COMMIT
+
+from refs/heads/master
+
+INPUT_END
+test_expect_failure \
+ 'B: fail on invalid branch name ".badbranchname"' \
+ 'git-fast-import <input'
+rm -f .git/objects/pack_* .git/objects/index_*
+
+cat >input <<INPUT_END
+commit bad[branch]name
+committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+data <<COMMIT
+corrupt
+COMMIT
+
+from refs/heads/master
+
+INPUT_END
+test_expect_failure \
+ 'B: fail on invalid branch name "bad[branch]name"' \
+ 'git-fast-import <input'
+rm -f .git/objects/pack_* .git/objects/index_*
+
+cat >input <<INPUT_END
+commit TEMP_TAG
+committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+data <<COMMIT
+tag base
+COMMIT
+
+from refs/heads/master
+
+INPUT_END
+test_expect_success \
+ 'B: accept branch name "TEMP_TAG"' \
+ 'git-fast-import <input &&
+ test -f .git/TEMP_TAG &&
+ test `git rev-parse master` = `git rev-parse TEMP_TAG^`'
+rm -f .git/TEMP_TAG
+
###
### series C
###