@matheusbsbs / matheus-bagliano / commits / 7dc4642989
Fork 0

Fix "git checkout -b foo ':/substring'"

Because ':/substring' extended SHA1 expression cannot take postfix modifiers such as ^{tree} and ^{commit}, we would need to do it in multiple steps. With the patch, you can start a new branch from a randomly-picked commit whose message has the named string in it. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Feb 1, 2008 at 19:06 UTC 7dc46429896d6292d71391ff7e5f95fec1370b51
1 file changed +4 -3
git-checkout.sh
+4 -3
@@ -71,7 +71,8 @@ while test $# != 0; do
71 done
72
73 arg="$1"
74 -if rev=$(git rev-parse --verify "$arg^0" 2>/dev/null)
74 +rev=$(git rev-parse --verify "$arg" 2>/dev/null)
75 +if rev=$(git rev-parse --verify "$rev^0" 2>/dev/null)
76 then
77 [ -z "$rev" ] && die "unknown flag $arg"
78 new_name="$arg"
@@ -82,11 +83,11 @@ then
83 fi
84 new="$rev"
85 shift
85 -elif rev=$(git rev-parse --verify "$arg^{tree}" 2>/dev/null)
86 +elif rev=$(git rev-parse --verify "$rev^{tree}" 2>/dev/null)
87 then
88 # checking out selected paths from a tree-ish.
89 new="$rev"
89 - new_name="$arg^{tree}"
90 + new_name="$rev^{tree}"
91 shift
92 fi
93 [ "$1" = "--" ] && shift