Skip to content

Commit 427c6d0

Browse files
committed
Merge branch 'jc/fake-ancestor-with-non-blobs' into maint
Rebasing the history of superproject with change in the submodule has been broken since v1.7.12. * jc/fake-ancestor-with-non-blobs: apply: diagnose incomplete submodule object name better apply: simplify build_fake_ancestor() git-am: record full index line in the patch used while rebasing
2 parents 45bb6cb + e28efb1 commit 427c6d0

File tree

3 files changed

+45
-17
lines changed

3 files changed

+45
-17
lines changed

builtin/apply.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3609,28 +3609,30 @@ static void build_fake_ancestor(struct patch *list, const char *filename)
36093609
* worth showing the new sha1 prefix, but until then...
36103610
*/
36113611
for (patch = list; patch; patch = patch->next) {
3612-
const unsigned char *sha1_ptr;
36133612
unsigned char sha1[20];
36143613
struct cache_entry *ce;
36153614
const char *name;
36163615

36173616
name = patch->old_name ? patch->old_name : patch->new_name;
36183617
if (0 < patch->is_new)
36193618
continue;
3620-
else if (get_sha1_blob(patch->old_sha1_prefix, sha1))
3621-
/* git diff has no index line for mode/type changes */
3622-
if (!patch->lines_added && !patch->lines_deleted) {
3623-
if (get_current_sha1(patch->old_name, sha1))
3624-
die("mode change for %s, which is not "
3625-
"in current HEAD", name);
3626-
sha1_ptr = sha1;
3627-
} else
3628-
die("sha1 information is lacking or useless "
3629-
"(%s).", name);
3630-
else
3631-
sha1_ptr = sha1;
36323619

3633-
ce = make_cache_entry(patch->old_mode, sha1_ptr, name, 0, 0);
3620+
if (S_ISGITLINK(patch->old_mode)) {
3621+
if (get_sha1_hex(patch->old_sha1_prefix, sha1))
3622+
die("submoule change for %s without full index name",
3623+
name);
3624+
} else if (!get_sha1_blob(patch->old_sha1_prefix, sha1)) {
3625+
; /* ok */
3626+
} else if (!patch->lines_added && !patch->lines_deleted) {
3627+
/* mode-only change: update the current */
3628+
if (get_current_sha1(patch->old_name, sha1))
3629+
die("mode change for %s, which is not "
3630+
"in current HEAD", name);
3631+
} else
3632+
die("sha1 information is lacking or useless "
3633+
"(%s).", name);
3634+
3635+
ce = make_cache_entry(patch->old_mode, sha1, name, 0, 0);
36343636
if (!ce)
36353637
die(_("make_cache_entry failed for path '%s'"), name);
36363638
if (add_index_entry(&result, ce, ADD_CACHE_OK_TO_ADD))

git-am.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ do
664664
sed -e '1,/^$/d' >"$dotest/msg-clean"
665665
echo "$commit" >"$dotest/original-commit"
666666
get_author_ident_from_commit "$commit" >"$dotest/author-script"
667-
git diff-tree --root --binary "$commit" >"$dotest/patch"
667+
git diff-tree --root --binary --full-index "$commit" >"$dotest/patch"
668668
else
669669
git mailinfo $keep $no_inbody_headers $scissors $utf8 "$dotest/msg" "$dotest/patch" \
670670
<"$dotest/$msgnum" >"$dotest/info" ||

t/t7402-submodule-rebase.sh

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Copyright (c) 2008 Johannes Schindelin
44
#
55

6-
test_description='Test rebasing and stashing with dirty submodules'
6+
test_description='Test rebasing, stashing, etc. with submodules'
77

88
. ./test-lib.sh
99

@@ -20,7 +20,8 @@ test_expect_success setup '
2020
echo second line >> file &&
2121
(cd submodule && git pull) &&
2222
test_tick &&
23-
git commit -m file-and-submodule -a
23+
git commit -m file-and-submodule -a &&
24+
git branch added-submodule
2425
2526
'
2627

@@ -89,4 +90,29 @@ test_expect_success 'stash with a dirty submodule' '
8990
9091
'
9192

93+
test_expect_success 'rebasing submodule that should conflict' '
94+
git reset --hard &&
95+
git checkout added-submodule &&
96+
git add submodule &&
97+
test_tick &&
98+
git commit -m third &&
99+
(
100+
cd submodule &&
101+
git commit --allow-empty -m extra
102+
) &&
103+
git add submodule &&
104+
test_tick &&
105+
git commit -m fourth &&
106+
107+
test_must_fail git rebase --onto HEAD^^ HEAD^ HEAD^0 &&
108+
git ls-files -s submodule >actual &&
109+
(
110+
cd submodule &&
111+
echo "160000 $(git rev-parse HEAD^) 1 submodule" &&
112+
echo "160000 $(git rev-parse HEAD^^) 2 submodule" &&
113+
echo "160000 $(git rev-parse HEAD) 3 submodule"
114+
) >expect &&
115+
test_cmp expect actual
116+
'
117+
92118
test_done

0 commit comments

Comments
 (0)