Skip to content

Commit

Permalink
allow git-update-ref create refs with slashes in names
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Alex Riesen authored and Junio C Hamano committed Nov 15, 2005
1 parent 7acab8f commit 08db81a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
5 changes: 2 additions & 3 deletions git-branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,5 @@ rev=$(git-rev-parse --verify "$head") || exit
git-check-ref-format "heads/$branchname" ||
die "we do not like '$branchname' as a branch name."

leading=`expr "refs/heads/$branchname" : '\(.*\)/'` &&
mkdir -p "$GIT_DIR/$leading" &&
echo $rev > "$GIT_DIR/refs/heads/$branchname"
git update-ref "refs/heads/$branchname" $rev

8 changes: 8 additions & 0 deletions t/t3200-branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,12 @@ test_expect_failure \
'git branch --help should not have created a bogus branch' \
'test -f .git/refs/heads/--help'

test_expect_success \
'git branch abc should create a branch' \
'git-branch abc && test -f .git/refs/heads/abc'

test_expect_success \
'git branch a/b/c should create a branch' \
'git-branch a/b/c && test -f .git/refs/heads/a/b/c'

test_done
5 changes: 4 additions & 1 deletion update-ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ static int re_verify(const char *path, unsigned char *oldsha1, unsigned char *cu
int main(int argc, char **argv)
{
char *hex;
const char *refname, *value, *oldval, *path, *lockpath;
const char *refname, *value, *oldval, *path;
char *lockpath;
unsigned char sha1[20], oldsha1[20], currsha1[20];
int fd, written;

Expand Down Expand Up @@ -49,6 +50,8 @@ int main(int argc, char **argv)
}
path = strdup(path);
lockpath = mkpath("%s.lock", path);
if (safe_create_leading_directories(lockpath) < 0)
die("Unable to create all of %s", lockpath);

fd = open(lockpath, O_CREAT | O_EXCL | O_WRONLY, 0666);
if (fd < 0)
Expand Down

0 comments on commit 08db81a

Please sign in to comment.