subtree: make --ignore-joins pay attention to adds

Changes the behavior of --ignore-joins to always consider a subtree add commit, and ignore only splits and squashes. The --ignore-joins option is documented to ignore prior --rejoin commits. However, it additionally ignored subtree add commits generated when a subtree was initially added to a repo. Due to the logic which determines whether a commit is a mainline commit or a subtree commit (namely, the presence or absence of content in the subtree prefix) this causes commits before the initial add to appear to be part of the subtree. An --ignore-joins split would therefore consider those commits part of the subtree history and include them at the beginning of the synthetic history, causing the resulting hashes to be incorrect for all later commits. Signed-off-by: Strain, Roger L <roger.strain@swri.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Strain, Roger L committed Sep 28, 2018 at 13:35 UTC dd21d43b58ee3ce1b9801b5121fead0298961be1
1 file changed +7 -7
contrib/subtree/git-subtree.sh
+7 -7
@@ -340,7 +340,12 @@ find_existing_splits () {
340 revs="$2"
341 main=
342 sub=
343 - git log --grep="^git-subtree-dir: $dir/*\$" \
343 + local grep_format="^git-subtree-dir: $dir/*\$"
344 + if test -n "$ignore_joins"
345 + then
346 + grep_format="^Add '$dir/' from commit '"
347 + fi
348 + git log --grep="$grep_format" \
349 --no-show-signature --pretty=format:'START %H%n%s%n%n%b%nEND%n' $revs |
350 while read a b junk
351 do
@@ -730,12 +735,7 @@ cmd_split () {
735 done
736 fi
737
733 - if test -n "$ignore_joins"
734 - then
735 - unrevs=
736 - else
737 - unrevs="$(find_existing_splits "$dir" "$revs")"
738 - fi
738 + unrevs="$(find_existing_splits "$dir" "$revs")"
739
740 # We can't restrict rev-list to only $dir here, because some of our
741 # parents have the $dir contents the root, and those won't match.