@matheusbsbs / matheus-bagliano / commits / 43a3951243
Fork 0

New --branch option to split command.

This is just a handy way to create a new branch from the newly-split subtree.

Avery Pennarun committed May 30, 2009 at 01:05 UTC 43a3951243ebcfb8ef4c47259ecb2d0dfaadbce4
2 files changed +29 -7
git-subtree.sh
+24 -2
@@ -19,15 +19,17 @@ d show debug messages
19 prefix= the name of the subdir to split out
20 options for 'split'
21 annotate= add a prefix to commit message of new commits
22 +b,branch= create a new branch from the split subtree
23 +ignore-joins ignore prior --rejoin commits
24 onto= try connecting new tree to an existing one
25 rejoin merge the new branch back into HEAD
24 -ignore-joins ignore prior --rejoin commits
26 "
27 eval $(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)
28 . git-sh-setup
29 require_work_tree
30
31 quiet=
32 +branch=
33 debug=
34 command=
35 onto=
@@ -69,6 +71,7 @@ while [ $# -gt 0 ]; do
71 -d) debug=1 ;;
72 --annotate) annotate="$1"; shift ;;
73 --no-annotate) annotate= ;;
74 + -b) branch="$1"; shift ;;
75 --prefix) prefix="$1"; shift ;;
76 --no-prefix) prefix= ;;
77 --onto) onto="$1"; shift ;;
@@ -78,6 +81,7 @@ while [ $# -gt 0 ]; do
81 --ignore-joins) ignore_joins=1 ;;
82 --no-ignore-joins) ignore_joins= ;;
83 --) break ;;
84 + *) die "Unexpected option: $opt" ;;
85 esac
86 done
87
@@ -139,12 +143,21 @@ cache_set()
143 echo "$newrev" >"$cachedir/$oldrev"
144 }
145
146 +rev_exists()
147 +{
148 + if git rev-parse "$1" >/dev/null 2>&1; then
149 + return 0
150 + else
151 + return 1
152 + fi
153 +}
154 +
155 # if a commit doesn't have a parent, this might not work. But we only want
156 # to remove the parent from the rev-list, and since it doesn't exist, it won't
157 # be there anyway, so do nothing in that case.
158 try_remove_previous()
159 {
147 - if git rev-parse "$1^" >/dev/null 2>&1; then
160 + if rev_exists "$1^"; then
161 echo "^$1^"
162 fi
163 }
@@ -344,6 +357,10 @@ cmd_add()
357
358 cmd_split()
359 {
360 + if [ -n "$branch" ] && rev_exists "refs/heads/$branch"; then
361 + die "Branch '$branch' already exists."
362 + fi
363 +
364 debug "Splitting $dir..."
365 cache_setup || exit $?
366
@@ -408,6 +425,11 @@ cmd_split()
425 -m "$(merge_msg $dir $latest_old $latest_new)" \
426 $latest_new >&2 || exit $?
427 fi
428 + if [ -n "$branch" ]; then
429 + git update-ref -m 'subtree split' "refs/heads/$branch" \
430 + $latest_new "" || exit $?
431 + say "Created branch '$branch'"
432 + fi
433 echo $latest_new
434 exit 0
435 }
todo
+5 -5
@@ -3,17 +3,17 @@
3
4 delete tempdir
5
6 - --annotate-sometimes: only annotate if the patch also changes files
7 - outside the subdir?
8 -
6 'git subtree rejoin' option to do the same as --rejoin, eg. after a
7 rebase
8
9 + --prefix doesn't force the subtree correctly in merge/pull:
10 "-s subtree" should be given an explicit subtree option?
13 -
14 - --prefix doesn't force the subtree correctly in merge/pull
11 + There doesn't seem to be a way to do this. We'd have to
12 + patch git-merge-subtree. Ugh.
13
14 add a 'push' subcommand to parallel 'pull'
15 +
16 + add a 'log' subcommand to see what's new in a subtree?
17
18 add a --squash option so we don't merge histories but can still split
19