зеркало из https://github.com/microsoft/git.git
Merge branch 'jv/merge-nothing-into-void' into maint
"git merge FETCH_HEAD" dereferenced NULL pointer when merging nothing into an unborn history (which is arguably unusual usage, which perhaps was the reason why nobody noticed it). * jv/merge-nothing-into-void: merge: fix NULL pointer dereference when merging nothing into void
This commit is contained in:
Коммит
a5953f6818
|
@ -1257,12 +1257,12 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
|
||||||
builtin_merge_options);
|
builtin_merge_options);
|
||||||
|
|
||||||
if (!head_commit) {
|
if (!head_commit) {
|
||||||
struct commit *remote_head;
|
|
||||||
/*
|
/*
|
||||||
* If the merged head is a valid one there is no reason
|
* If the merged head is a valid one there is no reason
|
||||||
* to forbid "git merge" into a branch yet to be born.
|
* to forbid "git merge" into a branch yet to be born.
|
||||||
* We do the same for "git pull".
|
* We do the same for "git pull".
|
||||||
*/
|
*/
|
||||||
|
unsigned char *remote_head_sha1;
|
||||||
if (squash)
|
if (squash)
|
||||||
die(_("Squash commit into empty head not supported yet"));
|
die(_("Squash commit into empty head not supported yet"));
|
||||||
if (fast_forward == FF_NO)
|
if (fast_forward == FF_NO)
|
||||||
|
@ -1270,13 +1270,13 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
|
||||||
"an empty head"));
|
"an empty head"));
|
||||||
remoteheads = collect_parents(head_commit, &head_subsumed,
|
remoteheads = collect_parents(head_commit, &head_subsumed,
|
||||||
argc, argv, NULL);
|
argc, argv, NULL);
|
||||||
remote_head = remoteheads->item;
|
if (!remoteheads)
|
||||||
if (!remote_head)
|
|
||||||
die(_("%s - not something we can merge"), argv[0]);
|
die(_("%s - not something we can merge"), argv[0]);
|
||||||
if (remoteheads->next)
|
if (remoteheads->next)
|
||||||
die(_("Can merge only exactly one commit into empty head"));
|
die(_("Can merge only exactly one commit into empty head"));
|
||||||
read_empty(remote_head->object.oid.hash, 0);
|
remote_head_sha1 = remoteheads->item->object.oid.hash;
|
||||||
update_ref("initial pull", "HEAD", remote_head->object.oid.hash,
|
read_empty(remote_head_sha1, 0);
|
||||||
|
update_ref("initial pull", "HEAD", remote_head_sha1,
|
||||||
NULL, 0, UPDATE_REFS_DIE_ON_ERR);
|
NULL, 0, UPDATE_REFS_DIE_ON_ERR);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
|
@ -753,4 +753,14 @@ test_expect_success 'merge detects mod-256 conflicts (resolve)' '
|
||||||
test_must_fail git merge -s resolve master
|
test_must_fail git merge -s resolve master
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'merge nothing into void' '
|
||||||
|
git init void &&
|
||||||
|
(
|
||||||
|
cd void &&
|
||||||
|
git remote add up .. &&
|
||||||
|
git fetch up &&
|
||||||
|
test_must_fail git merge FETCH_HEAD
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
Загрузка…
Ссылка в новой задаче