@matheusbsbs / matheus-bagliano / commits / 13648af5ee
Fork 0

Add 'git subtree merge' and 'git subtree pull'.

These are simple shortcuts for 'git merge -s subtree' and 'git pull -s subtree', but it makes sense to have it all in one command.

Avery Pennarun committed Apr 24, 2009 at 23:41 UTC 13648af5eecd0880a64b6ea4b14f485f53daa2f1
1 file changed +40 -15
git-subtree.sh
+40 -15
@@ -8,13 +8,15 @@ if [ $# -eq 0 ]; then
8 set -- -h
9 fi
10 OPTS_SPEC="\
11 -git subtree add <--prefix=prefix <commit>
12 -git subtree split [options...] <--prefix=prefix> <commit...>
13 -git subtree merge
11 +git subtree add --prefix=<prefix> <commit>
12 +git subtree split [options...] --prefix=<prefix> <commit...>
13 +git subtree merge --prefix=<prefix> <commit>
14 +git subtree pull --prefix=<prefix> <repository> <refspec...>
15 --
16 h,help show the help
17 q quiet
18 prefix= the name of the subdir to split out
19 + options for 'split'
20 onto= try connecting new tree to an existing one
21 rejoin merge the new branch back into HEAD
22 ignore-joins ignore prior --rejoin commits
@@ -68,27 +70,29 @@ done
70 command="$1"
71 shift
72 case "$command" in
71 - add|merge) default= ;;
73 + add|merge|pull) default= ;;
74 split) default="--default HEAD" ;;
75 *) die "Unknown command '$command'" ;;
76 esac
77
76 -revs=$(git rev-parse $default --revs-only "$@") || exit $?
77 -
78 if [ -z "$prefix" ]; then
79 die "You must provide the --prefix option."
80 fi
81 dir="$prefix"
82
83 -dirs="$(git rev-parse --no-revs --no-flags "$@")" || exit $?
84 -if [ -n "$dirs" ]; then
85 - die "Error: Use --prefix instead of bare filenames."
83 +if [ "$command" != "pull" ]; then
84 + revs=$(git rev-parse $default --revs-only "$@") || exit $?
85 + dirs="$(git rev-parse --no-revs --no-flags "$@")" || exit $?
86 + if [ -n "$dirs" ]; then
87 + die "Error: Use --prefix instead of bare filenames."
88 + fi
89 fi
90
91 debug "command: {$command}"
92 debug "quiet: {$quiet}"
93 debug "revs: {$revs}"
94 debug "dir: {$dir}"
95 +debug "opts: {$*}"
96 debug
97
98 cache_setup()
@@ -258,17 +262,23 @@ copy_or_skip()
262 fi
263 }
264
261 -cmd_add()
265 +ensure_clean()
266 {
263 - if [ -e "$dir" ]; then
264 - die "'$dir' already exists. Cannot add."
265 - fi
267 if ! git diff-index HEAD --exit-code --quiet; then
268 die "Working tree has modifications. Cannot add."
269 fi
270 if ! git diff-index --cached HEAD --exit-code --quiet; then
271 die "Index has modifications. Cannot add."
272 fi
273 +}
274 +
275 +cmd_add()
276 +{
277 + if [ -e "$dir" ]; then
278 + die "'$dir' already exists. Cannot add."
279 + fi
280 + ensure_clean
281 +
282 set -- $revs
283 if [ $# -ne 1 ]; then
284 die "You must provide exactly one revision. Got: '$revs'"
@@ -357,7 +367,22 @@ cmd_split()
367
368 cmd_merge()
369 {
360 - die "merge command not implemented yet"
370 + ensure_clean
371 +
372 + set -- $revs
373 + if [ $# -ne 1 ]; then
374 + die "You must provide exactly one revision. Got: '$revs'"
375 + fi
376 + rev="$1"
377 +
378 + git merge -s subtree $rev
379 +}
380 +
381 +cmd_pull()
382 +{
383 + ensure_clean
384 + set -x
385 + git pull -s subtree "$@"
386 }
387
363 -"cmd_$command"
388 +"cmd_$command" "$@"