git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] We do not like "HEAD" as a new branch name
@ 2005-12-15 11:46 Johannes Schindelin
  2005-12-15 16:27 ` H. Peter Anvin
  2005-12-15 19:34 ` Junio C Hamano
  0 siblings, 2 replies; 10+ messages in thread
From: Johannes Schindelin @ 2005-12-15 11:46 UTC (permalink / raw)
  To: git, junkio


This makes git-check-ref-format fail for "HEAD". Since the check is only
executed when creating refs, the existing symbolic ref is safe.

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>

---

	This patch was triggered by Alex' mail. Even if it should be a 
	rare case, it could catch some bad errors: Just try to run

		git checkout -b HEAD

	and imagine what a regular git user makes of the error 
	message...

 refs.c                 |    5 +++++
 t/t3300-funny-names.sh |    2 ++
 2 files changed, 7 insertions(+), 0 deletions(-)

04d60f0bf743f91d03e03acebf123db527cb7507
diff --git a/refs.c b/refs.c
index bda45f7..293bfe7 100644
--- a/refs.c
+++ b/refs.c
@@ -332,6 +332,11 @@ int check_ref_format(const char *ref)
 		if (ch == '.' || bad_ref_char(ch))
 			return -1;
 
+		/* do not allow "HEAD" as ref name */
+		if (ch == 'H' && (!strcmp(cp, "EAD") ||
+					!strncmp(cp, "EAD/", 4)))
+			return -1;
+
 		/* scan the rest of the path component */
 		while ((ch = *cp++) != 0) {
 			if (bad_ref_char(ch))
diff --git a/t/t3300-funny-names.sh b/t/t3300-funny-names.sh
index 897c378..8ebd896 100755
--- a/t/t3300-funny-names.sh
+++ b/t/t3300-funny-names.sh
@@ -139,4 +139,6 @@ test_expect_success 'git-apply non-git d
 	 git-apply --stat | sed -e "s/|.*//" -e "s/ *\$//" >current &&
 	 diff -u expected current'
 
+test_expect_failure 'HEAD is special' 'git checkout -b HEAD'
+
 test_done
-- 
0.99.9.GIT

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2005-12-16 11:32 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-12-15 11:46 [PATCH] We do not like "HEAD" as a new branch name Johannes Schindelin
2005-12-15 16:27 ` H. Peter Anvin
2005-12-15 16:40   ` Johannes Schindelin
2005-12-15 17:00     ` Alex Riesen
2005-12-15 19:34 ` Junio C Hamano
2005-12-15 22:41   ` Johannes Schindelin
2005-12-15 23:38     ` Junio C Hamano
2005-12-16  1:40       ` Johannes Schindelin
2005-12-16  6:34         ` Junio C Hamano
2005-12-16 11:32           ` Johannes Schindelin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).