{"thread":{"id":"52407","subject":"How to detect if a tree is in status \"merge\"?","startedAt":"2019-12-08T10:55:34Z","lastAt":"2019-12-10T10:02:12Z","messageCount":3,"participants":["Olaf Hering","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"387714","messageId":"20191208115517.6b319a44.olaf@aepfle.de","threadId":"52407","inReplyTo":null,"subject":"How to detect if a tree is in status \"merge\"?","fromName":"Olaf Hering","fromEmail":"olaf@aepfle.de","sentAt":"2019-12-08T10:55:17Z","receivedAt":"2019-12-08T10:55:34Z","isPatch":false,"sender":{"key":"olaf@aepfle.de","avatar":"https://avatars.githubusercontent.com/u/942324?v=4"},"body":"Is there a way to detect (from a script) if the current working tree is in state 'merge'?\n\nRight now I had the case that a conflict resolution resulted in 'no pending changes'. As a result my \"git --no-pager status --porcelain --untracked-files=no | tee $t\" showed nothing, which skipped the required 'git commit' in my script.\n\nThanks,\nOlaf\n"},{"id":"387842","messageId":"xmqqzhg1tdm9.fsf@gitster-ct.c.googlers.com","threadId":"52407","inReplyTo":"20191208115517.6b319a44.olaf@aepfle.de","subject":"Re: How to detect if a tree is in status \"merge\"?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-12-09T21:04:14Z","receivedAt":"2019-12-09T21:04:22Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Olaf Hering <olaf@aepfle.de> writes:\n\n> Is there a way to detect (from a script) if the current working tree is in state 'merge'?\n\nThe first step is to define what \"state 'merge'\" is, I think.\n\nAre you trying to go into a repository with an unknown state, see if\nthere is anything to commit, and then commit whatever is in the\nworking tree and/or in the index?  Perhaps you are doing so with\nsome condition to avoid recording random mess (e.g. avoid doing a\ncommit if the index is still unmerged, i.e. \"git ls-files -u\" gives\nsomething, as \"git commit -a\" from such a state may record working\ntree files in an unusable contents with conflict markers)?\n\nThe way \"git commit\" that is forbidden to create an empty commit\n(i.e. a single-parent commit whose tree is identical to the tree of\nits sole parent) is to see if the index to be made into a tree to be\ncommitted is different from the tree of HEAD (i.e. \"diff-index HEAD\"\nmust not be empty) but still allow an otherwise empty commit to be\nmade if MERGE_HEAD exists (i.e. the resulting commit will be a no-op\nrelative to the previous tip of the branch, marking everything done\non the side-branch to now have been integrated---this happens when a\nside branch gets merged to 'master' but a better solution is already\nthere).\n\n\n> Right now I had the case that a conflict resolution resulted in\n> 'no pending changes'. As a result my \"git --no-pager status\n> --porcelain --untracked-files=no | tee $t\" showed nothing, which\n> skipped the required 'git commit' in my script.\n\nWhy are you scripting around \"git commit\"?  Doesn't \"git commit\"\nrefrain from creating an empty commit when there is nothing to\ncommit anyway, unless it is recording a merge whose result happens\nto be a no-op?\n"},{"id":"387875","messageId":"20191210105545.66768b7a.olaf@aepfle.de","threadId":"52407","inReplyTo":"xmqqzhg1tdm9.fsf@gitster-ct.c.googlers.com","subject":"Re: How to detect if a tree is in status \"merge\"?","fromName":"Olaf Hering","fromEmail":"olaf@aepfle.de","sentAt":"2019-12-10T09:55:45Z","receivedAt":"2019-12-10T10:02:12Z","isPatch":false,"sender":{"key":"olaf@aepfle.de","avatar":"https://avatars.githubusercontent.com/u/942324?v=4"},"body":"Am Mon, 09 Dec 2019 13:04:14 -0800\nschrieb Junio C Hamano <gitster@pobox.com>:\n\n> Olaf Hering <olaf@aepfle.de> writes:\n> > Is there a way to detect (from a script) if the current working tree is in state 'merge'?  \n> The first step is to define what \"state 'merge'\" is, I think.\n\nI do a fresh clone of a remote repository, checkout the target branch,\nthen merge some other branch into it. Usually the 'git status' command\ngives me a list of files. In case it creates some output, 'git commit'\nis called. In case there is '^UU' in the output, manual intervention\nis required prior commit.\n\nIn this case the resolved conflict resulted in no changes. I do remember\na plain 'git status' showed something like 'a merge is going on'.\nApparently there is no easy way to get this state from a git command.\nBut as you said I may be able to test for existence of files in the\n.git directory. I will try to recreate the state to repeat this merge.\n\n> Why are you scripting around \"git commit\"?  Doesn't \"git commit\"\n> refrain from creating an empty commit when there is nothing to\n> commit anyway, unless it is recording a merge whose result happens\n> to be a no-op?\n\n'git commit' errors out if there is nothing to commit.\nBut in this case it would have to create a merge commit.\n\nOlaf\n"}]}