From patchwork Thu Mar 21 06:53:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10862963 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2A0A71515 for ; Thu, 21 Mar 2019 06:53:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 01BD52A041 for ; Thu, 21 Mar 2019 06:53:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E9D222A045; Thu, 21 Mar 2019 06:53:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CBC652A041 for ; Thu, 21 Mar 2019 06:53:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727859AbfCUGxl (ORCPT ); Thu, 21 Mar 2019 02:53:41 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:43274 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727823AbfCUGxl (ORCPT ); Thu, 21 Mar 2019 02:53:41 -0400 Received: by mail-pf1-f194.google.com with SMTP id c8so3679340pfd.10 for ; Wed, 20 Mar 2019 23:53:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=oVZzTl2JlCGgMg7xahXxobM3HiiIN2E2+2vkHvDEUqQ=; b=WUM6I3t4HQVjihTkWO54IYZlEvXPH6WwOJEYblxOLSlAKENmiH+ck+k0YrCxFXFDSu qQfaaRXJweRwAYgfiTFJUnfFoDdQfgawciIz6BYPJhPJHSCsY84Eu0VZmL3mOKvNsBcC zI0AfZ8V9wwz33Vb4LAHVRXhtN3EBoGZjmFbzE9VJnTLTkm5Bj3xBqk5sKxsxzj4L4fv nXtKF38eIE7aRiIBTmiLELD1lBNNUJnIUDVTKWCbtrTqAE3pohwbh2dmfBI3MXMrbFWY CWWkYxmlOO+z5H6G25vpL5v+Vn7KGI5F4USQnScNOMS62Gfc3CD8nJTbQADiebFGda/j KX5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=oVZzTl2JlCGgMg7xahXxobM3HiiIN2E2+2vkHvDEUqQ=; b=J4zM52+SoFiHQJwqWQ/w4sNXoYo6qB+P6PTEoTQEXGD1k4x2L5uUXxoF3BG3KTLtgg zvJLm3FTSwZL04Ti1wGPRV3qCOyrsmyIEJ2JPIvKctnlPITjmQQjqQ+NUyvyLHhUNFU2 2lETpgc5vWb7FeKCq1VXt8AVXDVyJA1ixB6LnPqkKkLK944UZLIMX/ii5wQWzvIYwxwQ ZH3ChXBBOePErwICnsVsD1PhyR/HiE2XVGqmxJvggsqZIUhcj0F+d9bCwJIz4IWve371 tH9BAAYie4pIGY0prDx1hqWl3uyL4BlvW9bUol+GafjfG1f3vlpELWgNffgvcw8qxPq4 PYRA== X-Gm-Message-State: APjAAAWpG9AiwOQyBVSzS6U9dP63QYbjZisqEhAylt6xIZbUdDtQXqyB 5ff+Ic52fJexHyO+msMbsOb0lofw8g4= X-Google-Smtp-Source: APXvYqyrptLYNSDW4qwxQPHLMi1sI1dsivEA0FLIlgeo71M7S08eQYRnQ/ZQUTcEnNZ5GS3oo9CWkQ== X-Received: by 2002:a17:902:2848:: with SMTP id e66mr2005512plb.181.1553151220308; Wed, 20 Mar 2019 23:53:40 -0700 (PDT) Received: from archbookpro.localdomain (c-73-222-73-77.hsd1.ca.comcast.net. [73.222.73.77]) by smtp.gmail.com with ESMTPSA id i64sm5457323pfb.112.2019.03.20.23.53.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Mar 2019 23:53:39 -0700 (PDT) Date: Wed, 20 Mar 2019 23:53:37 -0700 From: Denton Liu To: Git Mailing List Cc: Denton Liu , Eric Sunshine , Junio C Hamano , Phillip Wood , Ramsay Jones , SZEDER =?iso-8859-1?q?G=E1bor?= Subject: [PATCH v9 01/11] t7600: clean up style Message-ID: <3274886c16141fe1b5c228e02d75f623f79a0539.1553150827.git.liu.denton@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.3 (2019-02-01) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Clean up the 'merge --squash c3 with c7' test by removing some unnecessary braces and removing a pipe. Also, generally cleanup style by unindenting a here-doc, removing stray spaces after a redirection operator and allowing sed to open its own input instead of redirecting input from the shell. Helped-by: SZEDER Gábor Helped-by: Eric Sunshine Helped-by: Junio C Hamano Signed-off-by: Denton Liu --- t/t7600-merge.sh | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh index 106148254d..2f4c2801fb 100755 --- a/t/t7600-merge.sh +++ b/t/t7600-merge.sh @@ -233,17 +233,16 @@ test_expect_success 'merge --squash c3 with c7' ' cat result.9z >file && git commit --no-edit -a && - { - cat <<-EOF - Squashed commit of the following: + cat >expect <<-EOF && + Squashed commit of the following: - $(git show -s c7) + $(git show -s c7) - # Conflicts: - # file - EOF - } >expect && - git cat-file commit HEAD | sed -e '1,/^$/d' >actual && + # Conflicts: + # file + EOF + git cat-file commit HEAD >raw && + sed -e '1,/^$/d' raw >actual && test_cmp expect actual ' @@ -680,10 +679,10 @@ cat >editor <<\EOF ( echo "Merge work done on the side branch c1" echo - cat <"$1" + cat "$1" ) >"$1.tmp" && mv "$1.tmp" "$1" # strip comments and blank lines from end of message -sed -e '/^#/d' < "$1" | sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' > expected +sed -e '/^#/d' "$1" | sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' >expected EOF chmod 755 editor @@ -768,14 +767,14 @@ test_expect_success 'set up mod-256 conflict scenario' ' git commit -m base && # one side changes the first line of each to "master" - sed s/-1/-master/ tmp && + sed s/-1/-master/ file >tmp && mv tmp file && git commit -am master && # and the other to "side"; merging the two will # yield 256 separate conflicts git checkout -b side HEAD^ && - sed s/-1/-side/ tmp && + sed s/-1/-side/ file >tmp && mv tmp file && git commit -am side ' @@ -814,7 +813,7 @@ EOF test_expect_success EXECKEEPSPID 'killed merge can be completed with --continue' ' git reset --hard c0 && ! "$SHELL_PATH" -c '\'' - echo kill -TERM $$ >> .git/FAKE_EDITOR + echo kill -TERM $$ >>.git/FAKE_EDITOR GIT_EDITOR=.git/FAKE_EDITOR export GIT_EDITOR exec git merge --no-ff --edit c1'\'' && From patchwork Thu Mar 21 06:53:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10862965 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 958F61823 for ; Thu, 21 Mar 2019 06:53:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 76AD42A041 for ; Thu, 21 Mar 2019 06:53:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6A31D2A043; Thu, 21 Mar 2019 06:53:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EBDC52A042 for ; Thu, 21 Mar 2019 06:53:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727867AbfCUGxp (ORCPT ); Thu, 21 Mar 2019 02:53:45 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:46753 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727823AbfCUGxo (ORCPT ); Thu, 21 Mar 2019 02:53:44 -0400 Received: by mail-pf1-f196.google.com with SMTP id 9so3439326pfj.13 for ; Wed, 20 Mar 2019 23:53:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=zONT9wgeUtMRr2psstEvePElRUfzKGh9VjRi7CUmC5c=; b=r9FNyMlp1EaqOGF+SLgcL442+qQVzv86lui4hv4nQaRc1GXuDe4fbH/aAuCsK8eIqf zBTpxOlmGKHetz60dKKKSRJ034zP4QHcrG8hDYCYruygoAwvboDYWNSjdmyMs/uNU5Kt JplfXjqmIhHn8ToZClnIt77ikBuQNpp+VPW1ZQZUJpepkxPYnjFXl868k+iwocf6aVsn iH0yYsvXlK3wxHxk7ugOcHwcMOqCaHAZXyDDkxjkoks5quzut7zuSDn2Q+KZSKyPkd2/ pOJi673VML+YEnZGBF+3QiBs5n0Z9iIvFgx+dg+HtAH3puq7JkUaClHGXTP8uABXAtvs rqvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=zONT9wgeUtMRr2psstEvePElRUfzKGh9VjRi7CUmC5c=; b=nkjeQR/BVwfkXMnNUHXv5jGb++MlF1fwgvlUMsfc3/wIoPdAjrGUv4t7XpHlPXaBbU 8s0eXYYiotSPqq2wD56007e+Mt5pIjqu8Agbee0he9EcMcOH3YsSpRGt1tYzXqF2/7vZ jK6cPvpF90YI7HLuHY37h56T72QRFMHQTZSvTI/7fPQHhEoBHJkYpwAUTnGxZYcgaEhl dxLoQ7x3/phybNJH05WpLtYka8BBw1NVVh7iehrKgU9aPk6VTb811rG4HsvGScE+ts3A YU+npZtfceiFROTsz7sYwxbmoBeRmHq+nD+SgNULkY1Np7ROtMGvn/jvKHZsu9lRcwyD BFUQ== X-Gm-Message-State: APjAAAW1amYsKZ8BNyjK4WfAGrsHjPRnOb7VXhoO9Rqi+MYVLSv49mRQ T0h9BKZ5j8kC72xnMPuXOp2CmJ8OXns= X-Google-Smtp-Source: APXvYqwDrv2cMhIaZ8ZRNwYrr+sGLTZMJBdIiUCkuJi4mbeI/vEmVg9ADmrtmsJcDe4HrUFXUGlKEA== X-Received: by 2002:a62:be08:: with SMTP id l8mr1850354pff.162.1553151223134; Wed, 20 Mar 2019 23:53:43 -0700 (PDT) Received: from archbookpro.localdomain (c-73-222-73-77.hsd1.ca.comcast.net. [73.222.73.77]) by smtp.gmail.com with ESMTPSA id a13sm4277847pgw.91.2019.03.20.23.53.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Mar 2019 23:53:42 -0700 (PDT) Date: Wed, 20 Mar 2019 23:53:40 -0700 From: Denton Liu To: Git Mailing List Cc: Denton Liu , Eric Sunshine , Junio C Hamano , Phillip Wood , Ramsay Jones , SZEDER =?iso-8859-1?q?G=E1bor?= Subject: [PATCH v9 02/11] t3507: clean up style Message-ID: <7d8d39b93002d1416eaf730f3e8262360c925c42.1553150827.git.liu.denton@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.3 (2019-02-01) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Remove space after redirection operators for style. Also, remove a git command which was upstream of a pipe. Finally, let grep and sed open their own input instead of letting the shell redirect the input. Helped-by: SZEDER Gábor Signed-off-by: Denton Liu --- t/t3507-cherry-pick-conflict.sh | 42 ++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/t/t3507-cherry-pick-conflict.sh b/t/t3507-cherry-pick-conflict.sh index 0db166152a..777fb23d18 100755 --- a/t/t3507-cherry-pick-conflict.sh +++ b/t/t3507-cherry-pick-conflict.sh @@ -88,7 +88,7 @@ test_expect_success 'cherry-pick --no-commit does not set CHERRY_PICK_HEAD' ' test_expect_success 'cherry-pick w/dirty tree does not set CHERRY_PICK_HEAD' ' pristine_detach initial && - echo foo > foo && + echo foo >foo && test_must_fail git cherry-pick base && test_must_fail git rev-parse --verify CHERRY_PICK_HEAD ' @@ -96,7 +96,7 @@ test_expect_success 'cherry-pick w/dirty tree does not set CHERRY_PICK_HEAD' ' test_expect_success \ 'cherry-pick --strategy=resolve w/dirty tree does not set CHERRY_PICK_HEAD' ' pristine_detach initial && - echo foo > foo && + echo foo >foo && test_must_fail git cherry-pick --strategy=resolve base && test_must_fail git rev-parse --verify CHERRY_PICK_HEAD ' @@ -175,23 +175,23 @@ test_expect_success 'failed cherry-pick registers participants in index' ' git ls-files --stage foo && git checkout picked -- foo && git ls-files --stage foo - } > stages && + } >stages && sed " 1 s/ 0 / 1 / 2 s/ 0 / 2 / 3 s/ 0 / 3 / - " < stages > expected && + " stages >expected && git read-tree -u --reset HEAD && test_must_fail git cherry-pick picked && - git ls-files --stage --unmerged > actual && + git ls-files --stage --unmerged >actual && test_cmp expected actual ' test_expect_success 'failed cherry-pick describes conflict in work tree' ' pristine_detach initial && - cat <<-EOF > expected && + cat <<-EOF >expected && <<<<<<< HEAD a ======= @@ -201,14 +201,14 @@ test_expect_success 'failed cherry-pick describes conflict in work tree' ' test_must_fail git cherry-pick picked && - sed "s/[a-f0-9]*\.\.\./objid/" foo > actual && + sed "s/[a-f0-9]*\.\.\./objid/" foo >actual && test_cmp expected actual ' test_expect_success 'diff3 -m style' ' pristine_detach initial && git config merge.conflictstyle diff3 && - cat <<-EOF > expected && + cat <<-EOF >expected && <<<<<<< HEAD a ||||||| parent of objid picked @@ -220,14 +220,14 @@ test_expect_success 'diff3 -m style' ' test_must_fail git cherry-pick picked && - sed "s/[a-f0-9]*\.\.\./objid/" foo > actual && + sed "s/[a-f0-9]*\.\.\./objid/" foo >actual && test_cmp expected actual ' test_expect_success 'revert also handles conflicts sanely' ' git config --unset merge.conflictstyle && pristine_detach initial && - cat <<-EOF > expected && + cat <<-EOF >expected && <<<<<<< HEAD a ======= @@ -241,24 +241,24 @@ test_expect_success 'revert also handles conflicts sanely' ' git ls-files --stage foo && git checkout base -- foo && git ls-files --stage foo - } > stages && + } >stages && sed " 1 s/ 0 / 1 / 2 s/ 0 / 2 / 3 s/ 0 / 3 / - " < stages > expected-stages && + " stages >expected-stages && git read-tree -u --reset HEAD && head=$(git rev-parse HEAD) && test_must_fail git revert picked && newhead=$(git rev-parse HEAD) && - git ls-files --stage --unmerged > actual-stages && + git ls-files --stage --unmerged >actual-stages && test "$head" = "$newhead" && test_must_fail git update-index --refresh -q && test_must_fail git diff-index --exit-code HEAD && test_cmp expected-stages actual-stages && - sed "s/[a-f0-9]*\.\.\./objid/" foo > actual && + sed "s/[a-f0-9]*\.\.\./objid/" foo >actual && test_cmp expected actual ' @@ -284,7 +284,7 @@ test_expect_success 'revert --no-commit sets REVERT_HEAD' ' test_expect_success 'revert w/dirty tree does not set REVERT_HEAD' ' pristine_detach base && - echo foo > foo && + echo foo >foo && test_must_fail git revert base && test_must_fail git rev-parse --verify CHERRY_PICK_HEAD && test_must_fail git rev-parse --verify REVERT_HEAD @@ -319,7 +319,7 @@ test_expect_success 'failed commit does not clear REVERT_HEAD' ' test_expect_success 'revert conflict, diff3 -m style' ' pristine_detach initial && git config merge.conflictstyle diff3 && - cat <<-EOF > expected && + cat <<-EOF >expected && <<<<<<< HEAD a ||||||| objid picked @@ -331,7 +331,7 @@ test_expect_success 'revert conflict, diff3 -m style' ' test_must_fail git revert picked && - sed "s/[a-f0-9]*\.\.\./objid/" foo > actual && + sed "s/[a-f0-9]*\.\.\./objid/" foo >actual && test_cmp expected actual ' @@ -345,7 +345,7 @@ test_expect_success 'commit after failed cherry-pick does not add duplicated -s' pristine_detach initial && test_must_fail git cherry-pick -s picked-signed && git commit -a -s && - test $(git show -s |grep -c "Signed-off-by") = 1 + test $(git show -s >tmp && grep -c "Signed-off-by" tmp && rm tmp) = 1 ' test_expect_success 'commit after failed cherry-pick adds -s at the right place' ' @@ -359,7 +359,7 @@ test_expect_success 'commit after failed cherry-pick adds -s at the right place' Signed-off-by: C O Mitter # Conflicts: EOF - grep -e "^# Conflicts:" -e '^Signed-off-by' <.git/COMMIT_EDITMSG >actual && + grep -e "^# Conflicts:" -e '^Signed-off-by' .git/COMMIT_EDITMSG >actual && test_cmp expect actual && cat <<-\EOF >expected && @@ -378,7 +378,7 @@ test_expect_success 'commit --amend -s places the sign-off at the right place' ' # emulate old-style conflicts block mv .git/MERGE_MSG .git/MERGE_MSG+ && - sed -e "/^# Conflicts:/,\$s/^# *//" <.git/MERGE_MSG+ >.git/MERGE_MSG && + sed -e "/^# Conflicts:/,\$s/^# *//" .git/MERGE_MSG+ >.git/MERGE_MSG && git commit -a && git commit --amend -s && @@ -388,7 +388,7 @@ test_expect_success 'commit --amend -s places the sign-off at the right place' ' Signed-off-by: C O Mitter Conflicts: EOF - grep -e "^Conflicts:" -e '^Signed-off-by' <.git/COMMIT_EDITMSG >actual && + grep -e "^Conflicts:" -e '^Signed-off-by' .git/COMMIT_EDITMSG >actual && test_cmp expect actual ' From patchwork Thu Mar 21 06:53:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10862971 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D4B0D1823 for ; Thu, 21 Mar 2019 06:53:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B81CE2A041 for ; Thu, 21 Mar 2019 06:53:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC7FA2A043; Thu, 21 Mar 2019 06:53:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E2622A041 for ; Thu, 21 Mar 2019 06:53:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727874AbfCUGxr (ORCPT ); Thu, 21 Mar 2019 02:53:47 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:43548 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727823AbfCUGxq (ORCPT ); Thu, 21 Mar 2019 02:53:46 -0400 Received: by mail-pg1-f194.google.com with SMTP id l11so3557748pgq.10 for ; Wed, 20 Mar 2019 23:53:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=mhhn8/9vG8AfLbuSjBMwFQP0SA6lkwEbsU0fRDZnILY=; b=jMUyuQ44i6BaL8w3+Mw7yjMIX5TdMKtAVevw58um07U7mDru1UHGENWgdgQ1fvwNeh RY2V0/LBS3pBwtS0qhiheVbSOPc9U4DsgInhrE+FzMksUcEKZ88SD6VyMeJIwRI2nuwI MXLp5G0CCTQomsydLcVeRScFbIivkDjXftH2PRs6HWNaTjAEo48c+D587mpeaLDdR47A bGbpFAwfGvSUTwhOvrYbOnKNtWzU9LytoYXai1nyRJvwInmj+wYX6brcU1163o9su6Jy CHJJDu5sg4PSTyysF+IE6My//LPZ8neCx6395efGdxcRXIqEmyy/fMIXoMGL8XTBC3yY /oiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=mhhn8/9vG8AfLbuSjBMwFQP0SA6lkwEbsU0fRDZnILY=; b=O5rCMv/+NY9Yw32WWYp6XDbccybdJg1LExeFsJ6F88n1ceiw5lr13l2sk4QtFun1ve gSVfRCRAIDO6Q0dIdZU2HZ0ktDkoRx7pkSQJz2bdEt3u1OHLGkSZtFZirBGq9xjbMYkB 5IAJN0d1EDiN8a+m+OcdXA54V9gJrGiAFfvFpf9cdfBqYFsFe9eu8JXDxtL2YT/tEY4f rj0lb1jPbXoRqcc5wgGhdRxeN9S0uDeyIM11HwVfoTM2iA37S3JokJ9fACIW3CoBIIk0 EuC/y7U2P9UjMlT5esEgd2pkdWurvNZSH07CKEeOwMNN5OPT3GueHfnnSAAYfmiHdya+ sngA== X-Gm-Message-State: APjAAAUD3Wpj3chHX6apUHBulq6bNYoopNfKxFCsbG+ZNOU8poV9wWCT YoLgjQ090nNELwpJFOSqWND/6dkCWZ4= X-Google-Smtp-Source: APXvYqweNyhL3oBjYINpIX+3uKLD1zT/idPesGNrePdN0S3JyDp6g23APV5oVWz11gxr6RzUE7NRmg== X-Received: by 2002:a63:db07:: with SMTP id e7mr1788059pgg.231.1553151225849; Wed, 20 Mar 2019 23:53:45 -0700 (PDT) Received: from archbookpro.localdomain (c-73-222-73-77.hsd1.ca.comcast.net. [73.222.73.77]) by smtp.gmail.com with ESMTPSA id 123sm1870943pff.182.2019.03.20.23.53.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Mar 2019 23:53:45 -0700 (PDT) Date: Wed, 20 Mar 2019 23:53:43 -0700 From: Denton Liu To: Git Mailing List Cc: Denton Liu , Eric Sunshine , Junio C Hamano , Phillip Wood , Ramsay Jones , SZEDER =?iso-8859-1?q?G=E1bor?= Subject: [PATCH v9 03/11] t7604: clean up style Message-ID: <61d1c7c907500662a8918e8175b2b96282406fef.1553150827.git.liu.denton@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.3 (2019-02-01) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Before, we had some Git commands which were upstream of the pipe. This meant that if it produced an error, it would've gone unnoticed. Refactor to place Git commands on their own. Also, while we're at it, remove spaces after redirection operators. Helped-by: Eric Sunshine Helped-by: SZEDER Gábor Signed-off-by: Denton Liu --- t/t7604-merge-custom-message.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/t/t7604-merge-custom-message.sh b/t/t7604-merge-custom-message.sh index 89619cf446..aba1279132 100755 --- a/t/t7604-merge-custom-message.sh +++ b/t/t7604-merge-custom-message.sh @@ -16,16 +16,16 @@ create_merge_msgs() { } test_expect_success 'setup' ' - echo c0 > c0.c && + echo c0 >c0.c && git add c0.c && git commit -m c0 && git tag c0 && - echo c1 > c1.c && + echo c1 >c1.c && git add c1.c && git commit -m c1 && git tag c1 && git reset --hard c0 && - echo c2 > c2.c && + echo c2 >c2.c && git add c2.c && git commit -m c2 && git tag c2 && @@ -36,14 +36,16 @@ test_expect_success 'setup' ' test_expect_success 'merge c2 with a custom message' ' git reset --hard c1 && git merge -m "$(cat exp.subject)" c2 && - git cat-file commit HEAD | sed -e "1,/^$/d" >actual && + git cat-file commit HEAD >raw && + sed -e "1,/^$/d" raw >actual && test_cmp exp.subject actual ' test_expect_success 'merge --log appends to custom message' ' git reset --hard c1 && git merge --log -m "$(cat exp.subject)" c2 && - git cat-file commit HEAD | sed -e "1,/^$/d" >actual && + git cat-file commit HEAD >raw && + sed -e "1,/^$/d" raw >actual && test_cmp exp.log actual ' From patchwork Thu Mar 21 06:53:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10862969 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9AE7314DE for ; Thu, 21 Mar 2019 06:53:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7ACD42A042 for ; Thu, 21 Mar 2019 06:53:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6F2082A044; Thu, 21 Mar 2019 06:53:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C06782A042 for ; Thu, 21 Mar 2019 06:53:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727878AbfCUGxt (ORCPT ); Thu, 21 Mar 2019 02:53:49 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:40217 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727823AbfCUGxt (ORCPT ); Thu, 21 Mar 2019 02:53:49 -0400 Received: by mail-pf1-f196.google.com with SMTP id c207so3689382pfc.7 for ; Wed, 20 Mar 2019 23:53:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=75TH6zfU3ftXoZ+0EvQdGm0O4Z9rYSkyS4KMdcMba0o=; b=S4qlhpjnU1nlOHrSba0ucYeXLCMEemeJ1Le6meBkQ/bxXbBmaUvefpT9mDAj/0MZAW S5zXNrtCuxyfNG15JS6X3vZMSFKTMWXfpAoaXFB5jwMMMJXINXjcJ9jLN/6ayHNniZIb h3JtUKvdAavpUd6qM0x0cVzzQSyfsPrTexAxyHErS9vlMzhwRqt8QYHh7eoOVbVWJ7up 1GT01gjL4lPV3MPTpI6eicKlO9DZEiiNjXQsGdRYvy94Aln/Hv7yxsvPAhrsvSzPJpgd Q4qgStph3vkJ6CjC4nRJlEvXGeNl0l0BlB3MM6nVsckpA2oQWsCHiN7Cjvv+cMlujjYG P8EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=75TH6zfU3ftXoZ+0EvQdGm0O4Z9rYSkyS4KMdcMba0o=; b=kEN1ifW2Bz5MUZU4p2sk3Kklqaag+RY8nPD9g9pcS9a9BVrk5dqSusILe6cs5x5WVa Gj+o1EvcI+eXbYHIIt7Mp2ASWwur++E81wEFHFqWT9VlKoQkkGSvHgz4ryvymKcBoRXo ZNO5voCdvaJ/UKR/KVp/5qbOnSZ7ewe5T7dbaQAjNh4QZ8GiPQnE0SaPTVQf/X2kX8QH fcUsJSsKW79g8kYO7pUzmiGgPA29w/m/8122yXTQZc/UArl52rQkFUpJRw+KuFllkOT4 6U64qskBpPP1tGtUNT1fobMLu31iXhTdXEBWuwx15Rtp9b1EnSLugEcvmEIAqWFNJ8zH x+hQ== X-Gm-Message-State: APjAAAWJOyZy4k9MNdCP9ZQ6nnsGnguiK3NZvEMn/9EuSWsMP4c5e1SH VCwz2gIcG3UhVKlR3IiSptePtbQPLZA= X-Google-Smtp-Source: APXvYqwU3etQHQo6CxS9/k1AfrjBcuBdzEcFIt0qMw7kUc4OKaccHHWlyM1nTBAuxo/AF7ffo0Pg+Q== X-Received: by 2002:a63:cc43:: with SMTP id q3mr1937628pgi.387.1553151228564; Wed, 20 Mar 2019 23:53:48 -0700 (PDT) Received: from archbookpro.localdomain (c-73-222-73-77.hsd1.ca.comcast.net. [73.222.73.77]) by smtp.gmail.com with ESMTPSA id a20sm6621764pfj.5.2019.03.20.23.53.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Mar 2019 23:53:47 -0700 (PDT) Date: Wed, 20 Mar 2019 23:53:46 -0700 From: Denton Liu To: Git Mailing List Cc: Denton Liu , Eric Sunshine , Junio C Hamano , Phillip Wood , Ramsay Jones , SZEDER =?iso-8859-1?q?G=E1bor?= Subject: [PATCH v9 04/11] t7502: clean up style Message-ID: <845a32295467706d9ce029ba1282851577fa51ac.1553150827.git.liu.denton@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.3 (2019-02-01) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Refactor out Git commands that were upstream of a pipe. Remove spaces after "> ". Indent here-docs appropriately. Convert echo chains to use the test_write_lines function. Refactor 'sign off' test to use test_cmp instead of comparing variables. Helped-by: Eric Sunshine Helped-by: SZEDER Gábor Signed-off-by: Denton Liu --- t/t7502-commit-porcelain.sh | 93 +++++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 40 deletions(-) diff --git a/t/t7502-commit-porcelain.sh b/t/t7502-commit-porcelain.sh index ca4a740da0..5733d9cd34 100755 --- a/t/t7502-commit-porcelain.sh +++ b/t/t7502-commit-porcelain.sh @@ -16,7 +16,8 @@ commit_msg_is () { # Arguments: [] [] check_summary_oneline() { test_tick && - git commit ${3+"$3"} -m "$2" | head -1 > act && + git commit ${3+"$3"} -m "$2" >raw && + head -n 1 raw >act && # branch name SUMMARY_PREFIX="$(git name-rev --name-only HEAD)" && @@ -68,7 +69,7 @@ test_expect_success 'output summary format for merges' ' git checkout recursive-a && test_must_fail git merge recursive-b && # resolve the conflict - echo commit-a > file1 && + echo commit-a >file1 && git add file1 && check_summary_oneline "" "Merge" ' @@ -142,9 +143,11 @@ test_expect_success 'sign off' ' >positive && git add positive && git commit -s -m "thank you" && - actual=$(git cat-file commit HEAD | sed -ne "s/Signed-off-by: //p") && - expected=$(git var GIT_COMMITTER_IDENT | sed -e "s/>.*/>/") && - test "z$actual" = "z$expected" + git cat-file commit HEAD >commit.msg && + sed -ne "s/Signed-off-by: //p" commit.msg >actual && + git var GIT_COMMITTER_IDENT >ident && + sed -e "s/>.*/>/" ident >expected && + test_cmp expected actual ' @@ -153,8 +156,8 @@ test_expect_success 'multiple -m' ' >negative && git add negative && git commit -m "one" -m "two" -m "three" && - actual=$(git cat-file commit HEAD | sed -e "1,/^\$/d") && - expected=$(echo one; echo; echo two; echo; echo three) && + actual=$(git cat-file commit HEAD >tmp && sed -e "1,/^\$/d" tmp && rm tmp) && + expected=$(test_write_lines "one" "" "two" "" "three") && test "z$actual" = "z$expected" ' @@ -163,7 +166,8 @@ test_expect_success 'verbose' ' echo minus >negative && git add negative && - git status -v | sed -ne "/^diff --git /p" >actual && + git status -v >raw && + sed -ne "/^diff --git /p" raw >actual && echo "diff --git a/negative b/negative" >expect && test_cmp expect actual @@ -189,7 +193,8 @@ test_expect_success 'cleanup commit messages (verbatim option,-t)' ' echo >>negative && git commit --cleanup=verbatim --no-status -t expect -a && - git cat-file -p HEAD |sed -e "1,/^\$/d" >actual && + git cat-file -p HEAD >raw && + sed -e "1,/^\$/d" raw >actual && test_cmp expect actual ' @@ -198,7 +203,8 @@ test_expect_success 'cleanup commit messages (verbatim option,-F)' ' echo >>negative && git commit --cleanup=verbatim -F expect -a && - git cat-file -p HEAD |sed -e "1,/^\$/d">actual && + git cat-file -p HEAD >raw && + sed -e "1,/^\$/d" raw >actual && test_cmp expect actual ' @@ -207,7 +213,8 @@ test_expect_success 'cleanup commit messages (verbatim option,-m)' ' echo >>negative && git commit --cleanup=verbatim -m "$mesg_with_comment_and_newlines" -a && - git cat-file -p HEAD |sed -e "1,/^\$/d">actual && + git cat-file -p HEAD >raw && + sed -e "1,/^\$/d" raw >actual && test_cmp expect actual ' @@ -215,10 +222,11 @@ test_expect_success 'cleanup commit messages (verbatim option,-m)' ' test_expect_success 'cleanup commit messages (whitespace option,-F)' ' echo >>negative && - { echo;echo "# text";echo; } >text && + test_write_lines "" "# text" "" >text && echo "# text" >expect && git commit --cleanup=whitespace -F text -a && - git cat-file -p HEAD |sed -e "1,/^\$/d">actual && + git cat-file -p HEAD >raw && + sed -e "1,/^\$/d" raw >actual && test_cmp expect actual ' @@ -226,48 +234,51 @@ test_expect_success 'cleanup commit messages (whitespace option,-F)' ' test_expect_success 'cleanup commit messages (scissors option,-F,-e)' ' echo >>negative && - cat >text <text <<-\EOF && -# to be kept + # to be kept - # ------------------------ >8 ------------------------ -# to be kept, too -# ------------------------ >8 ------------------------ -to be removed -# ------------------------ >8 ------------------------ -to be removed, too -EOF + # ------------------------ >8 ------------------------ + # to be kept, too + # ------------------------ >8 ------------------------ + to be removed + # ------------------------ >8 ------------------------ + to be removed, too + EOF - cat >expect <expect <<-\EOF && + # to be kept - # ------------------------ >8 ------------------------ -# to be kept, too -EOF + # ------------------------ >8 ------------------------ + # to be kept, too + EOF git commit --cleanup=scissors -e -F text -a && - git cat-file -p HEAD |sed -e "1,/^\$/d">actual && + git cat-file -p HEAD >raw && + sed -e "1,/^\$/d" raw >actual && test_cmp expect actual ' test_expect_success 'cleanup commit messages (scissors option,-F,-e, scissors on first line)' ' echo >>negative && - cat >text <8 ------------------------ -to be removed -EOF + cat >text <<-\EOF && + # ------------------------ >8 ------------------------ + to be removed + EOF git commit --cleanup=scissors -e -F text -a --allow-empty-message && - git cat-file -p HEAD |sed -e "1,/^\$/d">actual && + git cat-file -p HEAD >raw && + sed -e "1,/^\$/d" raw >actual && test_must_be_empty actual ' test_expect_success 'cleanup commit messages (strip option,-F)' ' echo >>negative && - { echo;echo "# text";echo sample;echo; } >text && + test_write_lines "" "# text" "sample" "" >text && echo sample >expect && git commit --cleanup=strip -F text -a && - git cat-file -p HEAD |sed -e "1,/^\$/d">actual && + git cat-file -p HEAD >raw && + sed -e "1,/^\$/d" raw >actual && test_cmp expect actual ' @@ -275,7 +286,7 @@ test_expect_success 'cleanup commit messages (strip option,-F)' ' test_expect_success 'cleanup commit messages (strip option,-F,-e)' ' echo >>negative && - { echo;echo sample;echo; } >text && + test_write_lines "" "sample" "" >text && git commit -e -F text -a && head -n 4 .git/COMMIT_EDITMSG >actual ' @@ -387,7 +398,7 @@ test_expect_success AUTOIDENT 'message shows committer when it is automatic' ' ' write_script .git/FAKE_EDITOR < "$(pwd)/.git/result" +echo editor started >"$(pwd)/.git/result" exit 0 EOF @@ -455,7 +466,7 @@ EOF test_expect_success EXECKEEPSPID 'a SIGTERM should break locks' ' echo >>negative && ! "$SHELL_PATH" -c '\'' - echo kill -TERM $$ >> .git/FAKE_EDITOR + echo kill -TERM $$ >>.git/FAKE_EDITOR GIT_EDITOR=.git/FAKE_EDITOR export GIT_EDITOR exec git commit -a'\'' && @@ -471,7 +482,8 @@ test_expect_success 'Hand committing of a redundant merge removes dups' ' test_must_fail git merge second master && git checkout master g && EDITOR=: git commit -a && - git cat-file commit HEAD | sed -n -e "s/^parent //p" -e "/^$/q" >actual && + git cat-file commit HEAD >raw && + sed -n -e "s/^parent //p" -e "/^$/q" raw >actual && test_cmp expect actual ' @@ -480,7 +492,8 @@ test_expect_success 'A single-liner subject with a token plus colon is not a foo git reset --hard && git commit -s -m "hello: kitty" --allow-empty && - git cat-file commit HEAD | sed -e "1,/^$/d" >actual && + git cat-file commit HEAD >raw && + sed -e "1,/^$/d" raw >actual && test_line_count = 3 actual ' From patchwork Thu Mar 21 06:53:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10862973 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 51C8D14DE for ; Thu, 21 Mar 2019 06:53:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 344D82A040 for ; Thu, 21 Mar 2019 06:53:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 285A22A042; Thu, 21 Mar 2019 06:53:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A2B5F2A040 for ; Thu, 21 Mar 2019 06:53:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727883AbfCUGxw (ORCPT ); Thu, 21 Mar 2019 02:53:52 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:37395 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727811AbfCUGxw (ORCPT ); Thu, 21 Mar 2019 02:53:52 -0400 Received: by mail-pf1-f193.google.com with SMTP id 8so3698791pfr.4 for ; Wed, 20 Mar 2019 23:53:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=/pZ5ie1Vyj6gsKDYqQSrhAjKAYhZ8TNUnN1cZxLKcwI=; b=SD6iONwUUXCUA4U76ozYOkhC/zBl9cyuxUw7iUuphUGMyQFdvuXqLbJ2IicI6CLiGz WxO1lGu3BjpW02kBP54JFppF1digVxY88I1QFRtHx+QkfKVBccmg8Pb2c34o8oeruG/c fRI/Cn+kSTo+a0f6WTRhJbd31pQPJ3xNTIJSJ5YIlMmRGTnKtvW/ylVIi/orgVlgwmkj PurVt4v87MO7uYYYSqrcAsdZ3tmVtWWmOP7yt3VWlTmBFqVKIKQDdszK999w2etVtzmT SiBVkOq+QjPISmRYnDiBL4Alo2hRjw6Z+b7uX6ymZYT3t2VrETUyGKONeHL5aKkSU6js 4F4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=/pZ5ie1Vyj6gsKDYqQSrhAjKAYhZ8TNUnN1cZxLKcwI=; b=ZfX6TidOhbLWbCoAeTJ1W6vp3+p7OUmpKWOlNyDyCdDjj2z/QsdTqTxaP5kLiuE/12 V0wr1/7fuwnfHq7462iXBjtXlXr/4pNGNDna1HuDBSdyf3rSV5iCOkiiYdfiKELu3pql 3E2GdvCXg4sbeUMyHLWyMoee+2Cqd80gfxPCzdCr0zgRmQG0HPp2Du/W3EKMkRDEHD6l 3dDvwONtiasm7QfEVWHBpFB83IMuaNFj6rYW/5++fGQdRaPrTsrYdTrcxKbhWhdwnumt m+i5n7LLfv+33CdUiBmbLCl3fn2k3C98RSju9Uv52meIh22VxDKgLXowTCTB3MQdUYtE 8aDg== X-Gm-Message-State: APjAAAWGcNzM0y5Z05gSh/Wclfj0iJdqbo32PlQ2Cp9Q/O0FQdLDYoe2 htXXGUw35Ot/7S1L51mC8Img0zxLOe4= X-Google-Smtp-Source: APXvYqwtlrmfOtDqimLLjEj1RW4YEmFRvo5KTLQbbIaTlCsKCa81x7xQBEFRSIFWvp7DIWE9USbytw== X-Received: by 2002:a17:902:848b:: with SMTP id c11mr1879990plo.279.1553151231289; Wed, 20 Mar 2019 23:53:51 -0700 (PDT) Received: from archbookpro.localdomain (c-73-222-73-77.hsd1.ca.comcast.net. [73.222.73.77]) by smtp.gmail.com with ESMTPSA id j20sm5027855pfa.158.2019.03.20.23.53.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Mar 2019 23:53:50 -0700 (PDT) Date: Wed, 20 Mar 2019 23:53:48 -0700 From: Denton Liu To: Git Mailing List Cc: Denton Liu , Eric Sunshine , Junio C Hamano , Phillip Wood , Ramsay Jones , SZEDER =?iso-8859-1?q?G=E1bor?= Subject: [PATCH v9 05/11] commit: extract cleanup_mode functions to sequencer Message-ID: <6f20c20939fb946af18f5e0af794305242ca0ef2.1553150827.git.liu.denton@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.3 (2019-02-01) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Denton Liu --- builtin/commit.c | 25 ++----------------------- sequencer.c | 29 +++++++++++++++++++++++++++++ sequencer.h | 6 ++++++ 3 files changed, 37 insertions(+), 23 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index f17537474a..0df15e4851 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1172,24 +1172,7 @@ static int parse_and_validate_options(int argc, const char *argv[], die(_("Only one of --include/--only/--all/--interactive/--patch can be used.")); if (argc == 0 && (also || (only && !amend && !allow_empty))) die(_("No paths with --include/--only does not make sense.")); - if (!cleanup_arg || !strcmp(cleanup_arg, "default")) - cleanup_mode = use_editor ? COMMIT_MSG_CLEANUP_ALL : - COMMIT_MSG_CLEANUP_SPACE; - else if (!strcmp(cleanup_arg, "verbatim")) - cleanup_mode = COMMIT_MSG_CLEANUP_NONE; - else if (!strcmp(cleanup_arg, "whitespace")) - cleanup_mode = COMMIT_MSG_CLEANUP_SPACE; - else if (!strcmp(cleanup_arg, "strip")) - cleanup_mode = COMMIT_MSG_CLEANUP_ALL; - else if (!strcmp(cleanup_arg, "scissors")) - cleanup_mode = use_editor ? COMMIT_MSG_CLEANUP_SCISSORS : - COMMIT_MSG_CLEANUP_SPACE; - /* - * Please update _git_commit() in git-completion.bash when you - * add new options. - */ - else - die(_("Invalid cleanup mode %s"), cleanup_arg); + cleanup_mode = get_cleanup_mode(cleanup_arg, use_editor); handle_untracked_files_arg(s); @@ -1626,11 +1609,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix) die(_("could not read commit message: %s"), strerror(saved_errno)); } - if (verbose || /* Truncate the message just before the diff, if any. */ - cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS) - strbuf_setlen(&sb, wt_status_locate_end(sb.buf, sb.len)); - if (cleanup_mode != COMMIT_MSG_CLEANUP_NONE) - strbuf_stripspace(&sb, cleanup_mode == COMMIT_MSG_CLEANUP_ALL); + cleanup_message(&sb, cleanup_mode, verbose); if (message_is_empty(&sb, cleanup_mode) && !allow_empty_message) { rollback_index_files(); diff --git a/sequencer.c b/sequencer.c index 95dda23eee..224c823b43 100644 --- a/sequencer.c +++ b/sequencer.c @@ -511,6 +511,25 @@ static int fast_forward_to(struct repository *r, return 0; } +enum commit_msg_cleanup_mode get_cleanup_mode(const char *cleanup_arg, + int use_editor) +{ + if (!cleanup_arg || !strcmp(cleanup_arg, "default")) + return use_editor ? COMMIT_MSG_CLEANUP_ALL : + COMMIT_MSG_CLEANUP_SPACE; + else if (!strcmp(cleanup_arg, "verbatim")) + return COMMIT_MSG_CLEANUP_NONE; + else if (!strcmp(cleanup_arg, "whitespace")) + return COMMIT_MSG_CLEANUP_SPACE; + else if (!strcmp(cleanup_arg, "strip")) + return COMMIT_MSG_CLEANUP_ALL; + else if (!strcmp(cleanup_arg, "scissors")) + return use_editor ? COMMIT_MSG_CLEANUP_SCISSORS : + COMMIT_MSG_CLEANUP_SPACE; + else + die(_("Invalid cleanup mode %s"), cleanup_arg); +} + void append_conflicts_hint(struct index_state *istate, struct strbuf *msgbuf) { @@ -1013,6 +1032,16 @@ static int rest_is_empty(const struct strbuf *sb, int start) return 1; } +void cleanup_message(struct strbuf *msgbuf, + enum commit_msg_cleanup_mode cleanup_mode, int verbose) +{ + if (verbose || /* Truncate the message just before the diff, if any. */ + cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS) + strbuf_setlen(msgbuf, wt_status_locate_end(msgbuf->buf, msgbuf->len)); + if (cleanup_mode != COMMIT_MSG_CLEANUP_NONE) + strbuf_stripspace(msgbuf, cleanup_mode == COMMIT_MSG_CLEANUP_ALL); +} + /* * Find out if the message in the strbuf contains only whitespace and * Signed-off-by lines. diff --git a/sequencer.h b/sequencer.h index 4d505b3590..eb9bd97ef3 100644 --- a/sequencer.h +++ b/sequencer.h @@ -116,6 +116,12 @@ int rearrange_squash(struct repository *r); void append_signoff(struct strbuf *msgbuf, size_t ignore_footer, unsigned flag); void append_conflicts_hint(struct index_state *istate, struct strbuf *msgbuf); +enum commit_msg_cleanup_mode get_cleanup_mode(const char *cleanup_arg, + int use_editor); + +void cleanup_message(struct strbuf *msgbuf, + enum commit_msg_cleanup_mode cleanup_mode, int verbose); + int message_is_empty(const struct strbuf *sb, enum commit_msg_cleanup_mode cleanup_mode); int template_untouched(const struct strbuf *sb, const char *template_file, From patchwork Thu Mar 21 06:53:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10862975 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 53B4414DE for ; Thu, 21 Mar 2019 06:53:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3675A2A040 for ; Thu, 21 Mar 2019 06:53:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2ACE22A042; Thu, 21 Mar 2019 06:53:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6D55E2A040 for ; Thu, 21 Mar 2019 06:53:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727890AbfCUGxz (ORCPT ); Thu, 21 Mar 2019 02:53:55 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:38384 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727811AbfCUGxz (ORCPT ); Thu, 21 Mar 2019 02:53:55 -0400 Received: by mail-pg1-f196.google.com with SMTP id v1so3576077pgi.5 for ; Wed, 20 Mar 2019 23:53:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=K83xnFPAcB1VIULC86KP35ikutyNj0u9e1zEXL9YwpU=; b=dI6BMzhZPqUwRwa8aU3Xy7GlO6hZFX7rLI8qa+DS0cEo5RFKUidDofZwlxWz16ur6W 7dTbcofYdkjlgJUl1NGiHcYQqn8JMb4ozhNtr3k+w9/wR6meqRCBcEujSqe3+G0P+oHK 2CzlGFr5PvucHyM7TDUUtjIzmYDMmnapJPPbJrWMDXrn7d6Itpvx1Z6bP4rnGqI1xy/v u+J63n1mK4yYOTA9kSqvRRjfNxRONvO3bFC5vToBzr1tbUxJR5QYlVWB4XEa232u9xFq ETdE4BxkZcLJZCpLEImoIYrt+RGHrwjRITcAz2aeF3A0+fY+R+D/LfpIlH63owTMzu0L tjKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=K83xnFPAcB1VIULC86KP35ikutyNj0u9e1zEXL9YwpU=; b=n00PdRqLGYBdT31DhKoGek1p4rjFBKk+klinsdmGzklMums/vDfx6Vkdr/t2E4T90U ZqoxYjb5wofV61PG5Hu/MMtYhTWFyz6tf+c+HWG4jTIAKxaeLtbrsVDoC9OtHxzM+mbf 5kXZNKrh0NsvWVS3qg7BErHfKNzBNPc9T2FD9shsEZQGl+xkU22UgQUWcb2GOOyJJuqj yx/q1ZrloBDYjOAzHwF1E27fsRPYiZsCQ7GNmBqiRGX8zWp90kSTi5fVbKrnGA2Zw26t J67RTaFxcdAdJpT5/E5aGPAWkU+o1N58AOANNB2KBTYD1UNUvWF4jxhH+NvO57kdMxmj KqUw== X-Gm-Message-State: APjAAAXBBVYjM4/ylJLhY5TCUz3NstQQYF87fLYX86452XQkKH+pW2py rcNhL3l2lDUSsLeFMeXd69IedGP0ZIc= X-Google-Smtp-Source: APXvYqwiw8TE7QqFRxXTf06wjx/nX6hoKWotmThtTTZuwH0JxLDCt5zmcX96DRadM9ByfGhJLTmGnA== X-Received: by 2002:a17:902:7786:: with SMTP id o6mr1977749pll.206.1553151234119; Wed, 20 Mar 2019 23:53:54 -0700 (PDT) Received: from archbookpro.localdomain (c-73-222-73-77.hsd1.ca.comcast.net. [73.222.73.77]) by smtp.gmail.com with ESMTPSA id k17sm4808647pfk.166.2019.03.20.23.53.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Mar 2019 23:53:53 -0700 (PDT) Date: Wed, 20 Mar 2019 23:53:51 -0700 From: Denton Liu To: Git Mailing List Cc: Denton Liu , Eric Sunshine , Junio C Hamano , Phillip Wood , Ramsay Jones , SZEDER =?iso-8859-1?q?G=E1bor?= Subject: [PATCH v9 06/11] parse-options.h: extract common --cleanup option Message-ID: <2c966ae31840cff8f58e64d203fdddbf9ad57f87.1553150827.git.liu.denton@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.3 (2019-02-01) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The --cleanup option is commonly used. Extract it so that its definition is not repeated. Helped-by: Phillip Wood Signed-off-by: Denton Liu --- builtin/commit.c | 2 +- builtin/tag.c | 3 +-- parse-options.h | 1 + 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index 0df15e4851..8277da8474 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1473,7 +1473,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix) OPT_BOOL('s', "signoff", &signoff, N_("add Signed-off-by:")), OPT_FILENAME('t', "template", &template_file, N_("use specified template file")), OPT_BOOL('e', "edit", &edit_flag, N_("force edit of commit")), - OPT_STRING(0, "cleanup", &cleanup_arg, N_("default"), N_("how to strip spaces and #comments from message")), + OPT_CLEANUP(&cleanup_arg), OPT_BOOL(0, "status", &include_status, N_("include status in commit message template")), { OPTION_STRING, 'S', "gpg-sign", &sign_commit, N_("key-id"), N_("GPG sign commit"), PARSE_OPT_OPTARG, NULL, (intptr_t) "" }, diff --git a/builtin/tag.c b/builtin/tag.c index 02f6bd1279..a3870fbdba 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -397,8 +397,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix) OPT_FILENAME('F', "file", &msgfile, N_("read message from file")), OPT_BOOL('e', "edit", &edit_flag, N_("force edit of tag message")), OPT_BOOL('s', "sign", &opt.sign, N_("annotated and GPG-signed tag")), - OPT_STRING(0, "cleanup", &cleanup_arg, N_("mode"), - N_("how to strip spaces and #comments from message")), + OPT_CLEANUP(&cleanup_arg), OPT_STRING('u', "local-user", &keyid, N_("key-id"), N_("use another key to sign the tag")), OPT__FORCE(&force, N_("replace the tag if exists"), 0), diff --git a/parse-options.h b/parse-options.h index 7d83e2971d..85faaee390 100644 --- a/parse-options.h +++ b/parse-options.h @@ -303,5 +303,6 @@ int parse_opt_passthru_argv(const struct option *, const char *, int); #define OPT_NO_CONTAINS(v, h) _OPT_CONTAINS_OR_WITH("no-contains", v, h, PARSE_OPT_NONEG) #define OPT_WITH(v, h) _OPT_CONTAINS_OR_WITH("with", v, h, PARSE_OPT_HIDDEN | PARSE_OPT_NONEG) #define OPT_WITHOUT(v, h) _OPT_CONTAINS_OR_WITH("without", v, h, PARSE_OPT_HIDDEN | PARSE_OPT_NONEG) +#define OPT_CLEANUP(v) OPT_STRING(0, "cleanup", v, N_("mode"), N_("how to strip spaces and #comments from message")) #endif From patchwork Thu Mar 21 06:53:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10862977 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 43E381515 for ; Thu, 21 Mar 2019 06:54:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2846D2A040 for ; Thu, 21 Mar 2019 06:54:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1C61F2A042; Thu, 21 Mar 2019 06:54:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 88DBB2A040 for ; Thu, 21 Mar 2019 06:53:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727893AbfCUGx6 (ORCPT ); Thu, 21 Mar 2019 02:53:58 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:34704 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727891AbfCUGx6 (ORCPT ); Thu, 21 Mar 2019 02:53:58 -0400 Received: by mail-pg1-f195.google.com with SMTP id v12so3596492pgq.1 for ; Wed, 20 Mar 2019 23:53:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=R0f6isHrpFXom1zlVM9c1JtgkdivNl3Iqxc6mzDKoHc=; b=hYGccKd0Ltgpd0Cyv1eUskCzthskDOnWyGdROFrcBt5prByxTh9z2sc8gNV6Dr2tO4 V12LVEy9B0KSnGG6PevbjievrtclB+eHcQU5xns8LL0l5x2AjAHwye9wtC/2vhcP1fzu +PGV5BFlsg/GNjt2LZCTpXEnwNP4XIVLs3yTRkhLlyrcKby52/yw0KN6mml17UGRkCxC BKB5xsG5LzMWRfyT2FcsJn+3Xia4EBBszzlP8IEjRxNEbLcdKzMc2Hmq58KpxADk4AhS 3T8e2Li6+uU0hjHxW9DxXgdTa8LPRJLBPTZQ5XfxxHcX3h6RerEtlzUAQjSnm+59KP1m 8OVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=R0f6isHrpFXom1zlVM9c1JtgkdivNl3Iqxc6mzDKoHc=; b=cFMsdnI6NDZxk42uZBXQANpSZipUgmEcpL+oVhh3fyMqRhumtCAXDpEUNKAWCCJLmG AlwozRFwPfTP9qqX6rdenzG1c/jd9mSbomXEStAB+3AMJAI/rbIhwvPL+8NCQX6cnEtk cayaz176xm2p/2Y4JLRlZMoPgS0u4BekM/O1+7Bur9rKQB+ypECJsd15UadFh5mViVcX YmuxcwCniLw/MyWGg2pvB/spYo/ZXcD2H4dxmeCfnWEQxyXA6tnSIpFvu4HjGWthcAt7 wf673MfT0VTlAK4N3kSOK5GcGiteg2gFhqp7tcnY0DyJ9stuol1xMWW6+oVKn0BGdlRe 3vfw== X-Gm-Message-State: APjAAAVocxXevO9EpnHMgl20zfXv6/tj+fTS+Nfp3ybEbF/7l3ikx2Dw sekmx5WAdTHFQKEbf6ycGLvACk84c1I= X-Google-Smtp-Source: APXvYqxsbIoguTvTPwYbs7F+jq5p5Z9toLc2AHhYBe2sP5R9wkiCpySa4tBXuMAP70+N4CzEVgZD4w== X-Received: by 2002:a17:902:6b8c:: with SMTP id p12mr2020393plk.282.1553151236833; Wed, 20 Mar 2019 23:53:56 -0700 (PDT) Received: from archbookpro.localdomain (c-73-222-73-77.hsd1.ca.comcast.net. [73.222.73.77]) by smtp.gmail.com with ESMTPSA id h11sm4351069pgq.57.2019.03.20.23.53.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Mar 2019 23:53:56 -0700 (PDT) Date: Wed, 20 Mar 2019 23:53:54 -0700 From: Denton Liu To: Git Mailing List Cc: Denton Liu , Eric Sunshine , Junio C Hamano , Phillip Wood , Ramsay Jones , SZEDER =?iso-8859-1?q?G=E1bor?= Subject: [PATCH v9 07/11] sequencer.c: remove duplicate code Message-ID: <492ba73797ac66cc48da2b44cdae2152b41aa481.1553150827.git.liu.denton@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.3 (2019-02-01) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Since we implemented get_cleanup_mode, we had some duplicate code in git_sequencer_config which essentially performed the same operations. Refactor git_sequencer_config to take advantage of the logic already in get_cleanup_mode. Note that we had to introduce a separate argument to get_cleanup_mode indicating whether to die or not on an invalid value. This is because if we are parsing a config, we do not want to die but instead, we only want to warn the user, whereas if we are parsing a command-line option, we would like to actually die. Finally, this is almost a no-op refactor but not quite. Previously, in the case that an invalid value is presented, default_msg_cleanup would not be set. We change the behaviour so that default_msg_cleanup will now take on the value as if "default" were provided as the cleanup_arg. Also, we lowercase some user-facing strings. Helped-by: Phillip Wood Signed-off-by: Denton Liu --- builtin/commit.c | 2 +- sequencer.c | 22 ++++++++-------------- sequencer.h | 2 +- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index 8277da8474..ba1e6027ba 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1172,7 +1172,7 @@ static int parse_and_validate_options(int argc, const char *argv[], die(_("Only one of --include/--only/--all/--interactive/--patch can be used.")); if (argc == 0 && (also || (only && !amend && !allow_empty))) die(_("No paths with --include/--only does not make sense.")); - cleanup_mode = get_cleanup_mode(cleanup_arg, use_editor); + cleanup_mode = get_cleanup_mode(cleanup_arg, use_editor, 1); handle_untracked_files_arg(s); diff --git a/sequencer.c b/sequencer.c index 224c823b43..2cbfb848dd 100644 --- a/sequencer.c +++ b/sequencer.c @@ -172,17 +172,7 @@ static int git_sequencer_config(const char *k, const char *v, void *cb) if (status) return status; - if (!strcmp(s, "verbatim")) - opts->default_msg_cleanup = COMMIT_MSG_CLEANUP_NONE; - else if (!strcmp(s, "whitespace")) - opts->default_msg_cleanup = COMMIT_MSG_CLEANUP_SPACE; - else if (!strcmp(s, "strip")) - opts->default_msg_cleanup = COMMIT_MSG_CLEANUP_ALL; - else if (!strcmp(s, "scissors")) - opts->default_msg_cleanup = COMMIT_MSG_CLEANUP_SPACE; - else - warning(_("invalid commit message cleanup mode '%s'"), - s); + opts->default_msg_cleanup = get_cleanup_mode(s, 0, 0); free((char *)s); return status; @@ -512,7 +502,7 @@ static int fast_forward_to(struct repository *r, } enum commit_msg_cleanup_mode get_cleanup_mode(const char *cleanup_arg, - int use_editor) + int use_editor, int die_on_error) { if (!cleanup_arg || !strcmp(cleanup_arg, "default")) return use_editor ? COMMIT_MSG_CLEANUP_ALL : @@ -526,8 +516,12 @@ enum commit_msg_cleanup_mode get_cleanup_mode(const char *cleanup_arg, else if (!strcmp(cleanup_arg, "scissors")) return use_editor ? COMMIT_MSG_CLEANUP_SCISSORS : COMMIT_MSG_CLEANUP_SPACE; - else - die(_("Invalid cleanup mode %s"), cleanup_arg); + else if (!die_on_error) { + warning(_("invalid cleanup mode %s, falling back to default"), cleanup_arg); + return use_editor ? COMMIT_MSG_CLEANUP_ALL : + COMMIT_MSG_CLEANUP_SPACE; + } else + die(_("invalid cleanup mode %s"), cleanup_arg); } void append_conflicts_hint(struct index_state *istate, diff --git a/sequencer.h b/sequencer.h index eb9bd97ef3..e7908f558e 100644 --- a/sequencer.h +++ b/sequencer.h @@ -117,7 +117,7 @@ void append_signoff(struct strbuf *msgbuf, size_t ignore_footer, unsigned flag); void append_conflicts_hint(struct index_state *istate, struct strbuf *msgbuf); enum commit_msg_cleanup_mode get_cleanup_mode(const char *cleanup_arg, - int use_editor); + int use_editor, int die_on_error); void cleanup_message(struct strbuf *msgbuf, enum commit_msg_cleanup_mode cleanup_mode, int verbose); From patchwork Thu Mar 21 06:53:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10862979 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 88B9A1515 for ; Thu, 21 Mar 2019 06:54:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 674D32A040 for ; Thu, 21 Mar 2019 06:54:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5A7CA2A042; Thu, 21 Mar 2019 06:54:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E3822A040 for ; Thu, 21 Mar 2019 06:54:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727898AbfCUGyB (ORCPT ); Thu, 21 Mar 2019 02:54:01 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:45654 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727891AbfCUGyB (ORCPT ); Thu, 21 Mar 2019 02:54:01 -0400 Received: by mail-pg1-f193.google.com with SMTP id y3so3558920pgk.12 for ; Wed, 20 Mar 2019 23:54:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=3k3TNZ/zc4SxHCpHGjS40R6EOMvUUMUV8YJpphudCK0=; b=ukbz0GC6i3OqUp9ykQli16Kkmt+gX1KBNEWRNZO84tEsCjzqrZf0+5Ls6Ivc+uz+B7 66fy92qui2sHsOkhTUd2aEfRo5lLygnAae211VwTJct3LFRXMgHm8mwAV5uj2NcfVkx9 mFxT5sc7OiYaZHqlDyQ4Khl/ILn//FJ7znNcY2NDzjdD988ERjpY1MrYkSr9WAk0iO75 ux4O4f4XSIQT2wOMOyAqxjme7bK/6MSuypN0dZN2QqcjSUo1+9Y4OpUIJRbfxd7D4PyK YPpnF8jq49jbgR3qGhWQuxX3bclBFw6yHp7lDaoOpKosai2NErY/oy7kamIr/jYJFMLs 7i/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=3k3TNZ/zc4SxHCpHGjS40R6EOMvUUMUV8YJpphudCK0=; b=T6MnauM0ZjXcHKtyVkSLMVGk25OJ8QJm0iGQj/DMc7pVUmY+fx5Ai5tNOMIffwc2t9 kn/IRtHBuQNWQgdB31hkVhOgWRbgSwu028OMjZnhSyLqYx2fwTvJ7Ty4lb0t4vUOlwlN cozvk+D+DKjt3FE+a/2OLCXSKYNdwmjw96Dh7acUHH49Qh0eBMxe3pfzkJKlrksGqE5U gguOUEDnzT5EA+QUbONjKsqa9N5FKp0r3Elz8vTMZxdMM5rjaa9UsK0yD5NtP/MFktte 3AALkWX/OrHFYMC67Ffz4LJB4FtHadBHZzfViWtFMrsXxPWZVAdgGRGJixWG6N/4jy/c 7VRQ== X-Gm-Message-State: APjAAAW01olD+1h7+NZeZmAM9rrboyGQVbkLcuJX7UGSccS7A+2Ir3dj QNJcu/mVR9phuVqKkXdykFvEW8IOENM= X-Google-Smtp-Source: APXvYqyQTqdelatZ84sPk/4R5ml+kJPBRnXo3RnCgQ2FucI3SXtRP8ecQXBwSSsM+mQXXE3a4fGyyA== X-Received: by 2002:a65:6108:: with SMTP id z8mr1979275pgu.188.1553151239633; Wed, 20 Mar 2019 23:53:59 -0700 (PDT) Received: from archbookpro.localdomain (c-73-222-73-77.hsd1.ca.comcast.net. [73.222.73.77]) by smtp.gmail.com with ESMTPSA id c2sm8218288pfm.187.2019.03.20.23.53.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Mar 2019 23:53:58 -0700 (PDT) Date: Wed, 20 Mar 2019 23:53:57 -0700 From: Denton Liu To: Git Mailing List Cc: Denton Liu , Eric Sunshine , Junio C Hamano , Phillip Wood , Ramsay Jones , SZEDER =?iso-8859-1?q?G=E1bor?= Subject: [PATCH v9 08/11] merge: cleanup messages like commit Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.3 (2019-02-01) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This change allows git-merge messages to be cleaned up with the commit.cleanup configuration or --cleanup option, just like how git-commit does it. We also give git-pull the passthrough option of --cleanup so that it can also take advantage of this change. Finally, add testing to ensure that messages are properly cleaned up. Note that some newlines that were added to the commit message were removed so that if a file were read via -F, it would be copied faithfully. Helped-by: Phillip Wood Helped-by: Eric Sunshine Signed-off-by: Denton Liu --- Documentation/merge-options.txt | 4 +++ builtin/merge.c | 35 ++++++++++++++---- builtin/pull.c | 23 ++++++++++++ t/t5521-pull-options.sh | 8 +++++ t/t7604-merge-custom-message.sh | 63 +++++++++++++++++++++++++++++++++ wt-status.c | 12 +++++-- wt-status.h | 1 + 7 files changed, 136 insertions(+), 10 deletions(-) diff --git a/Documentation/merge-options.txt b/Documentation/merge-options.txt index 92a7d936c1..bcf0b3e49c 100644 --- a/Documentation/merge-options.txt +++ b/Documentation/merge-options.txt @@ -32,6 +32,10 @@ they run `git merge`. To make it easier to adjust such scripts to the updated behaviour, the environment variable `GIT_MERGE_AUTOEDIT` can be set to `no` at the beginning of them. +--cleanup=:: + This option determines how the merge message will be cleaned up + before commiting. See linkgit:git-commit[1] for more details. + --ff:: When the merge resolves as a fast-forward, only update the branch pointer, without creating a merge commit. This is the default diff --git a/builtin/merge.c b/builtin/merge.c index 5ce8946d39..f5783a901d 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -38,6 +38,7 @@ #include "tag.h" #include "alias.h" #include "commit-reach.h" +#include "wt-status.h" #define DEFAULT_TWOHEAD (1<<0) #define DEFAULT_OCTOPUS (1<<1) @@ -98,6 +99,9 @@ enum ff_type { static enum ff_type fast_forward = FF_ALLOW; +static const char *cleanup_arg; +static enum commit_msg_cleanup_mode cleanup_mode; + static int option_parse_message(const struct option *opt, const char *arg, int unset) { @@ -249,6 +253,7 @@ static struct option builtin_merge_options[] = { N_("perform a commit if the merge succeeds (default)")), OPT_BOOL('e', "edit", &option_edit, N_("edit message before committing")), + OPT_CLEANUP(&cleanup_arg), OPT_SET_INT(0, "ff", &fast_forward, N_("allow fast-forward (default)"), FF_ALLOW), OPT_SET_INT_F(0, "ff-only", &fast_forward, N_("abort if fast-forward is not possible"), @@ -612,6 +617,8 @@ static int git_merge_config(const char *k, const char *v, void *cb) return git_config_string(&pull_twohead, k, v); else if (!strcmp(k, "pull.octopus")) return git_config_string(&pull_octopus, k, v); + else if (!strcmp(k, "commit.cleanup")) + return git_config_string(&cleanup_arg, k, v); else if (!strcmp(k, "merge.renormalize")) option_renormalize = git_config_bool(k, v); else if (!strcmp(k, "merge.ff")) { @@ -800,8 +807,13 @@ static void abort_commit(struct commit_list *remoteheads, const char *err_msg) static const char merge_editor_comment[] = N_("Please enter a commit message to explain why this merge is necessary,\n" "especially if it merges an updated upstream into a topic branch.\n" - "\n" - "Lines starting with '%c' will be ignored, and an empty message aborts\n" + "\n"); + +static const char scissors_editor_comment[] = +N_("An empty message aborts the commit.\n"); + +static const char no_scissors_editor_comment[] = +N_("Lines starting with '%c' will be ignored, and an empty message aborts\n" "the commit.\n"); static void write_merge_heads(struct commit_list *); @@ -809,11 +821,19 @@ static void prepare_to_commit(struct commit_list *remoteheads) { struct strbuf msg = STRBUF_INIT; strbuf_addbuf(&msg, &merge_msg); - strbuf_addch(&msg, '\n'); if (squash) BUG("the control must not reach here under --squash"); - if (0 < option_edit) - strbuf_commented_addf(&msg, _(merge_editor_comment), comment_line_char); + if (0 < option_edit) { + strbuf_addch(&msg, '\n'); + if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS) + wt_status_append_cut_line(&msg); + + strbuf_commented_addf(&msg, "\n"); + strbuf_commented_addf(&msg, _(merge_editor_comment)); + strbuf_commented_addf(&msg, _(cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS ? + scissors_editor_comment : + no_scissors_editor_comment), comment_line_char); + } if (signoff) append_signoff(&msg, ignore_non_trailer(msg.buf, msg.len), 0); write_merge_heads(remoteheads); @@ -832,7 +852,7 @@ static void prepare_to_commit(struct commit_list *remoteheads) abort_commit(remoteheads, NULL); read_merge_msg(&msg); - strbuf_stripspace(&msg, 0 < option_edit); + cleanup_message(&msg, cleanup_mode, 0); if (!msg.len) abort_commit(remoteheads, _("Empty commit message.")); strbuf_release(&merge_msg); @@ -880,7 +900,6 @@ static int finish_automerge(struct commit *head, parents = remoteheads; if (!head_subsumed || fast_forward == FF_NO) commit_list_insert(head, &parents); - strbuf_addch(&merge_msg, '\n'); prepare_to_commit(remoteheads); if (commit_tree(merge_msg.buf, merge_msg.len, result_tree, parents, &result_commit, NULL, sign_commit)) @@ -1389,6 +1408,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix) if (option_edit < 0) option_edit = default_edit_option(); + cleanup_mode = get_cleanup_mode(cleanup_arg, 0 < option_edit, 1); + if (!use_strategies) { if (!remoteheads) ; /* already up-to-date */ diff --git a/builtin/pull.c b/builtin/pull.c index 33db889955..55ebb5808e 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -24,6 +24,7 @@ #include "lockfile.h" #include "wt-status.h" #include "commit-reach.h" +#include "sequencer.h" enum rebase_type { REBASE_INVALID = -1, @@ -101,6 +102,7 @@ static char *opt_signoff; static char *opt_squash; static char *opt_commit; static char *opt_edit; +static char *opt_cleanup; static char *opt_ff; static char *opt_verify_signatures; static int opt_autostash = -1; @@ -168,6 +170,9 @@ static struct option pull_options[] = { OPT_PASSTHRU(0, "edit", &opt_edit, NULL, N_("edit message before committing"), PARSE_OPT_NOARG), + OPT_PASSTHRU(0, "cleanup", &opt_cleanup, NULL, + N_("how to strip spaces and #comments from message"), + 0), OPT_PASSTHRU(0, "ff", &opt_ff, NULL, N_("allow fast-forward"), PARSE_OPT_NOARG), @@ -644,6 +649,8 @@ static int run_merge(void) argv_array_push(&args, opt_commit); if (opt_edit) argv_array_push(&args, opt_edit); + if (opt_cleanup) + argv_array_push(&args, opt_cleanup); if (opt_ff) argv_array_push(&args, opt_ff); if (opt_verify_signatures) @@ -875,6 +882,22 @@ int cmd_pull(int argc, const char **argv, const char *prefix) argc = parse_options(argc, argv, prefix, pull_options, pull_usage, 0); + if (opt_cleanup) { + const char *prefix = "--cleanup="; + const char *cleanup_arg; + + if (strncmp(opt_cleanup, prefix, strlen(prefix))) + BUG("expecting prefix %s, argument is %s", prefix, opt_cleanup); + + cleanup_arg = &opt_cleanup[strlen(prefix)]; + + /* + * this only checks the validity of cleanup_arg; we don't need + * a valid value for use_editor + */ + get_cleanup_mode(cleanup_arg, 0, 1); + } + parse_repo_refspecs(argc, argv, &repo, &refspecs); if (!opt_ff) diff --git a/t/t5521-pull-options.sh b/t/t5521-pull-options.sh index c19d8dbc9d..ccde8ba491 100755 --- a/t/t5521-pull-options.sh +++ b/t/t5521-pull-options.sh @@ -77,6 +77,14 @@ test_expect_success 'git pull -q -v' ' test_must_be_empty out && test -s err) ' +test_expect_success 'git pull --cleanup errors early on invalid argument' ' + mkdir clonedcleanup && + (cd clonedcleanup && git init && + test_must_fail git pull --cleanup invalid "../parent" >out 2>err && + test_must_be_empty out && + test -s err) +' + test_expect_success 'git pull --force' ' mkdir clonedoldstyle && diff --git a/t/t7604-merge-custom-message.sh b/t/t7604-merge-custom-message.sh index aba1279132..cd4f9607dc 100755 --- a/t/t7604-merge-custom-message.sh +++ b/t/t7604-merge-custom-message.sh @@ -49,4 +49,67 @@ test_expect_success 'merge --log appends to custom message' ' test_cmp exp.log actual ' +mesg_with_comment_and_newlines=' +# text + +' + +test_expect_success 'prepare file with comment line and trailing newlines' ' + printf "%s" "$mesg_with_comment_and_newlines" >expect +' + +test_expect_success 'cleanup commit messages (verbatim option)' ' + git reset --hard c1 && + git merge --cleanup=verbatim -F expect c2 && + git cat-file commit HEAD >raw && + sed -e "1,/^$/d" raw >actual && + test_cmp expect actual +' + +test_expect_success 'cleanup commit messages (whitespace option)' ' + git reset --hard c1 && + test_write_lines "" "# text" "" >text && + echo "# text" >expect && + git merge --cleanup=whitespace -F text c2 && + git cat-file commit HEAD >raw && + sed -e "1,/^$/d" raw >actual && + test_cmp expect actual +' + +test_expect_success 'cleanup merge messages (scissors option)' ' + git reset --hard c1 && + cat >text <<-\EOF && + + # to be kept + + # ------------------------ >8 ------------------------ + # to be kept, too + # ------------------------ >8 ------------------------ + to be removed + # ------------------------ >8 ------------------------ + to be removed, too + EOF + + cat >expect <<-\EOF && + # to be kept + + # ------------------------ >8 ------------------------ + # to be kept, too + EOF + git merge --cleanup=scissors -e -F text c2 && + git cat-file commit HEAD >raw && + sed -e "1,/^$/d" raw >actual && + test_cmp expect actual +' + +test_expect_success 'cleanup commit messages (strip option)' ' + git reset --hard c1 && + test_write_lines "" "# text" "sample" "" >text && + echo sample >expect && + git merge --cleanup=strip -F text c2 && + git cat-file commit HEAD >raw && + sed -e "1,/^$/d" raw >actual && + test_cmp expect actual +' + test_done diff --git a/wt-status.c b/wt-status.c index 445a36204a..b81fcd428d 100644 --- a/wt-status.c +++ b/wt-status.c @@ -1006,13 +1006,19 @@ size_t wt_status_locate_end(const char *s, size_t len) return len; } -void wt_status_add_cut_line(FILE *fp) +void wt_status_append_cut_line(struct strbuf *buf) { const char *explanation = _("Do not modify or remove the line above.\nEverything below it will be ignored."); + + strbuf_commented_addf(buf, "%s", cut_line); + strbuf_add_commented_lines(buf, explanation, strlen(explanation)); +} + +void wt_status_add_cut_line(FILE *fp) +{ struct strbuf buf = STRBUF_INIT; - fprintf(fp, "%c %s", comment_line_char, cut_line); - strbuf_add_commented_lines(&buf, explanation, strlen(explanation)); + wt_status_append_cut_line(&buf); fputs(buf.buf, fp); strbuf_release(&buf); } diff --git a/wt-status.h b/wt-status.h index 3a95975032..64f1ddc9fd 100644 --- a/wt-status.h +++ b/wt-status.h @@ -129,6 +129,7 @@ struct wt_status { }; size_t wt_status_locate_end(const char *s, size_t len); +void wt_status_append_cut_line(struct strbuf *buf); void wt_status_add_cut_line(FILE *fp); void wt_status_prepare(struct repository *r, struct wt_status *s); void wt_status_print(struct wt_status *s); From patchwork Thu Mar 21 06:53:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10862981 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1E26814DE for ; Thu, 21 Mar 2019 06:54:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F235F2A040 for ; Thu, 21 Mar 2019 06:54:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E64C72A042; Thu, 21 Mar 2019 06:54:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B0412A040 for ; Thu, 21 Mar 2019 06:54:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727903AbfCUGyE (ORCPT ); Thu, 21 Mar 2019 02:54:04 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:36615 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727891AbfCUGyD (ORCPT ); Thu, 21 Mar 2019 02:54:03 -0400 Received: by mail-pf1-f193.google.com with SMTP id p10so3700994pff.3 for ; Wed, 20 Mar 2019 23:54:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Z9TOT/jnKBJCYSiQ22hbiwhygPS/MaEkZFG3c2YeXgc=; b=bkyh/FJXU0p1SQpFhVZhTdy2wdYCgQ7N4J9pFyu3KPQ/3tFtCwPvZWbm7In6tWHmEK 1o0vtlJybek0tOrlVN6ctP4Y2W8WPGF1ryT5kSCD9eO65yyXV6ZDfC+2ROb5XU82jInz FTRDbIkJtTyDv3ydyCgqLvZ53GabSi68QBGQ9+GaxR/qZFhnNcbwyklTCTD12l7L5d1j kKDPgqjphsco8F5CU7K3NYbPLcuCBvcWJB3MCnpe01yayK2KM7KbHAqW9KeTwXBGO3o/ qoQQO925+b4xk156HdcyzhxBxPb35RxkrbG9Z+Sdb3EW8qLJS5kkL3ooDC/mBtqu9XH3 Vadg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Z9TOT/jnKBJCYSiQ22hbiwhygPS/MaEkZFG3c2YeXgc=; b=GqmuQ64P8cwtmE6/jnl0BD87e8tyqDSTh/E41k9Mtuj4XQM6De21AL6uXWOfBbmQYk Lx1K5EML1GfbuNzxZCYj3InKZ8XYp5jTiTQ3zg1ourlpiJzrIOXXtr11SYPO8h/DMkfY 6bjrFZQqiffq0DNHGAHdsGhhTwTX8wrrxYvJe7Q+LXGrkdLtQuWMAn0aCc7GbV6a9PHX GnYKfBGt7EDBg85UyEXa/oiU7QA3GhUJXLffmL5+GZYKrvzj++06pE2X2fDdi/aGLPqN LCaHJfm+qlNsKILI5tGRNhUVytHglS15mYJWozeI6ki3ZLuR31wVSSeGQPoucmu5m0wt cp7Q== X-Gm-Message-State: APjAAAWnc4ylzaDoiKs7dyJnt+uGoeau9oM7KF9HOLrxR7oqAFJAvbjB ckH3NBkKypcm06JvOz8BUEY1hb/SwZY= X-Google-Smtp-Source: APXvYqwxgZWpxuBxuNfEihXaDkmuFbUPTGrQkNuRP8MOkYSBxB6ht0jjwGKvxVL6VsiMxy3tyKrgQA== X-Received: by 2002:a63:fc49:: with SMTP id r9mr1885487pgk.447.1553151242467; Wed, 20 Mar 2019 23:54:02 -0700 (PDT) Received: from archbookpro.localdomain (c-73-222-73-77.hsd1.ca.comcast.net. [73.222.73.77]) by smtp.gmail.com with ESMTPSA id u13sm7079346pfa.169.2019.03.20.23.54.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Mar 2019 23:54:01 -0700 (PDT) Date: Wed, 20 Mar 2019 23:53:59 -0700 From: Denton Liu To: Git Mailing List Cc: Denton Liu , Eric Sunshine , Junio C Hamano , Phillip Wood , Ramsay Jones , SZEDER =?iso-8859-1?q?G=E1bor?= Subject: [PATCH v9 09/11] merge: add scissors line on merge conflict Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.3 (2019-02-01) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This fixes a bug where the scissors line is placed after the Conflicts: section, in the case where a merge conflict occurs and commit.cleanup = scissors. Next, if commit.cleanup = scissors is specified, don't produce a scissors line in commit if one already exists in the MERGE_MSG file. Helped-by: Eric Sunshine Signed-off-by: Denton Liu --- Documentation/merge-options.txt | 7 +++-- builtin/commit.c | 20 ++++++++++---- builtin/merge.c | 14 ++++++++++ t/t7600-merge.sh | 46 +++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 7 deletions(-) diff --git a/Documentation/merge-options.txt b/Documentation/merge-options.txt index bcf0b3e49c..61876dbc33 100644 --- a/Documentation/merge-options.txt +++ b/Documentation/merge-options.txt @@ -33,8 +33,11 @@ updated behaviour, the environment variable `GIT_MERGE_AUTOEDIT` can be set to `no` at the beginning of them. --cleanup=:: - This option determines how the merge message will be cleaned up - before commiting. See linkgit:git-commit[1] for more details. + This option determines how the merge message will be cleaned up before + commiting. See linkgit:git-commit[1] for more details. In addition, if + the '' is given a value of `scissors`, scissors will be appended + to `MERGE_MSG` before being passed on to the commit machinery in the + case of a merge conflict. --ff:: When the merge resolves as a fast-forward, only update the branch diff --git a/builtin/commit.c b/builtin/commit.c index ba1e6027ba..b9159c2e7b 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -668,6 +668,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix, const char *hook_arg2 = NULL; int clean_message_contents = (cleanup_mode != COMMIT_MSG_CLEANUP_NONE); int old_display_comment_prefix; + int merge_contains_scissors = 0; /* This checks and barfs if author is badly specified */ determine_author_info(author_ident); @@ -728,6 +729,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix, strbuf_addbuf(&sb, &message); hook_arg1 = "message"; } else if (!stat(git_path_merge_msg(the_repository), &statbuf)) { + size_t merge_msg_start; + /* * prepend SQUASH_MSG here if it exists and a * "merge --squash" was originally performed @@ -738,8 +741,14 @@ static int prepare_to_commit(const char *index_file, const char *prefix, hook_arg1 = "squash"; } else hook_arg1 = "merge"; + + merge_msg_start = sb.len; if (strbuf_read_file(&sb, git_path_merge_msg(the_repository), 0) < 0) die_errno(_("could not read MERGE_MSG")); + + if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS && + wt_status_locate_end(sb.buf + merge_msg_start, sb.len - merge_msg_start) < sb.len - merge_msg_start) + merge_contains_scissors = 1; } else if (!stat(git_path_squash_msg(the_repository), &statbuf)) { if (strbuf_read_file(&sb, git_path_squash_msg(the_repository), 0) < 0) die_errno(_("could not read SQUASH_MSG")); @@ -807,7 +816,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix, struct ident_split ci, ai; if (whence != FROM_COMMIT) { - if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS) + if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS && + !merge_contains_scissors) wt_status_add_cut_line(s->fp); status_printf_ln(s, GIT_COLOR_NORMAL, whence == FROM_MERGE @@ -832,10 +842,10 @@ static int prepare_to_commit(const char *index_file, const char *prefix, _("Please enter the commit message for your changes." " Lines starting\nwith '%c' will be ignored, and an empty" " message aborts the commit.\n"), comment_line_char); - else if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS && - whence == FROM_COMMIT) - wt_status_add_cut_line(s->fp); - else /* COMMIT_MSG_CLEANUP_SPACE, that is. */ + else if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS) { + if (whence == FROM_COMMIT && !merge_contains_scissors) + wt_status_add_cut_line(s->fp); + } else /* COMMIT_MSG_CLEANUP_SPACE, that is. */ status_printf(s, GIT_COLOR_NORMAL, _("Please enter the commit message for your changes." " Lines starting\n" diff --git a/builtin/merge.c b/builtin/merge.c index f5783a901d..148554f08e 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -920,6 +920,20 @@ static int suggest_conflicts(void) filename = git_path_merge_msg(the_repository); fp = xfopen(filename, "a"); + /* + * We can't use cleanup_mode because if we're not using the editor, + * get_cleanup_mode will return COMMIT_MSG_CLEANUP_SPACE instead, even + * though the message is meant to be processed later by git-commit. + * Thus, we will get the cleanup mode which is returned when we _are_ using + * an editor. + */ + if (get_cleanup_mode(cleanup_arg, 1, 1) == COMMIT_MSG_CLEANUP_SCISSORS) { + fputc('\n', fp); + wt_status_add_cut_line(fp); + /* comments out the newline from append_conflicts_hint */ + fputc(comment_line_char, fp); + } + append_conflicts_hint(&the_index, &msgbuf); fputs(msgbuf.buf, fp); strbuf_release(&msgbuf); diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh index 2f4c2801fb..7f9c68cbe7 100755 --- a/t/t7600-merge.sh +++ b/t/t7600-merge.sh @@ -246,6 +246,52 @@ test_expect_success 'merge --squash c3 with c7' ' test_cmp expect actual ' +test_expect_success 'merge c3 with c7 with commit.cleanup = scissors' ' + git config commit.cleanup scissors && + git reset --hard c3 && + test_must_fail git merge c7 && + cat result.9z >file && + git commit --no-edit -a && + + cat >expect <<-\EOF && + Merge tag '"'"'c7'"'"' + + # ------------------------ >8 ------------------------ + # Do not modify or remove the line above. + # Everything below it will be ignored. + # + # Conflicts: + # file + EOF + git cat-file commit HEAD >raw && + sed -e '1,/^$/d' raw >actual && + test_i18ncmp expect actual +' + +test_expect_success 'merge c3 with c7 with --squash commit.cleanup = scissors' ' + git config commit.cleanup scissors && + git reset --hard c3 && + test_must_fail git merge --squash c7 && + cat result.9z >file && + git commit --no-edit -a && + + cat >expect <<-EOF && + Squashed commit of the following: + + $(git show -s c7) + + # ------------------------ >8 ------------------------ + # Do not modify or remove the line above. + # Everything below it will be ignored. + # + # Conflicts: + # file + EOF + git cat-file commit HEAD >raw && + sed -e '1,/^$/d' raw >actual && + test_i18ncmp expect actual +' + test_debug 'git log --graph --decorate --oneline --all' test_expect_success 'merge c1 with c2 and c3' ' From patchwork Thu Mar 21 06:54:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10862983 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DE7EC14DE for ; Thu, 21 Mar 2019 06:54:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C1DF329B17 for ; Thu, 21 Mar 2019 06:54:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B61EC29B78; Thu, 21 Mar 2019 06:54:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3FA4929B55 for ; Thu, 21 Mar 2019 06:54:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727913AbfCUGyH (ORCPT ); Thu, 21 Mar 2019 02:54:07 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:33077 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727906AbfCUGyG (ORCPT ); Thu, 21 Mar 2019 02:54:06 -0400 Received: by mail-pf1-f193.google.com with SMTP id i19so3705373pfd.0 for ; Wed, 20 Mar 2019 23:54:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=0PCZX0znN8Onl/GO23qvYBYcSPcLb0OMFLvSGScPF9c=; b=A6jPfPXISt7i3RUTYoDKEDlBoBnNi+Q4Jz52L4OE4hubr7scWI8Dx0NZacDwRCFEh8 5bX2E+MLbxq4HLFvizdB5TX+yDPfXk2bBMFhEY2LzPT+IUjvu/i2oOjx1h4wSYcrKopK j8uxUNhF/Vbvdtd8suhJwBJdXgsbOHvlOckk55y96Fst+47hVl1b5q+9JeV4K9mqVrWg D1D9d/rYaD7ymSTcsJuPQCMEg3kLVFs8p1tGPy4gJLrp9f8bHFRdA5FpwEegStK+rQGv wIuS016Ug6OnB5fNeZsnWxjX3O6iyY6WgrnMtkjiEHLSIe4hkqJ97eFwSQjc0VCMj1xA 3YRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=0PCZX0znN8Onl/GO23qvYBYcSPcLb0OMFLvSGScPF9c=; b=PhyyiBy3UYPaVDaEPwiOf9OyJvyk63/j6pWwk4k1maeyyBMHNvvNV6LoA7AmuE++3Y Zvn3iNzdzHLuFVheuDNeRYuHnGhtrymhS2dFjxEfV7mxUNnbHAPtS3UfzKiOkRnGoL2x hEFlZE/VBkZuxffSWh3JO9HpBs1YTkyVVzvWTnusWE3kD1FZiw1J6Rp/2SyQkvt+W9Bq vCZ74UJ4/NIjZPDC2B9+vyFgDeiuXIP+0VD0wJJPP1f00ftmxdui9B26Ygnnn0ijXkgu D3V3lZfvjGKBY0fwGEYeqUIs31qCxEaD3G7bcNbLQTGUDB6U9Ywuv+s+ikXAQpCqqCvM WyAQ== X-Gm-Message-State: APjAAAXWlndttMip6z9xcyHIckRjY5EIKrpEtCMUVpMpyjP1K6SL/8JF VgcFlQR9Wz9tG85pwKXaOwi/Zvcs6t8= X-Google-Smtp-Source: APXvYqyzHgUvo+c5LtjHzZY0IxarRwW7KgcZLwyluGe5oI5WiPC68DA6fr/e4QTFoAS7KgSN0vo6qg== X-Received: by 2002:a17:902:8bc7:: with SMTP id r7mr1970458plo.163.1553151245582; Wed, 20 Mar 2019 23:54:05 -0700 (PDT) Received: from archbookpro.localdomain (c-73-222-73-77.hsd1.ca.comcast.net. [73.222.73.77]) by smtp.gmail.com with ESMTPSA id i25sm4960891pfd.52.2019.03.20.23.54.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Mar 2019 23:54:04 -0700 (PDT) Date: Wed, 20 Mar 2019 23:54:02 -0700 From: Denton Liu To: Git Mailing List Cc: Denton Liu , Eric Sunshine , Junio C Hamano , Phillip Wood , Ramsay Jones , SZEDER =?iso-8859-1?q?G=E1bor?= Subject: [PATCH v9 10/11] sequencer.c: define describe_cleanup_mode Message-ID: <5927064b68c3894df69ecfb2c7224acc46f786d4.1553150827.git.liu.denton@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.3 (2019-02-01) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Define a function which allows us to get the string configuration value of a enum commit_msg_cleanup_mode. This is done by refactoring get_cleanup_mode such that it uses a lookup table to find the mappings between string and enum and then using the same LUT in reverse to define describe_cleanup_mode. Helped-by: Eric Sunshine Helped-by: Junio C Hamano Helped-by: Ramsay Jones Signed-off-by: Denton Liu --- sequencer.c | 62 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 15 deletions(-) diff --git a/sequencer.c b/sequencer.c index 2cbfb848dd..f782e8bab2 100644 --- a/sequencer.c +++ b/sequencer.c @@ -160,6 +160,22 @@ static GIT_PATH_FUNC(rebase_path_strategy_opts, "rebase-merge/strategy_opts") static GIT_PATH_FUNC(rebase_path_allow_rerere_autoupdate, "rebase-merge/allow_rerere_autoupdate") static GIT_PATH_FUNC(rebase_path_reschedule_failed_exec, "rebase-merge/reschedule-failed-exec") +struct cleanup_config_mapping { + const char *value; + enum commit_msg_cleanup_mode editor; + enum commit_msg_cleanup_mode no_editor; +}; + +/* the 0th element of this array must be the "default" */ +static struct cleanup_config_mapping cleanup_config_mapping[] = { + { "default", COMMIT_MSG_CLEANUP_ALL, COMMIT_MSG_CLEANUP_SPACE }, + { "verbatim", COMMIT_MSG_CLEANUP_NONE, COMMIT_MSG_CLEANUP_NONE }, + { "whitespace", COMMIT_MSG_CLEANUP_SPACE, COMMIT_MSG_CLEANUP_SPACE }, + { "strip", COMMIT_MSG_CLEANUP_ALL, COMMIT_MSG_CLEANUP_ALL }, + { "scissors", COMMIT_MSG_CLEANUP_SCISSORS, COMMIT_MSG_CLEANUP_SPACE }, + { NULL, 0, 0 } +}; + static int git_sequencer_config(const char *k, const char *v, void *cb) { struct replay_opts *opts = cb; @@ -504,26 +520,37 @@ static int fast_forward_to(struct repository *r, enum commit_msg_cleanup_mode get_cleanup_mode(const char *cleanup_arg, int use_editor, int die_on_error) { - if (!cleanup_arg || !strcmp(cleanup_arg, "default")) - return use_editor ? COMMIT_MSG_CLEANUP_ALL : - COMMIT_MSG_CLEANUP_SPACE; - else if (!strcmp(cleanup_arg, "verbatim")) - return COMMIT_MSG_CLEANUP_NONE; - else if (!strcmp(cleanup_arg, "whitespace")) - return COMMIT_MSG_CLEANUP_SPACE; - else if (!strcmp(cleanup_arg, "strip")) - return COMMIT_MSG_CLEANUP_ALL; - else if (!strcmp(cleanup_arg, "scissors")) - return use_editor ? COMMIT_MSG_CLEANUP_SCISSORS : - COMMIT_MSG_CLEANUP_SPACE; - else if (!die_on_error) { + struct cleanup_config_mapping *def = &cleanup_config_mapping[0]; + struct cleanup_config_mapping *p; + + if (!cleanup_arg) + return use_editor ? def->editor : + def->no_editor; + + for (p = cleanup_config_mapping; p->value; p++) + if (!strcmp(cleanup_arg, p->value)) + return use_editor ? p->editor : + p->no_editor; + + if (!die_on_error) { warning(_("invalid cleanup mode %s, falling back to default"), cleanup_arg); - return use_editor ? COMMIT_MSG_CLEANUP_ALL : - COMMIT_MSG_CLEANUP_SPACE; + return use_editor ? def->editor : + def->no_editor; } else die(_("invalid cleanup mode %s"), cleanup_arg); } +static const char *describe_cleanup_mode(enum commit_msg_cleanup_mode cleanup_mode) +{ + struct cleanup_config_mapping *curr; + + for (curr = &cleanup_config_mapping[1]; curr->value; curr++) + if (cleanup_mode == curr->editor) + return curr->value; + + BUG("invalid cleanup_mode provided (%d)", cleanup_mode); +} + void append_conflicts_hint(struct index_state *istate, struct strbuf *msgbuf) { @@ -2350,6 +2377,8 @@ static int populate_opts_cb(const char *key, const char *value, void *data) opts->allow_rerere_auto = git_config_bool_or_int(key, value, &error_flag) ? RERERE_AUTOUPDATE : RERERE_NOAUTOUPDATE; + else if (!strcmp(key, "options.default-msg-cleanup")) + opts->default_msg_cleanup = get_cleanup_mode(value, 1, 1); else return error(_("invalid key: %s"), key); @@ -2754,6 +2783,9 @@ static int save_opts(struct replay_opts *opts) res |= git_config_set_in_file_gently(opts_file, "options.allow-rerere-auto", opts->allow_rerere_auto == RERERE_AUTOUPDATE ? "true" : "false"); + + res |= git_config_set_in_file_gently(opts_file, "options.default-msg-cleanup", + describe_cleanup_mode(opts->default_msg_cleanup)); return res; } From patchwork Thu Mar 21 06:54:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10862985 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5A2371515 for ; Thu, 21 Mar 2019 06:54:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 396A029B17 for ; Thu, 21 Mar 2019 06:54:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2D5E129B84; Thu, 21 Mar 2019 06:54:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 54B7229B17 for ; Thu, 21 Mar 2019 06:54:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727914AbfCUGyK (ORCPT ); Thu, 21 Mar 2019 02:54:10 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:43587 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727916AbfCUGyJ (ORCPT ); Thu, 21 Mar 2019 02:54:09 -0400 Received: by mail-pg1-f196.google.com with SMTP id l11so3558305pgq.10 for ; Wed, 20 Mar 2019 23:54:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=cb6h+DE9n6oxhpoFSXl0d5M9mXzKYbJZwUhqswaLqnk=; b=byNabiMIjiLojD+v5pLZM9sTxrknt7fHy0SDewF8wtElqWAlxxB3H7YvMnC2IfMVQf 7qyvyYLADRDGLxt9b/Zh6r6VCukJxgYB5S0YKv13dwOoUfykyTa8Fqx4rYK6xoF1HH4X ymES4jy0DXD2Gd8Y4IpXndbEqJkKdIOSKUbztyES4oZ7gSXwAU434tRqpeXGl0a4dV7E N6UNm7Mkr1D3eEUFH4pbUo2csrY4A/4YYfpQCdrixCyP31nRs+un6YE+TNnadiEqpL5A 9Z6xtzHjKi30am1xecrZYKwgEVWNWS4M+70oRa011PPSF+LFS24VZO0xSaNnNPuCyp2X Kmnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=cb6h+DE9n6oxhpoFSXl0d5M9mXzKYbJZwUhqswaLqnk=; b=gMhm0CBkFSJp7nhjs3aCm/fz2zoGzADMwUJM7D27GGiZWglRtmjv3RY/+ucUrrvQBN 7GxpvrKUwiM8PRvdouG9M+WLhiZXBQOvMz8tpAptmcW0BhBJeCR6RnBf99UrrYX9n+is paZOuacHxXS7QU6PGaD2TlFCHju3/VyAk/7peJa5WPDat3oLyGA5XL9YDtzuJ6+snBXQ G4syYvx4ehJZfORW30WAezVVN/zloVDp+oDDCuXk7k7yOypgM7P1tDgzcUUjE++DH07Y t0tsxcnmPE6gvCsq/fVdN8kQZPsrpFEMLYs+riQYhFTR96Qe9oqUdRg+7YWfmR+tQN45 4qFg== X-Gm-Message-State: APjAAAXvgC8+SPrlVn7u9GFkW8QX5Te5RrL1t+dyZhyXQ//vA2rBqhQu 7VglOBPU4fYV8vEO4cwhMHwIlaJEJAg= X-Google-Smtp-Source: APXvYqx7bGtr1Z8XdEKPP/D/VZXjMuuHDP5K/GT9N3dihP0cRH65AzVZLH3x/vx4ez4GUeyNViiNmw== X-Received: by 2002:a62:121c:: with SMTP id a28mr1861955pfj.58.1553151248194; Wed, 20 Mar 2019 23:54:08 -0700 (PDT) Received: from archbookpro.localdomain (c-73-222-73-77.hsd1.ca.comcast.net. [73.222.73.77]) by smtp.gmail.com with ESMTPSA id 14sm5941232pft.137.2019.03.20.23.54.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Mar 2019 23:54:07 -0700 (PDT) Date: Wed, 20 Mar 2019 23:54:05 -0700 From: Denton Liu To: Git Mailing List Cc: Denton Liu , Eric Sunshine , Junio C Hamano , Phillip Wood , Ramsay Jones , SZEDER =?iso-8859-1?q?G=E1bor?= Subject: [PATCH v9 11/11] cherry-pick/revert: add scissors line on merge conflict Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.3 (2019-02-01) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Fix a bug where the scissors line is placed after the Conflicts: section, in the case where a merge conflict occurs and commit.cleanup = scissors. Helped-by: Phillip Wood Signed-off-by: Denton Liu --- Documentation/git-cherry-pick.txt | 7 +++ Documentation/git-revert.txt | 7 +++ builtin/merge.c | 9 +--- builtin/rebase--interactive.c | 2 +- builtin/revert.c | 5 ++ sequencer.c | 22 +++++--- sequencer.h | 3 +- t/t3507-cherry-pick-conflict.sh | 86 +++++++++++++++++++++++++++++++ 8 files changed, 123 insertions(+), 18 deletions(-) diff --git a/Documentation/git-cherry-pick.txt b/Documentation/git-cherry-pick.txt index b8cfeec67e..cbb663a843 100644 --- a/Documentation/git-cherry-pick.txt +++ b/Documentation/git-cherry-pick.txt @@ -57,6 +57,13 @@ OPTIONS With this option, 'git cherry-pick' will let you edit the commit message prior to committing. +--cleanup=:: + This option determines how the commit message will be cleaned up before + being passed on to the commit machinery. See linkgit:git-commit[1] for more + details. In particular, if the '' is given a value of `scissors`, + scissors will be appended to `MERGE_MSG` before being passed on in the case + of a conflict. + -x:: When recording the commit, append a line that says "(cherry picked from commit ...)" to the original commit diff --git a/Documentation/git-revert.txt b/Documentation/git-revert.txt index 837707a8fd..7fd254df92 100644 --- a/Documentation/git-revert.txt +++ b/Documentation/git-revert.txt @@ -66,6 +66,13 @@ more details. With this option, 'git revert' will not start the commit message editor. +--cleanup=:: + This option determines how the commit message will be cleaned up before + being passed on to the commit machinery. See linkgit:git-commit[1] for more + details. In particular, if the '' is given a value of `scissors`, + scissors will be appended to `MERGE_MSG` before being passed on in the case + of a conflict. + -n:: --no-commit:: Usually the command automatically creates some commits with diff --git a/builtin/merge.c b/builtin/merge.c index 148554f08e..235cd3b2e1 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -927,14 +927,7 @@ static int suggest_conflicts(void) * Thus, we will get the cleanup mode which is returned when we _are_ using * an editor. */ - if (get_cleanup_mode(cleanup_arg, 1, 1) == COMMIT_MSG_CLEANUP_SCISSORS) { - fputc('\n', fp); - wt_status_add_cut_line(fp); - /* comments out the newline from append_conflicts_hint */ - fputc(comment_line_char, fp); - } - - append_conflicts_hint(&the_index, &msgbuf); + append_conflicts_hint(&the_index, &msgbuf, get_cleanup_mode(cleanup_arg, 1, 1)); fputs(msgbuf.buf, fp); strbuf_release(&msgbuf); fclose(fp); diff --git a/builtin/rebase--interactive.c b/builtin/rebase--interactive.c index 888390f911..cf2151b271 100644 --- a/builtin/rebase--interactive.c +++ b/builtin/rebase--interactive.c @@ -199,10 +199,10 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix) OPT_END() }; + opts.action = REPLAY_INTERACTIVE_REBASE; sequencer_init_config(&opts); git_config_get_bool("rebase.abbreviatecommands", &abbreviate_commands); - opts.action = REPLAY_INTERACTIVE_REBASE; opts.allow_ff = 1; opts.allow_empty = 1; diff --git a/builtin/revert.c b/builtin/revert.c index a47b53ceaf..41e7392c24 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -96,11 +96,13 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts) { const char * const * usage_str = revert_or_cherry_pick_usage(opts); const char *me = action_name(opts); + const char *cleanup_arg = NULL; int cmd = 0; struct option base_options[] = { OPT_CMDMODE(0, "quit", &cmd, N_("end revert or cherry-pick sequence"), 'q'), OPT_CMDMODE(0, "continue", &cmd, N_("resume revert or cherry-pick sequence"), 'c'), OPT_CMDMODE(0, "abort", &cmd, N_("cancel revert or cherry-pick sequence"), 'a'), + OPT_CLEANUP(&cleanup_arg), OPT_BOOL('n', "no-commit", &opts->no_commit, N_("don't automatically commit")), OPT_BOOL('e', "edit", &opts->edit, N_("edit the commit message")), OPT_NOOP_NOARG('r', NULL), @@ -137,6 +139,9 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts) if (opts->keep_redundant_commits) opts->allow_empty = 1; + if (cleanup_arg) + opts->default_msg_cleanup = get_cleanup_mode(cleanup_arg, 1, 1); + /* Check for incompatible command line arguments */ if (cmd) { char *this_operation; diff --git a/sequencer.c b/sequencer.c index f782e8bab2..ea4687c3da 100644 --- a/sequencer.c +++ b/sequencer.c @@ -176,6 +176,11 @@ static struct cleanup_config_mapping cleanup_config_mapping[] = { { NULL, 0, 0 } }; +static inline int is_rebase_i(const struct replay_opts *opts) +{ + return opts->action == REPLAY_INTERACTIVE_REBASE; +} + static int git_sequencer_config(const char *k, const char *v, void *cb) { struct replay_opts *opts = cb; @@ -188,7 +193,7 @@ static int git_sequencer_config(const char *k, const char *v, void *cb) if (status) return status; - opts->default_msg_cleanup = get_cleanup_mode(s, 0, 0); + opts->default_msg_cleanup = get_cleanup_mode(s, !is_rebase_i(opts), 0); free((char *)s); return status; @@ -212,11 +217,6 @@ void sequencer_init_config(struct replay_opts *opts) git_config(git_sequencer_config, opts); } -static inline int is_rebase_i(const struct replay_opts *opts) -{ - return opts->action == REPLAY_INTERACTIVE_REBASE; -} - static const char *get_dir(const struct replay_opts *opts) { if (is_rebase_i(opts)) @@ -552,10 +552,16 @@ static const char *describe_cleanup_mode(enum commit_msg_cleanup_mode cleanup_mo } void append_conflicts_hint(struct index_state *istate, - struct strbuf *msgbuf) + struct strbuf *msgbuf, enum commit_msg_cleanup_mode cleanup_mode) { int i; + if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS) { + strbuf_addch(msgbuf, '\n'); + wt_status_append_cut_line(msgbuf); + strbuf_addch(msgbuf, comment_line_char); + } + strbuf_addch(msgbuf, '\n'); strbuf_commented_addf(msgbuf, "Conflicts:\n"); for (i = 0; i < istate->cache_nr;) { @@ -623,7 +629,7 @@ static int do_recursive_merge(struct repository *r, _(action_name(opts))); if (!clean) - append_conflicts_hint(r->index, msgbuf); + append_conflicts_hint(r->index, msgbuf, opts->default_msg_cleanup); return !clean; } diff --git a/sequencer.h b/sequencer.h index e7908f558e..830d8232f6 100644 --- a/sequencer.h +++ b/sequencer.h @@ -115,7 +115,8 @@ int rearrange_squash(struct repository *r); */ void append_signoff(struct strbuf *msgbuf, size_t ignore_footer, unsigned flag); -void append_conflicts_hint(struct index_state *istate, struct strbuf *msgbuf); +void append_conflicts_hint(struct index_state *istate, + struct strbuf *msgbuf, enum commit_msg_cleanup_mode cleanup_mode); enum commit_msg_cleanup_mode get_cleanup_mode(const char *cleanup_arg, int use_editor, int die_on_error); diff --git a/t/t3507-cherry-pick-conflict.sh b/t/t3507-cherry-pick-conflict.sh index 777fb23d18..a584b11c98 100755 --- a/t/t3507-cherry-pick-conflict.sh +++ b/t/t3507-cherry-pick-conflict.sh @@ -189,6 +189,46 @@ test_expect_success 'failed cherry-pick registers participants in index' ' test_cmp expected actual ' +test_expect_success \ + 'cherry-pick conflict, ensure commit.cleanup = scissors places scissors line properly' ' + pristine_detach initial && + git config commit.cleanup scissors && + cat <<-EOF >expected && + picked + + # ------------------------ >8 ------------------------ + # Do not modify or remove the line above. + # Everything below it will be ignored. + # + # Conflicts: + # foo + EOF + + test_must_fail git cherry-pick picked && + + test_i18ncmp expected .git/MERGE_MSG +' + +test_expect_success \ + 'cherry-pick conflict, ensure cleanup=scissors places scissors line properly' ' + pristine_detach initial && + git config --unset commit.cleanup && + cat <<-EOF >expected && + picked + + # ------------------------ >8 ------------------------ + # Do not modify or remove the line above. + # Everything below it will be ignored. + # + # Conflicts: + # foo + EOF + + test_must_fail git cherry-pick --cleanup=scissors picked && + + test_i18ncmp expected .git/MERGE_MSG +' + test_expect_success 'failed cherry-pick describes conflict in work tree' ' pristine_detach initial && cat <<-EOF >expected && @@ -335,6 +375,52 @@ test_expect_success 'revert conflict, diff3 -m style' ' test_cmp expected actual ' +test_expect_success \ + 'revert conflict, ensure commit.cleanup = scissors places scissors line properly' ' + pristine_detach initial && + git config commit.cleanup scissors && + cat >expected <<-EOF && + Revert "picked" + + This reverts commit OBJID. + + # ------------------------ >8 ------------------------ + # Do not modify or remove the line above. + # Everything below it will be ignored. + # + # Conflicts: + # foo + EOF + + test_must_fail git revert picked && + + sed "s/$OID_REGEX/OBJID/" .git/MERGE_MSG >actual && + test_i18ncmp expected actual +' + +test_expect_success \ + 'revert conflict, ensure cleanup=scissors places scissors line properly' ' + pristine_detach initial && + git config --unset commit.cleanup && + cat >expected <<-EOF && + Revert "picked" + + This reverts commit OBJID. + + # ------------------------ >8 ------------------------ + # Do not modify or remove the line above. + # Everything below it will be ignored. + # + # Conflicts: + # foo + EOF + + test_must_fail git revert --cleanup=scissors picked && + + sed "s/$OID_REGEX/OBJID/" .git/MERGE_MSG >actual && + test_i18ncmp expected actual +' + test_expect_success 'failed cherry-pick does not forget -s' ' pristine_detach initial && test_must_fail git cherry-pick -s picked &&