Skip to content

Commit a64f3a7

Browse files
committed
Trim some extra merge commits that don't need to go into the split tree.
...and update test.sh to test for this.
1 parent a046c7b commit a64f3a7

File tree

2 files changed

+38
-18
lines changed

2 files changed

+38
-18
lines changed

git-subtree.sh

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ copy_commit()
168168
{
169169
# We're doing to set some environment vars here, so
170170
# do it in a subshell to get rid of them safely later
171+
debug copy_commit "{$1}" "{$2}" "{$3}"
171172
git log -1 --pretty=format:'%an%n%ae%n%ad%n%cn%n%ce%n%cd%n%s%n%n%b' "$1" |
172173
(
173174
read GIT_AUTHOR_NAME
@@ -258,19 +259,31 @@ copy_or_skip()
258259

259260
identical=
260261
p=
262+
gotparents=
261263
for parent in $newparents; do
262264
ptree=$(toptree_for_commit $parent) || exit $?
265+
[ -z "$ptree" ] && continue
263266
if [ "$ptree" = "$tree" ]; then
264267
# an identical parent could be used in place of this rev.
265268
identical="$parent"
266269
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"
269282
p="$p -p $parent"
270283
fi
271284
done
272285

273-
if [ -n "$identical" -a "$parentmatch" = "$identical" ]; then
286+
if [ -n "$identical" -a "$gotparents" = " $identical" ]; then
274287
echo $identical
275288
else
276289
copy_commit $rev $tree "$p" || exit $?

test.sh

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ check()
2424
check_equal()
2525
{
2626
echo
27-
echo "check a:" "$1"
28-
echo " b:" "$2"
27+
echo "check a:" "{$1}"
28+
echo " b:" "{$2}"
2929
if [ "$1" = "$2" ]; then
3030
return 0
3131
else
@@ -100,17 +100,17 @@ git branch sub2 FETCH_HEAD
100100
git subtree merge --prefix=subdir FETCH_HEAD
101101
git branch pre-split
102102

103-
split1=$(git subtree split --annotate='*' \
103+
spl1=$(git subtree split --annotate='*' \
104104
--prefix subdir --onto FETCH_HEAD --rejoin)
105-
echo "split1={$split1}"
106-
git branch split1 "$split1"
105+
echo "spl1={$spl1}"
106+
git branch spl1 "$spl1"
107107

108108
create subdir/main-sub8
109109
git commit -m 'main-sub8'
110110

111111
cd ../subproj
112-
git fetch ../mainline split1
113-
git branch split1 FETCH_HEAD
112+
git fetch ../mainline spl1
113+
git branch spl1 FETCH_HEAD
114114
git merge FETCH_HEAD
115115

116116
create sub9
@@ -123,14 +123,14 @@ git branch split2 "$split2"
123123
create subdir/main-sub10
124124
git commit -m 'main-sub10'
125125

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"
128128

129129
cd ../subproj
130-
git fetch ../mainline split3
131-
git branch split3 FETCH_HEAD
130+
git fetch ../mainline spl3
131+
git branch spl3 FETCH_HEAD
132132
git merge FETCH_HEAD
133-
git branch subproj-merge-split3
133+
git branch subproj-merge-spl3
134134

135135
chkm="main4 main6"
136136
chkms="main-sub10 main-sub5 main-sub7 main-sub8"
@@ -147,9 +147,9 @@ allchanges=$(git log --name-only --pretty=format:'' | sort | fixnl)
147147
check_equal "$allchanges" "$chkms $chks"
148148

149149
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
153153

154154
# make sure exactly the right set of files ends up in the mainline
155155
mainfiles=$(git ls-files | fixnl)
@@ -162,5 +162,12 @@ check_equal "$mainfiles" "$chkm $chkms_sub $chks_sub"
162162
allchanges=$(git log --name-only --pretty=format:'' | sort | fixnl)
163163
check_equal "$allchanges" "$chkm $chkms $chks $chkms_sub"
164164

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+
165172
echo
166173
echo 'ok'

0 commit comments

Comments
 (0)