allow 'got ref' to manipulate refs which do not have a slash in their name
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
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