git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jasmin Oster <JOster@anexia.com>
Cc: "git@vger.kernel.org" <git@vger.kernel.org>
Subject: Re: git-merge: --no-commit is not respected on a fresh repository
Date: Wed, 03 Apr 2024 10:29:14 -0700	[thread overview]
Message-ID: <xmqqv84y73th.fsf@gitster.g> (raw)
In-Reply-To: <22efe19e-de44-4b6d-8e8b-57e2bddb321e@anexia.com> (Jasmin Oster's message of "Wed, 3 Apr 2024 13:26:53 +0000")

Jasmin Oster <JOster@anexia.com> writes:

> 1. Create a new repository: $ git init
> 2. Add a remote: $ git remote add foo ../<path-to-another-repo>
> 3. Fetch everything: $ git fetch --all
> 4. Initiate a subtree merge: $ git merge -s our --no-commit foo/main

This is expected.  We are not creating any new commit, so it is
following the --no-commit option to the letter.  Obviously it is
different from what you expected to see, though ;-)

The "merge into void" first came to "git pull $URL $branch" (no
other options) where people tried to pull into a freshly created
repository, where it was very clear that they wanted to have a copy
of the upstream branch.  The "git pull" implementation of the
"pulling into void" feature forgot that curious users may give
"--no-commit", and just always fast-forwarded to the merged commit
without checking if such an option was given.

The behaviour you are seeing was inherited into "git merge".  It
also always fast-forwards to the merged commit, ignoring the option.

In either case, there is no new commit created.  The history you are
seeing is the exact history of the upstream.  If you want to
dissociate your history from theirs and start your history anew:

    $ git merge foo/main
    $ git checkout --orphan master

would give you an unborn branch "master", with the merge result in
the working tree and in the index, without any history behind it.
If you wanted to, you can then rename it to main from this state
with:

    $ git branch -M master main

We could make it more explicit with a patch like the following, but
it probably is not worth it.  I dunno.

 builtin/merge.c | 2 ++
 builtin/pull.c  | 2 ++
 2 files changed, 4 insertions(+)

diff --git c/builtin/merge.c w/builtin/merge.c
index 1cbd6a899c..1c3165e99a 100644
--- c/builtin/merge.c
+++ w/builtin/merge.c
@@ -1434,6 +1434,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 		struct object_id *remote_head_oid;
 		if (squash)
 			die(_("Squash commit into empty head not supported yet"));
+		if (!option_commit)
+			die(_("--no-commit into empty head not supported"));
 		if (fast_forward == FF_NO)
 			die(_("Non-fast-forward commit does not make sense into "
 			    "an empty head"));
diff --git c/builtin/pull.c w/builtin/pull.c
index 72cbb76d52..98c11ecc55 100644
--- c/builtin/pull.c
+++ w/builtin/pull.c
@@ -1097,6 +1097,8 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
 	if (is_null_oid(&orig_head)) {
 		if (merge_heads.nr > 1)
 			die(_("Cannot merge multiple branches into empty head."));
+		if (opt_commit && !strcmp("--no-commit", opt_commit))
+			die(_("--no-commit into empty head not supported"));
 		ret = pull_into_void(merge_heads.oid, &curr_head);
 		goto cleanup;
 	}


      reply	other threads:[~2024-04-03 17:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-03 13:26 git-merge: --no-commit is not respected on a fresh repository Jasmin Oster
2024-04-03 17:29 ` Junio C Hamano [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqv84y73th.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=JOster@anexia.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).