diff options
-rwxr-xr-x | git-branch.sh | 5 | ||||
-rwxr-xr-x | t/t3200-branch.sh | 8 | ||||
-rw-r--r-- | update-ref.c | 5 |
3 files changed, 14 insertions, 4 deletions
diff --git a/git-branch.sh b/git-branch.sh index 67f113acb9..11d52fd78e 100755 --- a/git-branch.sh +++ b/git-branch.sh @@ -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 + diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh index 5f98f64de1..36f7749bed 100755 --- a/t/t3200-branch.sh +++ b/t/t3200-branch.sh @@ -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 diff --git a/update-ref.c b/update-ref.c index d79dc52fd7..e6fbddbab6 100644 --- a/update-ref.c +++ b/update-ref.c @@ -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; @@ -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) |