Skip to content

Commit 3a4b3f2

Browse files
spearceJunio C Hamano
authored andcommitted
Create/delete branch ref logs.
When crating a new branch offer '-l' as a way for the user to quickly enable ref logging for the new branch. When deleting a branch also delete its ref log. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 67644a4 commit 3a4b3f2

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

Documentation/git-branch.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ SYNOPSIS
99
--------
1010
[verse]
1111
'git-branch' [-r]
12-
'git-branch' [-f] <branchname> [<start-point>]
12+
'git-branch' [-l] [-f] <branchname> [<start-point>]
1313
'git-branch' (-d | -D) <branchname>...
1414

1515
DESCRIPTION
@@ -23,7 +23,8 @@ If no <start-point> is given, the branch will be created with a head
2323
equal to that of the currently checked out branch.
2424

2525
With a `-d` or `-D` option, `<branchname>` will be deleted. You may
26-
specify more than one branch for deletion.
26+
specify more than one branch for deletion. If the branch currently
27+
has a ref log then the ref log will also be deleted.
2728

2829

2930
OPTIONS
@@ -34,6 +35,11 @@ OPTIONS
3435
-D::
3536
Delete a branch irrespective of its index status.
3637

38+
-l::
39+
Create the branch's ref log. This activates recording of
40+
all changes to made the branch ref, enabling use of date
41+
based sha1 expressions such as "<branchname>@{yesterday}".
42+
3743
-f::
3844
Force the creation of a new branch even if it means deleting
3945
a branch that already exists with the same name.

git-branch.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

3-
USAGE='[(-d | -D) <branchname>] | [[-f] <branchname> [<start-point>]] | -r'
3+
USAGE='[-l] [(-d | -D) <branchname>] | [[-f] <branchname> [<start-point>]] | -r'
44
LONG_USAGE='If no arguments, show available branches and mark current branch with a star.
55
If one argument, create a new branch <branchname> based off of current HEAD.
66
If two arguments, create a new branch <branchname> based off of <start-point>.'
@@ -42,6 +42,7 @@ If you are sure you want to delete it, run 'git branch -D $branch_name'."
4242
esac
4343
;;
4444
esac
45+
rm -f "$GIT_DIR/logs/refs/heads/$branch_name"
4546
rm -f "$GIT_DIR/refs/heads/$branch_name"
4647
echo "Deleted branch $branch_name."
4748
done
@@ -55,6 +56,7 @@ ls_remote_branches () {
5556
}
5657

5758
force=
59+
create_log=
5860
while case "$#,$1" in 0,*) break ;; *,-*) ;; *) break ;; esac
5961
do
6062
case "$1" in
@@ -69,6 +71,9 @@ do
6971
-f)
7072
force="$1"
7173
;;
74+
-l)
75+
create_log="yes"
76+
;;
7277
--)
7378
shift
7479
break
@@ -117,4 +122,9 @@ then
117122
die "cannot force-update the current branch."
118123
fi
119124
fi
125+
if test "$create_log" = 'yes'
126+
then
127+
mkdir -p $(dirname "$GIT_DIR/logs/refs/heads/$branchname")
128+
touch "$GIT_DIR/logs/refs/heads/$branchname"
129+
fi
120130
git update-ref -m "branch: Created from $head" "refs/heads/$branchname" $rev

0 commit comments

Comments
 (0)