Trim some extra merge commits that don't need to go into the split tree.
...and update test.sh to test for this.
Avery Pennarun committed
Apr 26, 2009 at 16:53 UTC
a64f3a7286c4e554b38cd3f7dc8c722aab97cf98
2 files changed
+38
-18
git-subtree.sh
+16
-3
@@ -168,6 +168,7 @@ copy_commit()
168
{
169
# We're doing to set some environment vars here, so
170
# do it in a subshell to get rid of them safely later
171
+ debug copy_commit "{$1}" "{$2}" "{$3}"
172
git log -1 --pretty=format:'%an%n%ae%n%ad%n%cn%n%ce%n%cd%n%s%n%n%b' "$1" |
173
(
174
read GIT_AUTHOR_NAME
@@ -258,19 +259,31 @@ copy_or_skip()
259
260
identical=
261
p=
262
+ gotparents=
263
for parent in $newparents; do
264
ptree=$(toptree_for_commit $parent) || exit $?
265
+ [ -z "$ptree" ] && continue
266
if [ "$ptree" = "$tree" ]; then
267
# an identical parent could be used in place of this rev.
268
identical="$parent"
269
fi
267
- if [ -n "$ptree" ]; then
268
- parentmatch="$parentmatch$parent"
270
+
271
+ # sometimes both old parents map to the same newparent;
272
+ # eliminate duplicates
273
+ is_new=1
274
+ for gp in $gotparents; do
275
+ if [ "$gp" = "$parent" ]; then
276
+ is_new=
277
+ break
278
+ fi
279
+ done
280
+ if [ -n "$is_new" ]; then
281
+ gotparents="$gotparents $parent"
282
p="$p -p $parent"
283
fi
284
done
285
273
- if [ -n "$identical" -a "$parentmatch" = "$identical" ]; then
286
+ if [ -n "$identical" -a "$gotparents" = " $identical" ]; then
287
echo $identical
288
else
289
copy_commit $rev $tree "$p" || exit $?
test.sh
+22
-15
@@ -24,8 +24,8 @@ check()
24
check_equal()
25
{
26
echo
27
- echo "check a:" "$1"
28
- echo " b:" "$2"
27
+ echo "check a:" "{$1}"
28
+ echo " b:" "{$2}"
29
if [ "$1" = "$2" ]; then
30
return 0
31
else
@@ -100,17 +100,17 @@ git branch sub2 FETCH_HEAD
100
git subtree merge --prefix=subdir FETCH_HEAD
101
git branch pre-split
102
103
-split1=$(git subtree split --annotate='*' \
103
+spl1=$(git subtree split --annotate='*' \
104
--prefix subdir --onto FETCH_HEAD --rejoin)
105
-echo "split1={$split1}"
106
-git branch split1 "$split1"
105
+echo "spl1={$spl1}"
106
+git branch spl1 "$spl1"
107
108
create subdir/main-sub8
109
git commit -m 'main-sub8'
110
111
cd ../subproj
112
-git fetch ../mainline split1
113
-git branch split1 FETCH_HEAD
112
+git fetch ../mainline spl1
113
+git branch spl1 FETCH_HEAD
114
git merge FETCH_HEAD
115
116
create sub9
@@ -123,14 +123,14 @@ git branch split2 "$split2"
123
create subdir/main-sub10
124
git commit -m 'main-sub10'
125
126
-split3=$(git subtree split --annotate='*' --prefix subdir --rejoin)
127
-git branch split3 "$split3"
126
+spl3=$(git subtree split --annotate='*' --prefix subdir --rejoin)
127
+git branch spl3 "$spl3"
128
129
cd ../subproj
130
-git fetch ../mainline split3
131
-git branch split3 FETCH_HEAD
130
+git fetch ../mainline spl3
131
+git branch spl3 FETCH_HEAD
132
git merge FETCH_HEAD
133
-git branch subproj-merge-split3
133
+git branch subproj-merge-spl3
134
135
chkm="main4 main6"
136
chkms="main-sub10 main-sub5 main-sub7 main-sub8"
@@ -147,9 +147,9 @@ allchanges=$(git log --name-only --pretty=format:'' | sort | fixnl)
147
check_equal "$allchanges" "$chkms $chks"
148
149
cd ../mainline
150
-git fetch ../subproj subproj-merge-split3
151
-git branch subproj-merge-split3 FETCH_HEAD
152
-git subtree pull --prefix=subdir ../subproj subproj-merge-split3
150
+git fetch ../subproj subproj-merge-spl3
151
+git branch subproj-merge-spl3 FETCH_HEAD
152
+git subtree pull --prefix=subdir ../subproj subproj-merge-spl3
153
154
# make sure exactly the right set of files ends up in the mainline
155
mainfiles=$(git ls-files | fixnl)
@@ -162,5 +162,12 @@ check_equal "$mainfiles" "$chkm $chkms_sub $chks_sub"
162
allchanges=$(git log --name-only --pretty=format:'' | sort | fixnl)
163
check_equal "$allchanges" "$chkm $chkms $chks $chkms_sub"
164
165
+# make sure the --rejoin commits never make it into subproj
166
+check_equal "$(git log --pretty=format:'%s' HEAD^2 | grep -i split)" ""
167
+
168
+# make sure no 'git subtree' tagged commits make it into subproj. (They're
169
+# meaningless to subproj since one side of the merge refers to the mainline)
170
+check_equal "$(git log --pretty=format:'%s%n%b' HEAD^2 | grep 'git-subtree.*:')" ""
171
+
172
echo
173
echo 'ok'