@matheusbsbs / matheus-bagliano / commits / 08db81a9f1
Fork 0

allow git-update-ref create refs with slashes in names

Make git-update-ref create references with slashes in them. git-branch and git-checkout already support such reference names. git-branch can use git-update-ref to create the references in a more formal manner now. Signed-off-by: Junio C Hamano <junkio@cox.net>

Alex Riesen committed Nov 14, 2005 at 23:10 UTC 08db81a9f1e4072790f0257f5398e8408e3d6816
3 files changed +14 -4
git-branch.sh
+2 -3
@@ -102,6 +102,5 @@ rev=$(git-rev-parse --verify "$head") || exit
102 git-check-ref-format "heads/$branchname" ||
103 die "we do not like '$branchname' as a branch name."
104
105 -leading=`expr "refs/heads/$branchname" : '\(.*\)/'` &&
106 -mkdir -p "$GIT_DIR/$leading" &&
107 -echo $rev > "$GIT_DIR/refs/heads/$branchname"
105 +git update-ref "refs/heads/$branchname" $rev
106 +
t/t3200-branch.sh
+8
@@ -24,4 +24,12 @@ test_expect_failure \
24 'git branch --help should not have created a bogus branch' \
25 'test -f .git/refs/heads/--help'
26
27 +test_expect_success \
28 + 'git branch abc should create a branch' \
29 + 'git-branch abc && test -f .git/refs/heads/abc'
30 +
31 +test_expect_success \
32 + 'git branch a/b/c should create a branch' \
33 + 'git-branch a/b/c && test -f .git/refs/heads/a/b/c'
34 +
35 test_done
update-ref.c
+4 -1
@@ -19,7 +19,8 @@ static int re_verify(const char *path, unsigned char *oldsha1, unsigned char *cu
19 int main(int argc, char **argv)
20 {
21 char *hex;
22 - const char *refname, *value, *oldval, *path, *lockpath;
22 + const char *refname, *value, *oldval, *path;
23 + char *lockpath;
24 unsigned char sha1[20], oldsha1[20], currsha1[20];
25 int fd, written;
26
@@ -49,6 +50,8 @@ int main(int argc, char **argv)
50 }
51 path = strdup(path);
52 lockpath = mkpath("%s.lock", path);
53 + if (safe_create_leading_directories(lockpath) < 0)
54 + die("Unable to create all of %s", lockpath);
55
56 fd = open(lockpath, O_CREAT | O_EXCL | O_WRONLY, 0666);
57 if (fd < 0)