Commit 7fa81f883018bdf9a7067622c62c75734f846454

Stefan Sperling 2020-02-21T01:06:03

allow 'got ref' to manipulate refs which do not have a slash in their name

diff --git a/lib/reference.c b/lib/reference.c
index 398dfd5..135fe2d 100644
--- a/lib/reference.c
+++ b/lib/reference.c
@@ -245,7 +245,7 @@ get_refs_dir_path(struct got_repository *repo, const char *refname)
 static int
 is_valid_ref_name(const char *name)
 {
-	const char *s, *slash, *seg;
+	const char *s, *seg;
 	const char forbidden[] = { ' ', '~', '^', ':', '?', '*', '[' , '\\' };
 	const char *forbidden_seq[] = { "//", "..", "@{" };
 	const char *lfs = GOT_LOCKFILE_SUFFIX;
@@ -255,10 +255,6 @@ is_valid_ref_name(const char *name)
 	if (name[0] == '@' && name[1] == '\0')
 		return 0;
 
-	slash = strchr(name, '/');
-	if (slash == NULL)
-		return 0;
-
 	s = name;
 	seg = s;
 	if (seg[0] == '\0' || seg[0] == '.' || seg[0] == '/')
diff --git a/regress/cmdline/ref.sh b/regress/cmdline/ref.sh
old mode 100755
new mode 100744
index 4b2f3a9..50b3132
--- a/regress/cmdline/ref.sh
+++ b/regress/cmdline/ref.sh
@@ -106,8 +106,34 @@ function test_ref_create {
 		return 1
 	fi
 
+	# Change HEAD
+	got ref -r $testroot/repo -s HEAD refs/heads/newref
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		echo "got ref command failed unexpectedly"
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	# Ensure that Git recognizes the ref Got has created
+	(cd $testroot/repo && git checkout -q HEAD)
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		echo "git checkout command failed unexpectedly"
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	# Ensure Got recognizes the new ref
+	(cd $testroot/wt && got update -b HEAD >/dev/null)
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		echo "got checkout command failed unexpectedly"
+		test_done "$testroot" "$ret"
+		return 1
+	fi
 	got ref -r $testroot/repo -l > $testroot/stdout
-	echo "HEAD: refs/heads/symbolicref" > $testroot/stdout.expected
+	echo "HEAD: refs/heads/newref" > $testroot/stdout.expected
 	echo -n "refs/got/worktree/base-" >> $testroot/stdout.expected
 	cat $testroot/wt/.got/uuid | tr -d '\n' >> $testroot/stdout.expected
 	echo ": $commit_id" >> $testroot/stdout.expected