@matheusbsbs / matheus-bagliano / commits / 9a8821ff33
Fork 0

Pass the path using the --prefix option instead of on the command line.

I like this better. It's more like git-read-tree and some other commands.

Avery Pennarun committed Apr 24, 2009 at 22:57 UTC 9a8821ff33d5abc9d2603dd91c04872016d40982
2 files changed +19 -15
git-subtree.sh
+16 -12
@@ -8,14 +8,12 @@ if [ $# -eq 0 ]; then
8 set -- -h
9 fi
10 OPTS_SPEC="\
11 -git subtree split [options...] <commit...> -- <path>
11 +git subtree split [options...] <--prefix=prefix> <commit...> -- <path>
12 git subtree merge
13 -
14 -git subtree does foo and bar!
13 --
14 h,help show the help
15 q quiet
18 -v verbose
16 +prefix= the name of the subdir to split out
17 onto= try connecting new tree to an existing one
18 rejoin merge the new branch back into HEAD
19 ignore-joins ignore prior --rejoin commits
@@ -54,6 +52,8 @@ while [ $# -gt 0 ]; do
52 shift
53 case "$opt" in
54 -q) quiet=1 ;;
55 + --prefix) prefix="$1"; shift ;;
56 + --no-prefix) prefix= ;;
57 --onto) onto="$1"; shift ;;
58 --no-onto) onto= ;;
59 --rejoin) rejoin=1 ;;
@@ -72,14 +72,16 @@ case "$command" in
72 esac
73
74 revs=$(git rev-parse --default HEAD --revs-only "$@") || exit $?
75 -dirs="$(git rev-parse --sq --no-revs --no-flags "$@")" || exit $?
75
77 -#echo "dirs is {$dirs}"
78 -eval $(echo set -- $dirs)
79 -if [ "$#" -ne 1 ]; then
80 - die "Must provide exactly one subtree dir (got $#)"
76 +if [ -z "$prefix" ]; then
77 + die "You must provide the --prefix option."
78 +fi
79 +dir="$prefix"
80 +
81 +dirs="$(git rev-parse --no-revs --no-flags "$@")" || exit $?
82 +if [ -n "$dirs" ]; then
83 + die "Error: Use --prefix instead of bare filenames."
84 fi
82 -dir="$1"
85
86 debug "command: {$command}"
87 debug "quiet: {$quiet}"
@@ -261,8 +263,10 @@ cmd_split()
263 unrevs="$(find_existing_splits "$dir" "$revs")"
264 fi
265
264 - debug "git rev-list --reverse $revs $unrevs"
265 - git rev-list --reverse --parents $revs $unrevsx |
266 + # We can't restrict rev-list to only "$dir" here, because that leaves out
267 + # critical information about commit parents.
268 + debug "git rev-list --reverse --parents $revs $unrevs"
269 + git rev-list --reverse --parents $revs $unrevs |
270 while read rev parents; do
271 debug
272 debug "Processing commit: $rev"
test.sh
+3 -3
@@ -59,7 +59,7 @@ git branch sub2 FETCH_HEAD
59 git merge -s subtree FETCH_HEAD
60 git branch pre-split
61
62 -split1=$(git subtree split --onto FETCH_HEAD subdir --rejoin)
62 +split1=$(git subtree split --prefix subdir --onto FETCH_HEAD --rejoin)
63 echo "split1={$split1}"
64 git branch split1 "$split1"
65
@@ -77,14 +77,14 @@ git add sub6
77 git commit -m 'sub6'
78
79 cd ../mainline
80 -split2=$(git subtree split subdir --rejoin)
80 +split2=$(git subtree split --prefix subdir --rejoin)
81 git branch split2 "$split2"
82
83 touch subdir/main-sub7
84 git add subdir/main-sub7
85 git commit -m 'main-sub7'
86
87 -split3=$(git subtree split subdir --rejoin)
87 +split3=$(git subtree split --prefix subdir --rejoin)
88 git branch split3 "$split3"
89
90 cd ../subproj