@matheusbsbs / matheus-bagliano / commits / b77172f814
Fork 0

Add a new --rejoin option.

The idea is to join the new split branch back into this one, so future splits can append themselves to the old split branch. We mark the split branch's history in our merge commit, so we can pull it back out later.

Avery Pennarun committed Apr 24, 2009 at 15:48 UTC b77172f8140d830a9160306c8ee10ceed413ba23
1 file changed +44 -9
git-subtree.sh
+44 -9
@@ -2,10 +2,10 @@
2 #
3 # git-subtree.sh: split/join git repositories in subdirectories of this one
4 #
5 -# Copyright (c) 2009 Avery Pennarun <apenwarr@gmail.com>
5 +# Copyright (C) 2009 Avery Pennarun <apenwarr@gmail.com>
6 #
7 OPTS_SPEC="\
8 -git subtree split <revisions> -- <subdir>
8 +git subtree split [--rejoin] [--onto rev] <commit...> -- <path>
9 git subtree merge
10
11 git subtree does foo and bar!
@@ -13,6 +13,8 @@ git subtree does foo and bar!
13 h,help show the help
14 q quiet
15 v verbose
16 +onto= existing subtree revision to connect, if any
17 +rejoin merge the new branch back into HEAD
18 "
19 eval $(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)
20 . git-sh-setup
@@ -20,6 +22,8 @@ require_work_tree
22
23 quiet=
24 command=
25 +onto=
26 +rejoin=
27
28 debug()
29 {
@@ -42,9 +46,12 @@ assert()
46
47 while [ $# -gt 0 ]; do
48 opt="$1"
49 + debug "option: $1"
50 shift
51 case "$opt" in
52 -q) quiet=1 ;;
53 + --onto) onto="$1"; shift ;;
54 + --rejoin) rejoin=1 ;;
55 --) break ;;
56 esac
57 done
@@ -93,7 +100,9 @@ cache_set()
100 {
101 oldrev="$1"
102 newrev="$2"
96 - if [ "$oldrev" != "latest" -a -e "$cachedir/$oldrev" ]; then
103 + if [ "$oldrev" != "latest_old" \
104 + -a "$oldrev" != "latest_new" \
105 + -a -e "$cachedir/$oldrev" ]; then
106 die "cache for $oldrev already exists!"
107 fi
108 echo "$newrev" >"$cachedir/$oldrev"
@@ -111,12 +120,29 @@ copy_commit()
120 read GIT_COMMITTER_NAME
121 read GIT_COMMITTER_EMAIL
122 read GIT_COMMITTER_DATE
114 - export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE
115 - export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE
123 + export GIT_AUTHOR_NAME \
124 + GIT_AUTHOR_EMAIL \
125 + GIT_AUTHOR_DATE \
126 + GIT_COMMITTER_NAME \
127 + GIT_COMMITTER_EMAIL \
128 + GIT_COMMITTER_DATE
129 git commit-tree "$2" $3 # reads the rest of stdin
130 ) || die "Can't copy commit $1"
131 }
132
133 +merge_msg()
134 +{
135 + dir="$1"
136 + latest_old="$2"
137 + latest_new="$3"
138 + cat <<-EOF
139 + Split changes from '$dir/' into commit '$latest_new'
140 +
141 + git-subtree-dir: $dir
142 + git-subtree-includes: $latest_old
143 + EOF
144 +}
145 +
146 cmd_split()
147 {
148 debug "Splitting $dir..."
@@ -140,14 +166,23 @@ cmd_split()
166 newrev=$(copy_commit $rev $tree "$p") || exit $?
167 debug " newrev is: $newrev"
168 cache_set $rev $newrev
143 - cache_set latest $newrev
169 + cache_set latest_new $newrev
170 + cache_set latest_old $rev
171 done || exit $?
172 done || exit $?
146 - latest=$(cache_get latest)
147 - if [ -z "$latest" ]; then
173 + latest_new=$(cache_get latest_new)
174 + if [ -z "$latest_new" ]; then
175 die "No new revisions were found"
176 fi
150 - echo $latest
177 +
178 + if [ -n "$rejoin" ]; then
179 + debug "Merging split branch into HEAD..."
180 + latest_old=$(cache_get latest_old)
181 + git merge -s ours \
182 + -m "$(merge_msg $dir $latest_old $latest_new)" \
183 + $latest_new
184 + fi
185 + echo $latest_new
186 exit 0
187 }
188