git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* How to detect if a tree is in status "merge"?
@ 2019-12-08 10:55 Olaf Hering
  2019-12-09 21:04 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Olaf Hering @ 2019-12-08 10:55 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 348 bytes --]

Is there a way to detect (from a script) if the current working tree is in state 'merge'?

Right 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.

Thanks,
Olaf

[-- Attachment #2: Digitale Signatur von OpenPGP --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How to detect if a tree is in status "merge"?
  2019-12-08 10:55 How to detect if a tree is in status "merge"? Olaf Hering
@ 2019-12-09 21:04 ` Junio C Hamano
  2019-12-10  9:55   ` Olaf Hering
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2019-12-09 21:04 UTC (permalink / raw)
  To: Olaf Hering; +Cc: git

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.

Are you trying to go into a repository with an unknown state, see if
there is anything to commit, and then commit whatever is in the
working tree and/or in the index?  Perhaps you are doing so with
some condition to avoid recording random mess (e.g. avoid doing a
commit if the index is still unmerged, i.e. "git ls-files -u" gives
something, as "git commit -a" from such a state may record working
tree files in an unusable contents with conflict markers)?

The way "git commit" that is forbidden to create an empty commit
(i.e. a single-parent commit whose tree is identical to the tree of
its sole parent) is to see if the index to be made into a tree to be
committed is different from the tree of HEAD (i.e. "diff-index HEAD"
must not be empty) but still allow an otherwise empty commit to be
made if MERGE_HEAD exists (i.e. the resulting commit will be a no-op
relative to the previous tip of the branch, marking everything done
on the side-branch to now have been integrated---this happens when a
side branch gets merged to 'master' but a better solution is already
there).


> Right 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.

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?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How to detect if a tree is in status "merge"?
  2019-12-09 21:04 ` Junio C Hamano
@ 2019-12-10  9:55   ` Olaf Hering
  0 siblings, 0 replies; 3+ messages in thread
From: Olaf Hering @ 2019-12-10  9:55 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 1303 bytes --]

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

[-- Attachment #2: Digitale Signatur von OpenPGP --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-12-10 10:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-08 10:55 How to detect if a tree is in status "merge"? Olaf Hering
2019-12-09 21:04 ` Junio C Hamano
2019-12-10  9:55   ` Olaf Hering

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).