Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CEBCDC43603 for ; Mon, 9 Dec 2019 21:04:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9C575206E0 for ; Mon, 9 Dec 2019 21:04:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=pobox.com header.i=@pobox.com header.b="gnBh7QFS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726642AbfLIVEV (ORCPT ); Mon, 9 Dec 2019 16:04:21 -0500 Received: from pb-smtp20.pobox.com ([173.228.157.52]:54034 "EHLO pb-smtp20.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726408AbfLIVEV (ORCPT ); Mon, 9 Dec 2019 16:04:21 -0500 Received: from pb-smtp20.pobox.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 1F8B3A9EDD; Mon, 9 Dec 2019 16:04:19 -0500 (EST) (envelope-from junio@pobox.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=RGvxXz+EmhNLtM9q3BM23q8vjY8=; b=gnBh7Q FS4UuTS83KTuCJsfZGfDC52yirt6nWAWpzllzNhmMs7EJxmCZyamPoPm2Ni+fVlo RVqwTvZ1RK8Ho9kMyDDk+dUiUPV3Tvu8yWzWHcDCAxAoCRsnK2pq4fSxu2UfId9n JwD81knzpQ+W15TdFtJ8spQQT2XOh6i23vefM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=sasl; b=cXl+1/zf0mO9mZhMs9j7FPoG3W0NG10x nvulO6LOqFypQfZj3CkmL+NhHxm6kq3LscOKzIABXALhKRm+m/OWILR4/q/n/IH1 5HGBc3PZNNwPQUtFAlWFhBkFp9GFS6NLsDgB7gzJJnMlhazEhFXIzSa5VVQL+pJu 9JjPcFitQqU= Received: from pb-smtp20.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 174A3A9EDC; Mon, 9 Dec 2019 16:04:19 -0500 (EST) (envelope-from junio@pobox.com) Received: from pobox.com (unknown [34.76.80.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp20.pobox.com (Postfix) with ESMTPSA id 3F47CA9ED9; Mon, 9 Dec 2019 16:04:16 -0500 (EST) (envelope-from junio@pobox.com) From: Junio C Hamano To: Olaf Hering Cc: git@vger.kernel.org Subject: Re: How to detect if a tree is in status "merge"? References: <20191208115517.6b319a44.olaf@aepfle.de> Date: Mon, 09 Dec 2019 13:04:14 -0800 In-Reply-To: <20191208115517.6b319a44.olaf@aepfle.de> (Olaf Hering's message of "Sun, 8 Dec 2019 11:55:17 +0100") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Pobox-Relay-ID: 75A44D70-1AC7-11EA-9156-B0405B776F7B-77302942!pb-smtp20.pobox.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Olaf Hering 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?