git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: How to detect if a tree is in status "merge"?

From
Olaf Hering <olaf@aepfle.de>
Date
Dec 10, 2019, 09:55 UTC
Message-ID
<20191210105545.66768b7a.olaf@aepfle.de>
In-Reply-To
<xmqqzhg1tdm9.fsf@gitster-ct.c.googlers.com>

Am Mon, 09 Dec 2019 13:04:14 -0800 schrieb Junio C Hamano <gitster@pobox.com>:

> Olaf Hering <olaf@aepfle.de> writes:
> > Is there a way to detect (from a script) if the current working tree is in state 'merge'?  
> The first step is to define what "state 'merge'" is, I think.

I do a fresh clone of a remote repository, checkout the target branch, then merge some other branch into it. Usually the 'git status' command gives me a list of files. In case it creates some output, 'git commit' is called. In case there is '^UU' in the output, manual intervention is required prior commit.

In this case the resolved conflict resulted in no changes. I do remember a plain 'git status' showed something like 'a merge is going on'. Apparently there is no easy way to get this state from a git command. But as you said I may be able to test for existence of files in the .git directory. I will try to recreate the state to repeat this merge.

> Why are you scripting around "git commit"?  Doesn't "git commit"
> refrain from creating an empty commit when there is nothing to
> commit anyway, unless it is recording a merge whose result happens
> to be a no-op?

'git commit' errors out if there is nothing to commit. But in this case it would have to create a merge commit.

Olaf
Previous: Junio C Hamano
Message 3 of 3 in “How to detect if a tree is in status "merge"?”
  1. Olaf HeringDec 8, 2019
  2. Junio C HamanoDec 9, 2019
  3. Olaf HeringDec 10, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.