Enable ref log creation in git checkout -b.
Switch git checkout -b to use git-update-ref rather than echo and a shell I/O redirection. This is more in line with typical GIT commands and allows -b to be logged according to the normal ref logging rules. Added -l option to allow users to create the ref log at the same time as creating a branch. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Shawn Pearce committed
May 19, 2006 at 05:17 UTC
969d326d6b54573e171c903fdf9fdc6b107c18d1
2 files changed
+21
-5
Documentation/git-checkout.txt
+6
-1
@@ -8,7 +8,7 @@ git-checkout - Checkout and switch to a branch
8
SYNOPSIS
9
--------
10
[verse]
11
-'git-checkout' [-f] [-b <new_branch>] [-m] [<branch>]
11
+'git-checkout' [-f] [-b <new_branch> [-l]] [-m] [<branch>]
12
'git-checkout' [-m] [<branch>] <paths>...
13
14
DESCRIPTION
@@ -37,6 +37,11 @@ OPTIONS
37
-b::
38
Create a new branch and start it at <branch>.
39
40
+-l::
41
+ Create the new branch's ref log. This activates recording of
42
+ all changes to made the branch ref, enabling use of date
43
+ based sha1 expressions such as "<branchname>@{yesterday}".
44
+
45
-m::
46
If you have local modifications to one or more files that
47
are different between the current branch and the branch to
git-checkout.sh
+15
-4
@@ -5,10 +5,13 @@ SUBDIRECTORY_OK=Sometimes
5
. git-sh-setup
6
7
old=$(git-rev-parse HEAD)
8
+old_name=HEAD
9
new=
10
+new_name=
11
force=
12
branch=
13
newbranch=
14
+newbranch_log=
15
merge=
16
while [ "$#" != "0" ]; do
17
arg="$1"
@@ -24,6 +27,9 @@ while [ "$#" != "0" ]; do
27
git-check-ref-format "heads/$newbranch" ||
28
die "git checkout: we do not like '$newbranch' as a branch name."
29
;;
30
+ "-l")
31
+ newbranch_log=1
32
+ ;;
33
"-f")
34
force=1
35
;;
@@ -44,6 +50,7 @@ while [ "$#" != "0" ]; do
50
exit 1
51
fi
52
new="$rev"
53
+ new_name="$arg^0"
54
if [ -f "$GIT_DIR/refs/heads/$arg" ]; then
55
branch="$arg"
56
fi
@@ -51,9 +58,11 @@ while [ "$#" != "0" ]; do
58
then
59
# checking out selected paths from a tree-ish.
60
new="$rev"
61
+ new_name="$arg^{tree}"
62
branch=
63
else
64
new=
65
+ new_name=
66
branch=
67
set x "$arg" "$@"
68
shift
@@ -114,7 +123,7 @@ then
123
cd "$cdup"
124
fi
125
117
-[ -z "$new" ] && new=$old
126
+[ -z "$new" ] && new=$old && new_name="$old_name"
127
128
# If we don't have an old branch that we're switching to,
129
# and we don't have a new branch name for the target we
@@ -187,9 +196,11 @@ fi
196
#
197
if [ "$?" -eq 0 ]; then
198
if [ "$newbranch" ]; then
190
- leading=`expr "refs/heads/$newbranch" : '\(.*\)/'` &&
191
- mkdir -p "$GIT_DIR/$leading" &&
192
- echo $new >"$GIT_DIR/refs/heads/$newbranch" || exit
199
+ if [ "$newbranch_log" ]; then
200
+ mkdir -p $(dirname "$GIT_DIR/logs/refs/heads/$branchname")
201
+ touch "$GIT_DIR/logs/refs/heads/$branchname"
202
+ fi
203
+ git-update-ref -m "checkout: Created from $new_name" "refs/heads/$newbranch" $new || exit
204
branch="$newbranch"
205
fi
206
[ "$branch" ] &&