@@ -30,19 +30,19 @@ squash merge subtree changes as a single commit
30
30
31
31
PATH=$PATH :$( git --exec-path)
32
32
33
- branch =
34
- debug =
35
- command =
36
- onto =
37
- rejoin =
38
- ignore_joins =
39
- annotate =
40
- squash =
41
- message =
42
- prefix =
33
+ arg_debug =
34
+ arg_command =
35
+ arg_prefix =
36
+ arg_split_branch =
37
+ arg_split_onto =
38
+ arg_split_rejoin =
39
+ arg_split_ignore_joins =
40
+ arg_split_annotate =
41
+ arg_addmerge_squash =
42
+ arg_addmerge_message =
43
43
44
44
debug () {
45
- if test -n " $debug "
45
+ if test -n " $arg_debug "
46
46
then
47
47
printf " %s\n" " $* " >&2
48
48
fi
@@ -88,54 +88,54 @@ main () {
88
88
GIT_QUIET=1
89
89
;;
90
90
-d)
91
- debug =1
91
+ arg_debug =1
92
92
;;
93
93
--annotate)
94
- annotate =" $1 "
94
+ arg_split_annotate =" $1 "
95
95
shift
96
96
;;
97
97
--no-annotate)
98
- annotate =
98
+ arg_split_annotate =
99
99
;;
100
100
-b)
101
- branch =" $1 "
101
+ arg_split_branch =" $1 "
102
102
shift
103
103
;;
104
104
-P)
105
- prefix =" ${1%/ } "
105
+ arg_prefix =" ${1%/ } "
106
106
shift
107
107
;;
108
108
-m)
109
- message =" $1 "
109
+ arg_addmerge_message =" $1 "
110
110
shift
111
111
;;
112
112
--no-prefix)
113
- prefix =
113
+ arg_prefix =
114
114
;;
115
115
--onto)
116
- onto =" $1 "
116
+ arg_split_onto =" $1 "
117
117
shift
118
118
;;
119
119
--no-onto)
120
- onto =
120
+ arg_split_onto =
121
121
;;
122
122
--rejoin)
123
- rejoin =1
123
+ arg_split_rejoin =1
124
124
;;
125
125
--no-rejoin)
126
- rejoin =
126
+ arg_split_rejoin =
127
127
;;
128
128
--ignore-joins)
129
- ignore_joins =1
129
+ arg_split_ignore_joins =1
130
130
;;
131
131
--no-ignore-joins)
132
- ignore_joins =
132
+ arg_split_ignore_joins =
133
133
;;
134
134
--squash)
135
- squash =1
135
+ arg_addmerge_squash =1
136
136
;;
137
137
--no-squash)
138
- squash =
138
+ arg_addmerge_squash =
139
139
;;
140
140
--)
141
141
break
@@ -146,42 +146,42 @@ main () {
146
146
esac
147
147
done
148
148
149
- command =" $1 "
149
+ arg_command =" $1 "
150
150
shift
151
151
152
- case " $command " in
152
+ case " $arg_command " in
153
153
add|merge|pull)
154
154
default=
155
155
;;
156
156
split|push)
157
157
default=" --default HEAD"
158
158
;;
159
159
* )
160
- die " Unknown command '$command '"
160
+ die " Unknown command '$arg_command '"
161
161
;;
162
162
esac
163
163
164
- if test -z " $prefix "
164
+ if test -z " $arg_prefix "
165
165
then
166
166
die " You must provide the --prefix option."
167
167
fi
168
168
169
- case " $command " in
169
+ case " $arg_command " in
170
170
add)
171
- test -e " $prefix " &&
172
- die " prefix '$prefix ' already exists."
171
+ test -e " $arg_prefix " &&
172
+ die " prefix '$arg_prefix ' already exists."
173
173
;;
174
174
* )
175
- test -e " $prefix " ||
176
- die " '$prefix ' does not exist; use 'git subtree add'"
175
+ test -e " $arg_prefix " ||
176
+ die " '$arg_prefix ' does not exist; use 'git subtree add'"
177
177
;;
178
178
esac
179
179
180
- dir=" $( dirname " $prefix /." ) "
180
+ dir=" $( dirname " $arg_prefix /." ) "
181
181
182
- if test " $command " ! = " pull" &&
183
- test " $command " ! = " add" &&
184
- test " $command " ! = " push"
182
+ if test " $arg_command " ! = " pull" &&
183
+ test " $arg_command " ! = " add" &&
184
+ test " $arg_command " ! = " push"
185
185
then
186
186
revs=$( git rev-parse $default --revs-only " $@ " ) || exit $?
187
187
dirs=$( git rev-parse --no-revs --no-flags " $@ " ) || exit $?
@@ -192,14 +192,14 @@ main () {
192
192
fi
193
193
fi
194
194
195
- debug " command: {$command }"
195
+ debug " command: {$arg_command }"
196
196
debug " quiet: {$GIT_QUIET }"
197
197
debug " revs: {$revs }"
198
198
debug " dir: {$dir }"
199
199
debug " opts: {$* }"
200
200
debug
201
201
202
- " cmd_$command " " $@ "
202
+ " cmd_$arg_command " " $@ "
203
203
}
204
204
205
205
cache_setup () {
@@ -333,7 +333,7 @@ find_existing_splits () {
333
333
main=
334
334
sub=
335
335
local grep_format=" ^git-subtree-dir: $dir /*\$ "
336
- if test -n " $ignore_joins "
336
+ if test -n " $arg_split_ignore_joins "
337
337
then
338
338
grep_format=" ^Add '$dir /' from commit '"
339
339
fi
@@ -394,7 +394,7 @@ copy_commit () {
394
394
GIT_COMMITTER_EMAIL \
395
395
GIT_COMMITTER_DATE
396
396
(
397
- printf " %s" " $annotate "
397
+ printf " %s" " $arg_split_annotate "
398
398
cat
399
399
) |
400
400
git commit-tree " $2 " $3 # reads the rest of stdin
@@ -405,9 +405,9 @@ add_msg () {
405
405
dir=" $1 "
406
406
latest_old=" $2 "
407
407
latest_new=" $3 "
408
- if test -n " $message "
408
+ if test -n " $arg_addmerge_message "
409
409
then
410
- commit_message=" $message "
410
+ commit_message=" $arg_addmerge_message "
411
411
else
412
412
commit_message=" Add '$dir /' from commit '$latest_new '"
413
413
fi
@@ -421,9 +421,9 @@ add_msg () {
421
421
}
422
422
423
423
add_squashed_msg () {
424
- if test -n " $message "
424
+ if test -n " $arg_addmerge_message "
425
425
then
426
- echo " $message "
426
+ echo " $arg_addmerge_message "
427
427
else
428
428
echo " Merge commit '$1 ' as '$2 '"
429
429
fi
@@ -433,9 +433,9 @@ rejoin_msg () {
433
433
dir=" $1 "
434
434
latest_old=" $2 "
435
435
latest_new=" $3 "
436
- if test -n " $message "
436
+ if test -n " $arg_addmerge_message "
437
437
then
438
- commit_message=" $message "
438
+ commit_message=" $arg_addmerge_message "
439
439
else
440
440
commit_message=" Split '$dir /' into commit '$latest_new '"
441
441
fi
@@ -722,7 +722,7 @@ cmd_add_commit () {
722
722
headp=
723
723
fi
724
724
725
- if test -n " $squash "
725
+ if test -n " $arg_addmerge_squash "
726
726
then
727
727
rev=$( new_squash_commit " " " " " $rev " ) || exit $?
728
728
commit=$( add_squashed_msg " $rev " " $dir " |
@@ -741,10 +741,10 @@ cmd_split () {
741
741
debug " Splitting $dir ..."
742
742
cache_setup || exit $?
743
743
744
- if test -n " $onto "
744
+ if test -n " $arg_split_onto "
745
745
then
746
- debug " Reading history for --onto=$onto ..."
747
- git rev-list $onto |
746
+ debug " Reading history for --onto=$arg_split_onto ..."
747
+ git rev-list $arg_split_onto |
748
748
while read rev
749
749
do
750
750
# the 'onto' history is already just the subdir, so
@@ -776,7 +776,7 @@ cmd_split () {
776
776
die " No new revisions were found"
777
777
fi
778
778
779
- if test -n " $rejoin "
779
+ if test -n " $arg_split_rejoin "
780
780
then
781
781
debug " Merging split branch into HEAD..."
782
782
latest_old=$( cache_get latest_old) || exit $?
@@ -785,21 +785,21 @@ cmd_split () {
785
785
-m " $( rejoin_msg " $dir " " $latest_old " " $latest_new " ) " \
786
786
" $latest_new " >&2 || exit $?
787
787
fi
788
- if test -n " $branch "
788
+ if test -n " $arg_split_branch "
789
789
then
790
- if rev_exists " refs/heads/$branch "
790
+ if rev_exists " refs/heads/$arg_split_branch "
791
791
then
792
- if ! git merge-base --is-ancestor " $branch " " $latest_new "
792
+ if ! git merge-base --is-ancestor " $arg_split_branch " " $latest_new "
793
793
then
794
- die " Branch '$branch ' is not an ancestor of commit '$latest_new '."
794
+ die " Branch '$arg_split_branch ' is not an ancestor of commit '$latest_new '."
795
795
fi
796
796
action=' Updated'
797
797
else
798
798
action=' Created'
799
799
fi
800
800
git update-ref -m ' subtree split' \
801
- " refs/heads/$branch " " $latest_new " || exit $?
802
- say >&2 " $action branch '$branch '"
801
+ " refs/heads/$arg_split_branch " " $latest_new " || exit $?
802
+ say >&2 " $action branch '$arg_split_branch '"
803
803
fi
804
804
echo " $latest_new "
805
805
exit 0
@@ -810,7 +810,7 @@ cmd_merge () {
810
810
ensure_single_rev $rev
811
811
ensure_clean
812
812
813
- if test -n " $squash "
813
+ if test -n " $arg_addmerge_squash "
814
814
then
815
815
first_split=" $( find_latest_squash " $dir " ) " || exit $?
816
816
if test -z " $first_split "
@@ -830,12 +830,12 @@ cmd_merge () {
830
830
rev=" $new "
831
831
fi
832
832
833
- if test -n " $message "
833
+ if test -n " $arg_addmerge_message "
834
834
then
835
- git merge -Xsubtree=" $prefix " \
836
- --message=" $message " " $rev "
835
+ git merge -Xsubtree=" $arg_prefix " \
836
+ --message=" $arg_addmerge_message " " $rev "
837
837
else
838
- git merge -Xsubtree=" $prefix " $rev
838
+ git merge -Xsubtree=" $arg_prefix " $rev
839
839
fi
840
840
}
841
841
@@ -863,7 +863,7 @@ cmd_push () {
863
863
repository=$1
864
864
refspec=$2
865
865
echo " git push using: " " $repository " " $refspec "
866
- localrev=$( git subtree split --prefix=" $prefix " ) || die
866
+ localrev=$( git subtree split --prefix=" $arg_prefix " ) || die
867
867
git push " $repository " " $localrev " :" refs/heads/$refspec "
868
868
else
869
869
die " '$dir ' must already exist. Try 'git subtree add'."
0 commit comments