From patchwork Sun Mar 17 10:15:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10856261 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 CDAE213B5 for ; Sun, 17 Mar 2019 10:16:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B722529736 for ; Sun, 17 Mar 2019 10:16:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A9EFF29741; Sun, 17 Mar 2019 10:16: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 2D33929736 for ; Sun, 17 Mar 2019 10:16:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726981AbfCQKP6 (ORCPT ); Sun, 17 Mar 2019 06:15:58 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:32901 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725903AbfCQKP5 (ORCPT ); Sun, 17 Mar 2019 06:15:57 -0400 Received: by mail-pg1-f196.google.com with SMTP id i7so6170714pgq.0 for ; Sun, 17 Mar 2019 03:15: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:content-transfer-encoding:in-reply-to :user-agent; bh=6tLa8EVqiBAi/50IMuEGPwdytGLpbHW67KzH7vRf1Ms=; b=ABQ/JyDcaKLDaVVoIyOUoyRLhPhDvoTRmEafKZnqG1foNu1IZDN/LsETKSRFU5tMn+ f6xhLI3KYKUDhyMVeegsh/HfEkf/QlC2Io4DHCgRZ2XxQ6wvOVei3GbN97sRZ60GEJ3R 0igaaDCWMhoFlAtWO5YzRqoc12EqMCuwfeMX/yV2RuaWlQBQ5vokz7NlrwRgYnNSdFJ2 F0doDWnECgPZNZMOEqgJjJ4+qD1ZI9rPJTH2xOp5N3eh8P+gDavmb+5VqbZWceiScYvB 7NK+LBnuX8hvet1Z8fkYaDM3LfMXnvFwR9VUDtGK2DKjhwMK5R27DFf+t67ddCJYN6Hp 80hA== 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=6tLa8EVqiBAi/50IMuEGPwdytGLpbHW67KzH7vRf1Ms=; b=Z5CrSgV2y9ictBGI+/9yYatJ3Y33QCKAxS1LKyt0FPlYv363GNhx+Qe/aZ/QUz7NjV Bw8uOrbQLPaGSfrMxoqszwLg48KiJMdn8jC9iQKQf1sAR4NVttWXmF5qfA829vKO9WRX nuon2MOBlKtTDHiAyW9VeF6XJTrwb9q5NnwstAcg5N91/8b1eW3SAShWjQT+Usbh10J8 lHZoU8zwu0KiZyCI8Uu0psd8qGQ4n65R4RjWMG2HQZJahoLKtPLN9eEtkJrHIFOL55Z+ Aguq634Y2Nr4/z2LPHgurNGVuMBUKLmxTaCiAEEh1sI0KdSp0K9IW/aAfVTU9FYDYjZH WQiA== X-Gm-Message-State: APjAAAXBKYz+vyvhwcn2CLLyI8ApbL+bFpldicWXSWfRVv9OjYA5lOIz dYj3WCLKrmqsFS+nq/Z+i46HjuON X-Google-Smtp-Source: APXvYqwtcHk1gpeJ0taJKZiFOSAorO3MIyGluhJoyVzzfUzC2PQ7wufegTwkZFwthw5N0x3PoBpXxg== X-Received: by 2002:aa7:8157:: with SMTP id d23mr13486218pfn.67.1552817756139; Sun, 17 Mar 2019 03:15: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 f65sm11881909pff.21.2019.03.17.03.15.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 17 Mar 2019 03:15:55 -0700 (PDT) Date: Sun, 17 Mar 2019 03:15:53 -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 v8 01/11] t7600: clean up style Message-ID: <08426189b5a29b376581eb0172e52222ab22387a.1552817044.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 This cleans up the 'merge --squash c3 with c7' test by removing some unnecessary braces and removing a pipe. Finally, unindent a here-doc for style. Also, remove stray spaces after "> " for style. Helped-by: SZEDER Gábor Helped-by: Eric Sunshine Reviewed-by: Junio C Hamano Signed-off-by: Denton Liu --- t/t7600-merge.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh index 106148254d..a9620cd991 100755 --- a/t/t7600-merge.sh +++ b/t/t7600-merge.sh @@ -233,17 +233,17 @@ 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 >actual && + sed -e '1,/^$/d' tmp && + mv tmp actual && test_cmp expect actual ' @@ -683,7 +683,7 @@ cat >editor <<\EOF 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 @@ -814,7 +814,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 Sun Mar 17 10:15:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10856263 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 B26E413B5 for ; Sun, 17 Mar 2019 10:16:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 999AD29736 for ; Sun, 17 Mar 2019 10:16:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8DB7C29741; Sun, 17 Mar 2019 10:16:02 +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 0D26429736 for ; Sun, 17 Mar 2019 10:16:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727040AbfCQKQA (ORCPT ); Sun, 17 Mar 2019 06:16:00 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:37278 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726923AbfCQKQA (ORCPT ); Sun, 17 Mar 2019 06:16:00 -0400 Received: by mail-pg1-f193.google.com with SMTP id q206so9382898pgq.4 for ; Sun, 17 Mar 2019 03:15:59 -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=hQP3QMkX4oKr9kqTVesaIk2t8FOx174qRwSWSmPWHs0=; b=lBXaINhlVws5ychy2JhI3tJDDshbjrp1A4a3CamDVqKBpIqDsj8/2iGOuVOru2DD0r 9MmhsfESstYm7sPh/pJfuNLMEsVBm6NR8pq6YS+gMPmrjkl4Y0KEhUGD79wU5CYrtmH3 SYH1QlkiacL9YT/Z3wca7JF+j7oS55GTZESaVCqqPEH/s1yaXFKlrpZSC9CXkcmq43m9 bZY3UEGxOQPzhHojy2mt2Aj2IFRFYtQF/1t2VIY5+hSHft+NkbOWdFyNvZ122d2yP1Bb SDrniH+FlA8VMIzYWTIoFDmspwDs14jS+U2sO7WbcApPXGDjRAig4NWRkH9TZUzTr2Zl nOCA== 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=hQP3QMkX4oKr9kqTVesaIk2t8FOx174qRwSWSmPWHs0=; b=RE9cHw3DQGt72hr8nbARBYhbKwh267JVnTmW1A0vBC3mMAYW3aOSTpkQKgc4Emhe9Z 182DUbTXs6PlCKMQb4g/NTdQRV4NrCXRXHeBTbNlJFwjpzFrLUFWP5GCx3SjGLvb6QXV cP2I0bvgYB9IDKL+BbFWZjUUEBisf0r2ZjS9+mwyOG5VCwm6dsB+8Y56fJMGaqDCRODM 4JEE0Ws2JUfvter5NUw8Z/ADPGrbgEoXUOWBOvezrFBrLrPV48TaLI1JWHuq/j3gpD/G wqMHKNX6eGlKgsgS0oP3dciYliRAYXo1Vs3dgPdUUY7cFzujfkyTRQzf6hVJZWTcDur5 OIWw== X-Gm-Message-State: APjAAAUtOGCfuoIIG3mmgN9Kl/R/fHV+hXPQ1Pgl4c2MeRqIOAooiSP6 bB9f2u/9ZYzLjSSPFwQ3hORN+r86 X-Google-Smtp-Source: APXvYqxmrsy0xA2QrZp+wFP8gFskwlPscqw/Dc4EeX2+AacCrpQqVEJPRXtXGuEpzXeOlw3Bxnm2Jw== X-Received: by 2002:a17:902:bb0c:: with SMTP id l12mr14060149pls.108.1552817758964; Sun, 17 Mar 2019 03:15:58 -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 k12sm9376619pfk.109.2019.03.17.03.15.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 17 Mar 2019 03:15:58 -0700 (PDT) Date: Sun, 17 Mar 2019 03:15:56 -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 v8 02/11] t3507: cleanup space after redirection operators Message-ID: <8bd03165e4703d6a791a617838a82fd0cb4f7e02.1552817044.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 --- t/t3507-cherry-pick-conflict.sh | 34 ++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/t/t3507-cherry-pick-conflict.sh b/t/t3507-cherry-pick-conflict.sh index 0db166152a..74ff925526 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 && + " 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 && + " 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 ' From patchwork Sun Mar 17 10:15: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: 10856265 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 38D6215AC for ; Sun, 17 Mar 2019 10:16:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 20F0E29736 for ; Sun, 17 Mar 2019 10:16:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 12E6829741; Sun, 17 Mar 2019 10:16:06 +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 EFD6A29736 for ; Sun, 17 Mar 2019 10:16:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727044AbfCQKQD (ORCPT ); Sun, 17 Mar 2019 06:16:03 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:35422 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725903AbfCQKQD (ORCPT ); Sun, 17 Mar 2019 06:16:03 -0400 Received: by mail-pf1-f195.google.com with SMTP id j5so9304424pfa.2 for ; Sun, 17 Mar 2019 03:16:02 -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=JEUcjZWzAIG9eXYnfQ0anKegnuSK2H+kNBChGsHs26g=; b=bgXs/JCP/xAXxmgyvlQZAo96JrZNP0aSRz/ky7Ta1SQYz1Kyf2SA7Qq8ryWgSPgns1 S3AnZErJ+oqNVlC/yqV+Yg3d9V+4TOuOAeimgfuPx22w52Mh26/1Cp7Sq2gWZJHsMcLB gQPh/VsyyUMCfjX6cTrUzinTCF6MR21Mi0XeTIbN2lW9M9JCe95aFwib02yAgbqETDJE +Ruz1xbgM0aW44MkGHXa6joPRzHkZCJgytesEEkhsM0ChRIpC9chZ0iUIeceOmbfNMK4 aKOh6ioIU2rLbLDs+6tylV5tMLpsLBGRWlu5AFx9pyjILBTYPIWms36MfmI+K161LGEl f9YQ== 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=JEUcjZWzAIG9eXYnfQ0anKegnuSK2H+kNBChGsHs26g=; b=iHsHzxVzwHoBSNRlrwmFkYygO55yFrid68+NoDX7VD8x0p/p9IwT3pzNmP6wV4kGa3 Cf5QDs4pJq59HoSBPqp2ki6imNYVWPJVjuPpqoAxpGb8tEhPM/DULxBLKygJoRP9uwPZ KUDE1iFPS5trzjnad0VO2dyUlFy/U83FjN44ZS4RZ6oNEutXZHYpj8FFX/o6CJqWuDkC KSv0HyIICanOUBJRF66JJJxoGn0Su6sPKLMODZv9+FDTGrx2Hy4yOd3kxtYEC2G39BAb /cjT8yN3TirLbNHuwVyOyb+OzSsB8kiwsz3HVGe8aNTsuXbSOxrKSzCPsP2w9wiI00Vo oYSQ== X-Gm-Message-State: APjAAAXucTwdHlyKDRnmWqDkh0aWAur9eqtPMj6aPJ3nnIbf08eoKpmN sPpqikpwshIcoIZOmfCwsoXw54Im X-Google-Smtp-Source: APXvYqxdBu+OWiHZVl5rr0u/I/FB9ufor8AkRFqnely5eosy7xVKSvMtUTc+p33IuHJyrJy3mreRHQ== X-Received: by 2002:a17:902:ab95:: with SMTP id f21mr14212135plr.188.1552817761803; Sun, 17 Mar 2019 03:16:01 -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 f65sm11882167pff.21.2019.03.17.03.16.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 17 Mar 2019 03:16:01 -0700 (PDT) Date: Sun, 17 Mar 2019 03:15: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 v8 03/11] t7604: refactor out Git commands upstream of pipe Message-ID: <9db7453b4e2b7221a039aa18509589e5c4f662b3.1552817044.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. Helped-by: Eric Sunshine Signed-off-by: Denton Liu --- t/t7604-merge-custom-message.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/t/t7604-merge-custom-message.sh b/t/t7604-merge-custom-message.sh index 89619cf446..b045fdb413 100755 --- a/t/t7604-merge-custom-message.sh +++ b/t/t7604-merge-custom-message.sh @@ -36,14 +36,18 @@ 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 >actual && + sed -e "1,/^$/d" tmp && + mv tmp 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 >actual && + sed -e "1,/^$/d" tmp && + mv tmp actual && test_cmp exp.log actual ' From patchwork Sun Mar 17 10:16: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: 10856267 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 AF9B615AC for ; Sun, 17 Mar 2019 10:16:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 953EC29736 for ; Sun, 17 Mar 2019 10:16:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8989F29741; Sun, 17 Mar 2019 10:16: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 D126629736 for ; Sun, 17 Mar 2019 10:16:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727104AbfCQKQG (ORCPT ); Sun, 17 Mar 2019 06:16:06 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:33793 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725903AbfCQKQG (ORCPT ); Sun, 17 Mar 2019 06:16:06 -0400 Received: by mail-pg1-f196.google.com with SMTP id v12so9412873pgq.1 for ; Sun, 17 Mar 2019 03:16:05 -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=wWJvqSE2oCViRRDJdK6IxbYXV6iq07YlKKMMctk4/OU=; b=DnpIzIQ09UKCl7FC3qob8gNnElrSQqu7iyrBZfppypq+JFFOAkvqY4V+5IlffKFKDA MOg7QahKUh8AL8G455BNJ3rZ2HPd37FYLesCaeaypFp2NzVgkUH7cVFP2Xj60Mt0FhHb RNW5K8frzcxnv0H1fIDekT2V6d4UZNGa6gFS22SDS3k4S86vMhSo6HQUumWibvkyA01Z qXEXPY0le5N/0HvJmdxZwdi6IvoIvowwiq9uqmv0gSAav4hQ3livznV60giVdtUXytyS eg6ixOn9XsyAT21/6nkSrV1EHAspnpFJG2T6mulEjw3Vd29VCM2ojXU0qXC+iH8zHsly nYHQ== 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=wWJvqSE2oCViRRDJdK6IxbYXV6iq07YlKKMMctk4/OU=; b=bRi7LsF90r/y1xQAtFI8/oDIBhw+jZkJ4Stx2WUA3OBsegyX8/2GOyLx0Wz9NA7zoz ayBzaYgnBZ+mJ4Xbn7ofcy8P70/eJwkfffLZ8tjY0RunVTdFyLYuNd/ZyH4H/kyiBR5I WyFClMEDObt3dc3Dmx7yzHLJQWp1nCZPIVXVmfUTPovO1sTumuHMnR8wzNC1Q/FcMm1P gRNm77KkDYxgdnzcVBLXqfXh0hjG7sbC3aLBiGFqBzaxmR4EUuhCUCFiNWZETUaGjHrq YLXU2Vwb56gKIX19knfhAG96/kbde9d12ZjNKW9HA/pL1NB27wRu+yl0NAopdhhRxwM/ 16+A== X-Gm-Message-State: APjAAAVCsKJgrc2lBlDy20LDlQwP4TqIqHLtt9PtWgRwFJt9Ye0WJsSf 88rS8jr8fIkqscBMpd6N/UaYSfdM X-Google-Smtp-Source: APXvYqxlnkW8PVbThQ4hoL6Id6tv/30KzJ7PYsPQWLOloqmjNHvib4nGLvKV4WxnSmjbZQWpJbz+Mw== X-Received: by 2002:a17:902:aa92:: with SMTP id d18mr13494567plr.278.1552817764856; Sun, 17 Mar 2019 03:16:04 -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 138sm10343285pfx.93.2019.03.17.03.16.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 17 Mar 2019 03:16:04 -0700 (PDT) Date: Sun, 17 Mar 2019 03:16: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 v8 04/11] t7502: clean up test style Message-ID: <0759de616eb57825852a2a1b5e27f6e884d68fc2.1552817044.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. Also, as a style cleanup, remove spaces after "> ". Next, indent here-docs. Finally, convert echo chains to use the test_write_lines function. Helped-by: Eric Sunshine Signed-off-by: Denton Liu --- t/t7502-commit-porcelain.sh | 100 ++++++++++++++++++++++-------------- 1 file changed, 61 insertions(+), 39 deletions(-) diff --git a/t/t7502-commit-porcelain.sh b/t/t7502-commit-porcelain.sh index ca4a740da0..f035e4a507 100755 --- a/t/t7502-commit-porcelain.sh +++ b/t/t7502-commit-porcelain.sh @@ -16,7 +16,9 @@ commit_msg_is () { # Arguments: [] [] check_summary_oneline() { test_tick && - git commit ${3+"$3"} -m "$2" | head -1 > act && + git commit ${3+"$3"} -m "$2" >act && + head -1 tmp && + mv tmp act && # branch name SUMMARY_PREFIX="$(git name-rev --name-only HEAD)" && @@ -68,7 +70,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,8 +144,8 @@ 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/>.*/>/") && + actual=$(git cat-file commit HEAD >tmp && sed -ne "s/Signed-off-by: //p" tmp && sed -e "s/>.*/>/" 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" negative && git add negative && - git status -v | sed -ne "/^diff --git /p" >actual && + git status -v >actual && + sed -ne "/^diff --git /p" tmp && + mv tmp actual && echo "diff --git a/negative b/negative" >expect && test_cmp expect actual @@ -189,7 +193,9 @@ 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 >actual && + sed -e "1,/^\$/d" tmp && + mv tmp actual && test_cmp expect actual ' @@ -198,7 +204,9 @@ 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 >actual && + sed -e "1,/^\$/d" tmp && + mv tmp actual && test_cmp expect actual ' @@ -207,7 +215,9 @@ 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 >actual && + sed -e "1,/^\$/d" tmp && + mv tmp actual && test_cmp expect actual ' @@ -215,10 +225,12 @@ 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 >actual && + sed -e "1,/^\$/d" tmp && + mv tmp actual && test_cmp expect actual ' @@ -226,48 +238,54 @@ 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 >actual && + sed -e "1,/^\$/d" tmp && + mv tmp 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 >actual && + sed -e "1,/^\$/d" tmp && + mv tmp 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 >actual && + sed -e "1,/^\$/d" tmp && + mv tmp actual && test_cmp expect actual ' @@ -275,7 +293,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 +405,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 +473,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 +489,9 @@ 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 >actual && + sed -n -e "s/^parent //p" -e "/^$/q" tmp && + mv tmp actual && test_cmp expect actual ' @@ -480,7 +500,9 @@ 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 >actual && + sed -e "1,/^$/d" tmp && + mv tmp actual && test_line_count = 3 actual ' From patchwork Sun Mar 17 10:16: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: 10856269 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 B80C913B5 for ; Sun, 17 Mar 2019 10:16:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9FEB129736 for ; Sun, 17 Mar 2019 10:16:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9451E29741; Sun, 17 Mar 2019 10:16:10 +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 22F6429736 for ; Sun, 17 Mar 2019 10:16:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727112AbfCQKQJ (ORCPT ); Sun, 17 Mar 2019 06:16:09 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:32911 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725903AbfCQKQI (ORCPT ); Sun, 17 Mar 2019 06:16:08 -0400 Received: by mail-pg1-f193.google.com with SMTP id i7so6170856pgq.0 for ; Sun, 17 Mar 2019 03:16: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=/pZ5ie1Vyj6gsKDYqQSrhAjKAYhZ8TNUnN1cZxLKcwI=; b=rCJcdkM2F38TPP51OfsPQBRwa89c1J9TgB+rjZjXYE+ogzzxnoiCVbmFpOSkB1u8PR r+GX740ek/D5OtvMk8BUnrjSsFRnLpLyRFRx4vRP4472Fsktu0spQXn/VgIeSQZAz4I+ K6V9sNwFv3rhZ+kzkRjQ7latoBS9Yptob2Sh7q9a0XW1+6sYRtTUZZE6eAd3H1Druzlf y1rF/WKKGrZaHtmNUdHc3YGCdOeO4eiibYw9kgr2v7+REye1iQoTHMm9qT+8EgUCeF6K 9MKXE9z8wMFdDIDMYTXa6Ffz6KsBfBxTj64SS6hgxMY+lo5Rcu8proEKQYxFtQM0xSMk sYww== 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=JJNcK7jZ88HNaJbuYTmlbTCQd7MbN+igGJ6bnNmBqxnAOwqfWF8zvpkWGri8cW6Hdo SF3C13QVONaq6etniVo6FUNA+ME4O40GS2Jxsx5HhgeaTWJ93f68TMWskD5dt+UCAFwQ LI60LHJksZg7pkmpn3ycjqFB20hoh6CuTkxVTuzMSqkoy1DPO8dxje3b+KMYr8gEd7tY O2hNi1E5+B6ib+iXOuXBMebKg9BlkAGMY7pm4iwbtpFvpHJhR7J0apHq5ldvfyIhSRYF E45SuHzVF5Ybm1Y3ooAtLLbyVKnt/qVt0yr3uuzsdVSKx0OR2fATqZEgrYMMhcJgliqG t/ow== X-Gm-Message-State: APjAAAWcjXcbDGmrrCKirKZ2JS5mKPMRC3cz2ZDcsRvylfNVCsLqDThL gPQgrS30JyYENVmGE8b1o6N23VwV X-Google-Smtp-Source: APXvYqy0w/B74LnvBXwrn4KFNNzB0j7I1MTdYBfZkyBOI28o0Ew/FXx5EUrPzKUH8i3WlygFA0W3Zg== X-Received: by 2002:a63:7c07:: with SMTP id x7mr12516431pgc.284.1552817767603; Sun, 17 Mar 2019 03:16:07 -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 m24sm8399933pgv.1.2019.03.17.03.16.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 17 Mar 2019 03:16:06 -0700 (PDT) Date: Sun, 17 Mar 2019 03:16: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 v8 05/11] commit: extract cleanup_mode functions to sequencer 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 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 Sun Mar 17 10:16:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10856271 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 0679815AC for ; Sun, 17 Mar 2019 10:16:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E388829736 for ; Sun, 17 Mar 2019 10:16:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D7B1C29741; Sun, 17 Mar 2019 10:16:13 +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 1A58429736 for ; Sun, 17 Mar 2019 10:16:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727131AbfCQKQM (ORCPT ); Sun, 17 Mar 2019 06:16:12 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:44660 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727118AbfCQKQL (ORCPT ); Sun, 17 Mar 2019 06:16:11 -0400 Received: by mail-pg1-f194.google.com with SMTP id h34so9358095pgh.11 for ; Sun, 17 Mar 2019 03:16:10 -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=iNzkGkT+roTqVyjABIFfCxN2Rh4mqNWYVsTljIoMvuu2fkerPFMY8Uj47SbkUkx996 nJ21dbvGsB0l0EPoWp8+ViqM+ywa+bR8AF800Sc0lVhUPgQk3T4UmDWiTcfI2mOBorKX /9sWpiQsDxMd4WFXb53aDRYZlzXu3kqwYBNe6E1uXPLtqClSLJLAhuXpvU5DXMpEyMFG lrynZ7K7rL2uzbu30a62hi55KfeTJI/RmhRoYvUNnQE2kSh+NJH29Cv8NC+sFLBO6sPR LrS3gjHyTdIBQ2lTuWk98T+6w1KqJ85KIRP4tmcs2znC0dPLRxrcv7lZYSnHm4P/zDGn VDOg== 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=B9RGYRCLwN589hUIZ1xIfw7EcCrBbIvqRYVhqF+ElkL6lB/OjSkIHAVZMhpNb0R83G njLAkhcbm+QpF0DFjRxWCzMMlcxeFGzAphO3pBjGo6dC41bnUAy6bo94bZnvLOsyWhsV BsbrWyB5BtmG5XU2tRLj/0fLKwhXIUPCGDTTGklnVaxEHtEytFTjSjwc4g0UHp3AaIq4 Xmx0gU10444UBqt5Uy34ApzbGs/V7O+hWStWk2A7CK1j05z0gcUvH6ab+n4aNUwy5Um8 9Bt0aWX7a33FDpcXbZOTb+uR3dvQyUYlQFjgG155d4WqyMeVi41I+M/5A4E03QQ0PsYk G6xg== X-Gm-Message-State: APjAAAVEvSouHEEJbjHMobEiXf77JDxzYNvl9R/x8clGr4eWgpyzyFI1 fo/GwY2/m8Q1t7RCzcQmcN832/5L X-Google-Smtp-Source: APXvYqzh7d+YvzjR4jYXsajNsGSJZyTeMIj87K2CR0UFKZ4ffhpZSxKOgfQZbTsCuz4ZI/u79a/MGQ== X-Received: by 2002:aa7:8d17:: with SMTP id j23mr10279103pfe.62.1552817770403; Sun, 17 Mar 2019 03:16:10 -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 o7sm16967952pfi.105.2019.03.17.03.16.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 17 Mar 2019 03:16:09 -0700 (PDT) Date: Sun, 17 Mar 2019 03:16:07 -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 v8 06/11] parse-options.h: extract common --cleanup option Message-ID: <19cdc7528c155cd887299a7c24b3bd5ce05a67a6.1552817044.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 Sun Mar 17 10:16:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10856273 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 ABD3115AC for ; Sun, 17 Mar 2019 10:16:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94AE229736 for ; Sun, 17 Mar 2019 10:16:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 88BCE29741; Sun, 17 Mar 2019 10:16:16 +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 194C129736 for ; Sun, 17 Mar 2019 10:16:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727148AbfCQKQP (ORCPT ); Sun, 17 Mar 2019 06:16:15 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:43635 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725903AbfCQKQO (ORCPT ); Sun, 17 Mar 2019 06:16:14 -0400 Received: by mail-pf1-f194.google.com with SMTP id c8so2628044pfd.10 for ; Sun, 17 Mar 2019 03:16:14 -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=/hOMBbmx3PDgGx7271Y1+Yx9WvP5sR1bSossW4Q0tac=; b=dfZ2wamlbeEbH+sCLs6OGQHeQWHdiizq+QF454XWR2OB2+LhLiHqPTQb+gp7Ayy1Wz CClrv0m8bWpAbEMAgpufJB3XVYuYOQIbXZp/hq0TAw547//L1hmX3AYRgvXVeFNeFioO RqfBHy/JodwcwIClqmSZT8gtUW73pYj4Sj9cBuxqc58cqpzOIXvMEryjOWlKq2yHdsN/ JGYX5OQG/6GPzaKXk7RghgsA1x50bMEAATLsQVeMlIYR9LFaYqHs1KUsXTHjEZHqZzHf RR1Cu1cRtC1PhpBXf1oz6Igo6LGyX9wDqbe9Z0cn/6n7y5PDCyUtfz0sB/KdyiH0EyXS n2Nw== 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=/hOMBbmx3PDgGx7271Y1+Yx9WvP5sR1bSossW4Q0tac=; b=KVpq19q33x8qYrXatmFmT4VyGxcQYulzJaKfJrG3SZRfYXacxDV/31Gsv3WADbTgjC kK/cnWdfnjPMBUFpBYEyh7v3JRIyCgXigzUSq9esiMjJAcvH72L/7IolAqOO6B1vx+wm bCDU30pJAYlgAblGUbG08+3fEw2SY1mJ0vzMaIO4auC/BoE/dfXrFrjz6r/MAlfDSUm1 BZsQxvLO4KZgHUNJugt97wAWFuqhhDZZLT/KWFjiaWkwNlJgUW9b1p8u6CXMiPZTuvlZ pYSCZhX0b8RvtcGjl9akiCuNjO8jtoSGXO9ETjq8MxeDyLlRxiUMBK/v344+CbZ3ChYN XdXg== X-Gm-Message-State: APjAAAX+Dm8J+uHJKjtPYzO94oePiUqtajtGtWNfJbRAqUC9gfLzXVtF MIEF6ZMF1VencW1rBYw0ORYabdBp X-Google-Smtp-Source: APXvYqyv/BfMI1PJ0IOBvEHNzC08slaNya0+mGct1zlOg94THd8HcmKMCXRSpmd7+mrAUpu8gtJGHA== X-Received: by 2002:a17:902:e50b:: with SMTP id ck11mr14224803plb.25.1552817773244; Sun, 17 Mar 2019 03:16:13 -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 p7sm5131375pgs.42.2019.03.17.03.16.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 17 Mar 2019 03:16:12 -0700 (PDT) Date: Sun, 17 Mar 2019 03:16:10 -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 v8 07/11] sequencer.c: remove duplicate code Message-ID: <5cab2c3ed2085b7c706682d3d9878b6bf807d2f7.1552817044.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. Reviewed-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 Sun Mar 17 10:16:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10856275 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 8A3E613B5 for ; Sun, 17 Mar 2019 10:16:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6F4BA29736 for ; Sun, 17 Mar 2019 10:16:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 636B429741; Sun, 17 Mar 2019 10:16:20 +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 88BE029736 for ; Sun, 17 Mar 2019 10:16:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727179AbfCQKQS (ORCPT ); Sun, 17 Mar 2019 06:16:18 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:41828 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725903AbfCQKQS (ORCPT ); Sun, 17 Mar 2019 06:16:18 -0400 Received: by mail-pf1-f194.google.com with SMTP id d25so9272086pfn.8 for ; Sun, 17 Mar 2019 03:16:16 -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=IBCqF6Q/iMedYdVaHMT6GdYW3qVB0JBxExzzkRjlGZ8=; b=kvP4hfqqLjU7NecL33SZJTh63aIcC8+fewaMoogw0vegF1p/jZPHSRgzPCOm52f+FO U3PgQ4eaBqYWtzhc4wa3PBhD7BpnIWiOy/XtUtQxG5jaPRtOY6FKysHKCVp1vpz1D3iK LTcTQ80GtbwCMMcLbe9sCB2BHfxHIafW/2MvRqvGULCuJpw3N14kTYE+SFzrSOLRNMC7 HguNdEKFN76PCpb9Jo1wNqiEnvggYZoa/nEFYmJWOtLPrLSn7LsmCcJi9NW1YCMwc80c WwUbiurdFEcoBkfqBegzuiYFxDMtDCgpPnqhEKzviKyvbrUtSw3eUVI3uIH39bTZqCy1 bZ1g== 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=IBCqF6Q/iMedYdVaHMT6GdYW3qVB0JBxExzzkRjlGZ8=; b=QGltTWlxMG8eTXcKUDqNiVZ16RhnBP3BfqWbwn40tT8SYBcpBcyM2PmY+oQEra+wcS 98Ma3QS9LEyEQUCOou/8sOfnduDpnvfTrr04ctTjfQWzbTXxbNh8qkS0OTtFXDxy+UJm ACW+owAkWJy4dswiKfv4wIqdgZG0IL6DFjwPI2pCFy7M8OkfjcZWhvkbOs6vMfo7gvlx PTLgcjhwcvYmylzMGl+I4L9XL1hLFqY00bc2gRjrVdyb87TvCe9H2bQZG86dRtbb467b DNK/jyRU7rGfxRBYG67eNVwbuxuaOHDG06m/taUyyIVmovxXlsuZi0waL3Qd4W+3jUYE efDQ== X-Gm-Message-State: APjAAAWifHsVQxtGTnQ1m6x2w2mZYfEaF0J9g6G4P5lJruUc5teLNtH9 p2OePeDgwFja+jyS42PubJFLdUPN X-Google-Smtp-Source: APXvYqxxzI5v4KR910Hqh/GbrsuKuEJQiv/jxDKXeZ6EUHlXcrHCx4/1HdAspBQmqWTP3LC28dUU6g== X-Received: by 2002:aa7:8459:: with SMTP id r25mr13941216pfn.65.1552817775969; Sun, 17 Mar 2019 03:16:15 -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 i126sm9513648pfb.15.2019.03.17.03.16.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 17 Mar 2019 03:16:15 -0700 (PDT) Date: Sun, 17 Mar 2019 03:16:13 -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 v8 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. Reviewed-by: Phillip Wood Reviewed-by: Eric Sunshine Signed-off-by: Denton Liu --- Phillip Wood wrote: > cleanup needs to take an argument so PARSE_OPT_NOARG does not look > right. Also I think it would be bettor from the user's point of view if > the value of the argument was checked by pull before it does any work > rather otherwise if they pass in invalid value pull mostly runs and then > merge errors out at the end. I opted not to do a check on the validity of the value of the --cleanup-mode argument because the strategy options that existed before also didn't verify the validity of their values. In the future, it might be a good idea to check the values of both cleanup-mode and the strategy options but for now, I think we can leave it as it is. Documentation/merge-options.txt | 5 +++ builtin/merge.c | 31 +++++++++++---- builtin/pull.c | 6 +++ t/t7604-merge-custom-message.sh | 67 +++++++++++++++++++++++++++++++++ wt-status.c | 12 ++++-- wt-status.h | 1 + 6 files changed, 112 insertions(+), 10 deletions(-) diff --git a/Documentation/merge-options.txt b/Documentation/merge-options.txt index 92a7d936c1..646100ea9a 100644 --- a/Documentation/merge-options.txt +++ b/Documentation/merge-options.txt @@ -32,6 +32,11 @@ 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 or being passed on. 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..7be03a2610 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")) { @@ -797,23 +804,32 @@ static void abort_commit(struct commit_list *remoteheads, const char *err_msg) exit(1); } +static const char comment_line_explanation[] = +N_("Lines starting with '%c' will be ignored.\n"); + 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" - "the commit.\n"); + "An empty message aborts the commit.\n"); static void write_merge_heads(struct commit_list *); 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); + else + strbuf_commented_addf(&msg, _(comment_line_explanation), comment_line_char); + + strbuf_commented_addf(&msg, "\n"); + strbuf_commented_addf(&msg, _(merge_editor_comment)); + } if (signoff) append_signoff(&msg, ignore_non_trailer(msg.buf, msg.len), 0); write_merge_heads(remoteheads); @@ -832,7 +848,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 +896,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 +1404,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..292c1dac27 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -101,6 +101,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 +169,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 +648,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) diff --git a/t/t7604-merge-custom-message.sh b/t/t7604-merge-custom-message.sh index b045fdb413..c9685a318d 100755 --- a/t/t7604-merge-custom-message.sh +++ b/t/t7604-merge-custom-message.sh @@ -51,4 +51,71 @@ 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 >actual && + sed -e "1,/^$/d" tmp && + mv tmp 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 >actual && + sed -e "1,/^$/d" tmp && + mv tmp 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 >actual && + sed -e "1,/^$/d" tmp && + mv tmp 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 >actual && + sed -e "1,/^$/d" tmp && + mv tmp 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 Sun Mar 17 10:16:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10856277 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 2D7B515AC for ; Sun, 17 Mar 2019 10:16:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 130C629736 for ; Sun, 17 Mar 2019 10:16:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 06F3229741; Sun, 17 Mar 2019 10:16:23 +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 D0CAC29736 for ; Sun, 17 Mar 2019 10:16:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727191AbfCQKQU (ORCPT ); Sun, 17 Mar 2019 06:16:20 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:44668 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725903AbfCQKQU (ORCPT ); Sun, 17 Mar 2019 06:16:20 -0400 Received: by mail-pg1-f195.google.com with SMTP id h34so9358172pgh.11 for ; Sun, 17 Mar 2019 03:16:19 -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=GLtY6EmDCMryhIHsfvN21TmjnWd9kCvzjjd3s0iV1gQ=; b=muF82Vm6MoCabJJwksEc74effQHYqMSNLSqJDTnNW/ip61A7Hb+X/9J5ni7JO/zmBI SqC2o4NpyN1dSXeDGM21li9ONlBUDyd55USp7IjW7tEAVM6kHy3azs4rO2CWWQssKto/ UCtMc9SHAkwpzodP2dlo/7ng1Yslwuyero5gSobvwaUkOIUqJ5RSOr5lXbIClpiEu/uA R0i/d7xzIfY4w9Wg2t1QWRpfbdjEArE/hwKo6GpaSclzBwJKA68xS6lW5nvbdrJ4Wlh8 jwKxdyDzouvxwAjudQq3Eu3I8oV4sIONoX28Vr27euZj2JaqSJVXI7flub58hy8F+6Y7 KtOQ== 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=GLtY6EmDCMryhIHsfvN21TmjnWd9kCvzjjd3s0iV1gQ=; b=ic3HsiVyFwJHKsp3OXHsqPzbgzYudJp0LwR2f9LySN79OKPhDFslgmTAimu9u2yV2J Gk3Ou1GWJ8n/B5A/BZyUaNGu0eXZO+S7vpc/ueERsfNZCplm7lOiie0671HW6xEH+s9L 3THLhcpZTip+Al7k2B3HaW9WD4zu8TCutcMYNdd+8DVU51Cb+tU7fo9l9QBMAJ1rfie7 gtvSfvGcvPSWjD+Bi9ZOSdFjvGPdbOiRIJE5vlClVRha5ScNZOKfDlyC0kQtTpto8swK VnqMNUxWPUhLddVcfvso15aipHoTeLU+vFHmIn0OPo2Z9+g6XMK5pdoc0qOdmbJZ/Sdb Tg2A== X-Gm-Message-State: APjAAAUHch0nMD2osZ8TKhCT4m9Ajtu6sjBGjoL9kDGhPr0c1/7ReUWm gGm5zDNj7pgc4WDs4ytRsKsn6Xbl X-Google-Smtp-Source: APXvYqwQDwuk+m/jd+tkBKvLUcoGH7BZEbzTwBUmuqsZLRkftH5YyfXILvswx04uoFRl0mYtQCT3IA== X-Received: by 2002:a62:1ac3:: with SMTP id a186mr13526069pfa.48.1552817778894; Sun, 17 Mar 2019 03:16:18 -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 j6sm7013685pgq.72.2019.03.17.03.16.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 17 Mar 2019 03:16:18 -0700 (PDT) Date: Sun, 17 Mar 2019 03:16:16 -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 v8 09/11] merge: add scissors line on merge conflict Message-ID: <41e399af28495e0fdec87992526daf23bafef272.1552817044.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 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. Reviewed-by: Eric Sunshine Signed-off-by: Denton Liu --- Documentation/merge-options.txt | 4 ++- builtin/commit.c | 20 ++++++++++---- builtin/merge.c | 14 ++++++++++ t/t7600-merge.sh | 48 +++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 6 deletions(-) diff --git a/Documentation/merge-options.txt b/Documentation/merge-options.txt index 646100ea9a..405e16c617 100644 --- a/Documentation/merge-options.txt +++ b/Documentation/merge-options.txt @@ -35,7 +35,9 @@ set to `no` at the beginning of them. --cleanup=:: This option determines how the merge message will be cleaned up before commiting or being passed on. See linkgit:git-commit[1] for more - details. + 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 7be03a2610..86c54bff76 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -916,6 +916,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 a9620cd991..ed11b08db2 100755 --- a/t/t7600-merge.sh +++ b/t/t7600-merge.sh @@ -247,6 +247,54 @@ 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 >actual && + sed -e '1,/^$/d' tmp && + mv tmp 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 >actual && + sed -e '1,/^$/d' tmp && + mv tmp actual && + test_i18ncmp expect actual +' + test_debug 'git log --graph --decorate --oneline --all' test_expect_success 'merge c1 with c2 and c3' ' From patchwork Sun Mar 17 10:16:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10856279 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 3B24D13B5 for ; Sun, 17 Mar 2019 10:16:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2327D29736 for ; Sun, 17 Mar 2019 10:16:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 174D429741; Sun, 17 Mar 2019 10:16:25 +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 64F5B29736 for ; Sun, 17 Mar 2019 10:16:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727206AbfCQKQX (ORCPT ); Sun, 17 Mar 2019 06:16:23 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:45533 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727194AbfCQKQX (ORCPT ); Sun, 17 Mar 2019 06:16:23 -0400 Received: by mail-pg1-f195.google.com with SMTP id y3so151210pgk.12 for ; Sun, 17 Mar 2019 03:16:22 -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=epOOx5qmhX9XAzSIHFLPF2H7cgbOFAXzQxVq89PKzho=; b=nBpIT/AtfmwMfiidYThurTnsm1jIpVK0mpGPs7pdCPY9ptzuw0QALppZE1E2Cu90bd uIPWMmYKHfP/lSlOLHfj+srUup/YCGBa5jOji06qD8wacLNa4Yn1BcxkatOG7sDsrPQL 66P1s5K7VIL6LVfFlaFR09FE+fOndy/6ILp5cnk1SW8lZdu4KeKQrGnqMCknm8ulgGUh wUz4grx3KYgDw8EIF/XiU9ZNeMuFsY8QFP301KlBaSdz+8gNCHq5OoU/Lg018PERa99N KdZsNDRnJikQMUcPVLAaGN82Bx57XX7/IteaASwI4bvYkvLv1VvkeQgYBUmjmHwZt/zK pOqg== 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=epOOx5qmhX9XAzSIHFLPF2H7cgbOFAXzQxVq89PKzho=; b=bu/QgLbCQMeDpfY0fnkv4gWo/B/kOzr3Iw2nPlj32Nt4Q57iqYgWYBQCjS4FR3VJMN SRFcBtDdwwH6aripUEfAv8n81iVvd0/g9MYQZaZdgGlRggH/uEQdWehkDyggWhaHORIy uLFnNAsOvdG1/n8DkUowZvAHN63rxEYWRduObrC30bIN0YWcc6FK4g2r/306cIbDntwS JMlflJW6pptRsMHDWIIIKiLlKEHcXzZordSqeHdMeVR6NgbETL44IBwAtouWAwPPQ7XV k+9+5Mr4NDXiVFo7DH3mmPB1+0/9/a6E7L5xdibad6xCyldQmE2wiSdkrl2pytpjNU29 hQCA== X-Gm-Message-State: APjAAAUlDQwpYtLUhRovpKTnoFrYgfmSo0YDCRwq6vDK+0kkJWCWFn2A myhuUWKt4kBb9XN5ADHbBvy1Dbz4 X-Google-Smtp-Source: APXvYqxDoQt4rCKuAi1rbEX8eNpV/RKOnhzsVYalHol6VCwxbjNzgfwy5W/8UXReeCal16v8sqzS9w== X-Received: by 2002:a17:902:834b:: with SMTP id z11mr14009128pln.257.1552817781784; Sun, 17 Mar 2019 03:16:21 -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 r10sm1964302pfn.188.2019.03.17.03.16.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 17 Mar 2019 03:16:21 -0700 (PDT) Date: Sun, 17 Mar 2019 03:16:19 -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 v8 10/11] sequencer.c: define describe_cleanup_mode Message-ID: <4edca9db0b2a32621a7622b5b709db23b2512d1e.1552817044.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. Reviewed-by: Eric Sunshine Reviewed-by: Junio C Hamano Signed-off-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 Sun Mar 17 10:16:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10856281 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 B2EF213B5 for ; Sun, 17 Mar 2019 10:16:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 989B029736 for ; Sun, 17 Mar 2019 10:16:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8CFAC29741; Sun, 17 Mar 2019 10:16:28 +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 537F929736 for ; Sun, 17 Mar 2019 10:16:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727209AbfCQKQ0 (ORCPT ); Sun, 17 Mar 2019 06:16:26 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:39226 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725903AbfCQKQZ (ORCPT ); Sun, 17 Mar 2019 06:16:25 -0400 Received: by mail-pg1-f196.google.com with SMTP id h8so9378486pgp.6 for ; Sun, 17 Mar 2019 03:16:25 -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=ZvE3+AT/DQ+rm/lXQfcHvzumCAVmsD/G0VJ0M2pzT54=; b=P1KtsQ/Crb/uUxuHgjpgWoyQutAk5EWGF+gvifqlpZmBu72XPZKeJKs6C3FHtDBkmM HBcReBI1oI7jrH+k6HxKv28QY4RLoXAnJ8RmlrN+uHuEQeg7atzUvST7gDBhxAl5Bi1h GdorV+0FLAngXBK2iDXYfonywlw/3sbdTXxuS2YnM+TKD3FrGDZPEcYceZhZ46ofN988 9vxZwOagjAfP/njMnoXNtAX+lyAjr1Zjy207NxZwYoQ3eKPp7/BVH0V6dPMGqnd97OGF TuILzFs4c6m3qmtYBkLUCJ8Mmd6TPLa4pd5w7Qh5wnh2nOmlgnQsWQ6m0anIiBAIP0jE /uQA== 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=ZvE3+AT/DQ+rm/lXQfcHvzumCAVmsD/G0VJ0M2pzT54=; b=TuD9ajtZooTcMbEo6IpDOXfGGhR2dIerL+MlsC6g3hLx8cN7fFa8IJyfVcG1/9DPv/ Pb0D2t2/GpnCNLlkPFjxamrhkySHWo6L3pbUiP1ESbKCOitUP8MLUJcoz6Rqt3ChFIUt a3TkDlKgerJ3KJHn5j1kthIu0+QtlyW9jeUiBVcJtjPSil1POSm6dIUwzc79csmIXc+x u77Lt+G+T3YTRAc9VJT0v1+WT4SLG/ZI7z6ntIiDR9xMxBdJmIcpbmpymOeVjHrIPSmZ mtzZyGWh6/HOJaPXHBAwpYBZZ/20qcfbouNI7tLNNw49Dr5ovU7p6VHy0wYdlU/YxCUE /2RQ== X-Gm-Message-State: APjAAAXTjN3pqW7Xr41fP19yqFvt4LsZQgRsrVfcS9gHnH2TpyUiIhJm rBYRP7wn8GmR0veAlshdtpmzfFX2 X-Google-Smtp-Source: APXvYqzcutvlf/CRK4XVO5CyZOyHEPAUjCCxf1XSyXOLtTYm449qjfsVjeVDixbXJ2xi2EdDKwfRdw== X-Received: by 2002:a65:514a:: with SMTP id g10mr12471464pgq.400.1552817784575; Sun, 17 Mar 2019 03:16:24 -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 j14sm10005576pfn.77.2019.03.17.03.16.23 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 17 Mar 2019 03:16:23 -0700 (PDT) Date: Sun, 17 Mar 2019 03:16:22 -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 v8 11/11] cherry-pick/revert: add scissors line on merge conflict Message-ID: <5685ff80b582ab1d6daf4f2d0fcb93344b9069f5.1552817044.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 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. Reviewed-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..2601e1868e 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. 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 to the commit + machinery 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..cabeb9df2c 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. 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 to the commit + machinery 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 86c54bff76..90c64346e9 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -923,14 +923,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 74ff925526..c3894ca9d6 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 &&