From patchwork Thu Dec 20 21:48:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Orgad Shaneh X-Patchwork-Id: 10739629 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 0FBB4924 for ; Thu, 20 Dec 2018 21:48:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F2EDD28BAB for ; Thu, 20 Dec 2018 21:48:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E6F6C28C19; Thu, 20 Dec 2018 21:48:37 +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 9C4BD28BAB for ; Thu, 20 Dec 2018 21:48:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390035AbeLTVsg (ORCPT ); Thu, 20 Dec 2018 16:48:36 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:46188 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730700AbeLTVsf (ORCPT ); Thu, 20 Dec 2018 16:48:35 -0500 Received: by mail-wr1-f68.google.com with SMTP id l9so3238385wrt.13 for ; Thu, 20 Dec 2018 13:48:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=WfLzGBXzVFWCX+D00aTNf+mPu3wJyzdKZS5tiU/zKXY=; b=RiHEe4SJFpVccGw/zyaj4TAqtexbjB8gK7Fb8uLtNn4NyuCMcTf18w6zDS+Co94p4A IjYI7ied150ikEjqnZFH2RjG3BXCiEBoFm2zSEz8mHLQ5St8/mq4l6p42d2vXPJBMZRN NNb+L5L5A0NqmS8OEDy7l+SRduk8Cc+SHiBE8hl9TppjhvgXWUl9FuevxOMmpW0jUIyF 3Kpw58KHYP/t7Lx1aEe+uWJsgaxcUqlv368TjlxMtmbJjb50vDXu3iPFV/8ANcHfkO8H TyQy5/QWBVgFaNfTi0Jwu1+yhKNuuMWKDqU1L6PY4G2BTd87Wj6ScrFQ8q3GifLOXnU8 jSyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=WfLzGBXzVFWCX+D00aTNf+mPu3wJyzdKZS5tiU/zKXY=; b=NaLAn6SobaVcpHpIR/O1JaEVg7ZnCC6Pv10hojHSZyYlEiVoLn9l/t70qgeri/I6pG 78aRV19i4g+s+8pAwv3uYwkJjuObYXKCkwnVOWW7QwlkOzvYLgVw4DPFuNCvYY0sNvs5 crcCsB2oKEXpQB2LX/RrnNEuBSkdjJBe6xdePuv4JgKavfzKn4r7NYnLr8PTzqwAbh/f WRkf7xXiLUtbI6UtyqoGAcmQEBZtVVRdm4nG6Zixh7DpEkD35T2keYp7jTjQBQQf0P7i gvlhXgLdrXIjBWHP+R990d4WZwaBUEe2Gnojz5LFxTjwkG/lWz0yR+g2XkCHuJM/zAaE 7chQ== X-Gm-Message-State: AA+aEWbLPvvn6hoGvZkSXILWMWCT+qha6NsHiP7WpyA8d1ymD399/8/2 1cUAQ8n1LX+zZOfle4m/C9VwsGhg X-Google-Smtp-Source: AFSGD/Ueh32Q7FHX97d2HS+I8LGI+ZbnRK+EyoPchIIlxwcLQl/qjT9+V85PHvTcb6C7Ad4C5oGyag== X-Received: by 2002:a5d:52ca:: with SMTP id r10mr24900262wrv.123.1545342512124; Thu, 20 Dec 2018 13:48:32 -0800 (PST) Received: from localhost.localdomain ([95.86.125.58]) by smtp.gmail.com with ESMTPSA id t5sm8620006wmg.43.2018.12.20.13.48.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Dec 2018 13:48:31 -0800 (PST) From: orgads@gmail.com To: git@vger.kernel.org Cc: Orgad Shaneh Subject: [PATCH 1/2] t5403: Refactor Date: Thu, 20 Dec 2018 23:48:22 +0200 Message-Id: <20181220214823.21378-1-orgads@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Orgad Shaneh * Replace multiple clones and commits by test_commits. * Replace 3 invocations of awk by read. Signed-off-by: Orgad Shaneh --- t/t5403-post-checkout-hook.sh | 55 ++++++++++++----------------------- 1 file changed, 18 insertions(+), 37 deletions(-) diff --git a/t/t5403-post-checkout-hook.sh b/t/t5403-post-checkout-hook.sh index fc898c9eac..7e941537f9 100755 --- a/t/t5403-post-checkout-hook.sh +++ b/t/t5403-post-checkout-hook.sh @@ -7,67 +7,48 @@ test_description='Test the post-checkout hook.' . ./test-lib.sh test_expect_success setup ' - echo Data for commit0. >a && - echo Data for commit0. >b && - git update-index --add a && - git update-index --add b && - tree0=$(git write-tree) && - commit0=$(echo setup | git commit-tree $tree0) && - git update-ref refs/heads/master $commit0 && - git clone ./. clone1 && - git clone ./. clone2 && - GIT_DIR=clone2/.git git branch new2 && - echo Data for commit1. >clone2/b && - GIT_DIR=clone2/.git git add clone2/b && - GIT_DIR=clone2/.git git commit -m new2 + test_commit one && + test_commit two && + test_commit three three && + mv .git/hooks-disabled .git/hooks ' -for clone in 1 2; do - cat >clone${clone}/.git/hooks/post-checkout <<'EOF' +cat >.git/hooks/post-checkout <<'EOF' #!/bin/sh -echo $@ > $GIT_DIR/post-checkout.args +echo $@ > .git/post-checkout.args EOF - chmod u+x clone${clone}/.git/hooks/post-checkout -done +chmod u+x .git/hooks/post-checkout test_expect_success 'post-checkout runs as expected ' ' - GIT_DIR=clone1/.git git checkout master && - test -e clone1/.git/post-checkout.args + git checkout master && + test -e .git/post-checkout.args ' test_expect_success 'post-checkout receives the right arguments with HEAD unchanged ' ' - old=$(awk "{print \$1}" clone1/.git/post-checkout.args) && - new=$(awk "{print \$2}" clone1/.git/post-checkout.args) && - flag=$(awk "{print \$3}" clone1/.git/post-checkout.args) && + read old new flag < .git/post-checkout.args && test $old = $new && test $flag = 1 ' test_expect_success 'post-checkout runs as expected ' ' - GIT_DIR=clone1/.git git checkout master && - test -e clone1/.git/post-checkout.args + git checkout master && + test -e .git/post-checkout.args ' test_expect_success 'post-checkout args are correct with git checkout -b ' ' - GIT_DIR=clone1/.git git checkout -b new1 && - old=$(awk "{print \$1}" clone1/.git/post-checkout.args) && - new=$(awk "{print \$2}" clone1/.git/post-checkout.args) && - flag=$(awk "{print \$3}" clone1/.git/post-checkout.args) && + git checkout -b new1 && + read old new flag < .git/post-checkout.args && test $old = $new && test $flag = 1 ' test_expect_success 'post-checkout receives the right args with HEAD changed ' ' - GIT_DIR=clone2/.git git checkout new2 && - old=$(awk "{print \$1}" clone2/.git/post-checkout.args) && - new=$(awk "{print \$2}" clone2/.git/post-checkout.args) && - flag=$(awk "{print \$3}" clone2/.git/post-checkout.args) && + git checkout two && + read old new flag < .git/post-checkout.args && test $old != $new && test $flag = 1 ' test_expect_success 'post-checkout receives the right args when not switching branches ' ' - GIT_DIR=clone2/.git git checkout master b && - old=$(awk "{print \$1}" clone2/.git/post-checkout.args) && - new=$(awk "{print \$2}" clone2/.git/post-checkout.args) && - flag=$(awk "{print \$3}" clone2/.git/post-checkout.args) && + git checkout master -- three && + read old new flag < .git/post-checkout.args && test $old = $new && test $flag = 0 ' From patchwork Thu Dec 20 21:48:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Orgad Shaneh X-Patchwork-Id: 10739631 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 8CA20924 for ; Thu, 20 Dec 2018 21:48:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7BE2B286AA for ; Thu, 20 Dec 2018 21:48:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6D116289AD; Thu, 20 Dec 2018 21:48:41 +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 112E0286AA for ; Thu, 20 Dec 2018 21:48:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390066AbeLTVsj (ORCPT ); Thu, 20 Dec 2018 16:48:39 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:42703 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730700AbeLTVsi (ORCPT ); Thu, 20 Dec 2018 16:48:38 -0500 Received: by mail-wr1-f67.google.com with SMTP id q18so3251248wrx.9 for ; Thu, 20 Dec 2018 13:48:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Q4ioQTCyq2ttsFLScKLde0K877I98/kYudHo6MKN7AE=; b=MCqDEKl7fib5DlIdorJzVnJiDxdeeYsy9QN2Wv3dYl2ghDTTUnOvG/PE0wNzqi0b5Y g/PjgFtr3Fg5aqeLfyz8Jggh0f2CI09rzde/TIQtpQw+HYGyyI8uPIRgMwRkXwJtvw4T zshJ2chbld7v+I6mG5ardcalP57a7/r2yHA187EyDkA2jDXQsQe4Ey34XekLRUMvA+eR HiaOHCOmTTd4Kb6Qz4ZOmPOzqyR4YzDvvnS/L6VZyfbaBs1mYgI2QRt+G9+mMm3mq9HD Si/KutzVqsi9wlS+77TRuIr82bbaAS5sxaY6n0vgpph3E3yU2gcQ9/SlW0PqPPoT1DKV AqfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Q4ioQTCyq2ttsFLScKLde0K877I98/kYudHo6MKN7AE=; b=U6dZTYm157FHYnsBa2F4CmkjaMSWR7LYScMhP7DvY38k48kXdQg8ixzLbz5tNLHsSF UwpHSsPYRrSwCOx9qiBwU0RSwyMBDGPQTWUwG233SSL0F6Ku2ZD2ZOgnrmSSjRk+hEq3 iLZVic4QVSZyXeXsMVnbZKKT8fmj6BVOiv08LgE8QBBgt+dcYq4oyvtU/g7+tR8o6dq1 kYB3Zb/96soLYl327DgecnYvRXIRwaG5nrE5iM2srwO940vV65V8l7GDm8k88bVvDbGf 5ODC9sx8o+7kRRlpoMey+xe3L4YhCkRcykNO64D+TILq9rbinfFN/kIqopk/CeBUTTcO 8/cA== X-Gm-Message-State: AA+aEWYkeMrg8XA5DU0Z3spnNrnClliGIdpTFb9JYST7CJsYp3hFbXyH oww1nNUH+pJHsYhNnSi7Jsjn2GLr X-Google-Smtp-Source: AFSGD/VNy1yk8nMRxRkPIkrIJlm4bg4zYOyICX0Yha2Dt/+5fUHCOHi1XwGfU+dCoBp0tP63c+UYTQ== X-Received: by 2002:a5d:444a:: with SMTP id x10mr25076420wrr.162.1545342516072; Thu, 20 Dec 2018 13:48:36 -0800 (PST) Received: from localhost.localdomain ([95.86.125.58]) by smtp.gmail.com with ESMTPSA id t5sm8620006wmg.43.2018.12.20.13.48.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Dec 2018 13:48:35 -0800 (PST) From: orgads@gmail.com To: git@vger.kernel.org Cc: Orgad Shaneh Subject: [PATCH 2/2] Rebase: Run post-checkout hook on checkout Date: Thu, 20 Dec 2018 23:48:23 +0200 Message-Id: <20181220214823.21378-2-orgads@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20181220214823.21378-1-orgads@gmail.com> References: <20181220214823.21378-1-orgads@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Orgad Shaneh Signed-off-by: Orgad Shaneh --- builtin/rebase.c | 8 +++++++- t/t5403-post-checkout-hook.sh | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index b5c99ec10c..78a09dcda2 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -530,6 +530,7 @@ static int run_specific_rebase(struct rebase_options *opts) #define RESET_HEAD_DETACH (1<<0) #define RESET_HEAD_HARD (1<<1) +#define RESET_HEAD_RUN_HOOK (1<<2) static int reset_head(struct object_id *oid, const char *action, const char *switch_to_branch, unsigned flags, @@ -537,6 +538,7 @@ static int reset_head(struct object_id *oid, const char *action, { unsigned detach_head = flags & RESET_HEAD_DETACH; unsigned reset_hard = flags & RESET_HEAD_HARD; + unsigned run_hook = flags & RESET_HEAD_RUN_HOOK; struct object_id head_oid; struct tree_desc desc[2] = { { NULL }, { NULL } }; struct lock_file lock = LOCK_INIT; @@ -636,6 +638,10 @@ static int reset_head(struct object_id *oid, const char *action, ret = update_ref(reflog_head, "HEAD", oid, NULL, 0, UPDATE_REFS_MSG_ON_ERR); } + if (run_hook) + run_hook_le(NULL, "post-checkout", + oid_to_hex(orig ? orig : &null_oid), + oid_to_hex(oid), "1", NULL); leave_reset_head: strbuf_release(&msg); @@ -1539,7 +1545,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) strbuf_addf(&msg, "%s: checkout %s", getenv(GIT_REFLOG_ACTION_ENVIRONMENT), options.onto_name); if (reset_head(&options.onto->object.oid, "checkout", NULL, - RESET_HEAD_DETACH, NULL, msg.buf)) + RESET_HEAD_DETACH | RESET_HEAD_RUN_HOOK, NULL, msg.buf)) die(_("Could not detach HEAD")); strbuf_release(&msg); diff --git a/t/t5403-post-checkout-hook.sh b/t/t5403-post-checkout-hook.sh index 7e941537f9..de9c7fb871 100755 --- a/t/t5403-post-checkout-hook.sh +++ b/t/t5403-post-checkout-hook.sh @@ -9,6 +9,8 @@ test_description='Test the post-checkout hook.' test_expect_success setup ' test_commit one && test_commit two && + test_commit rebase-on-me && + git reset --hard HEAD^ && test_commit three three && mv .git/hooks-disabled .git/hooks ' @@ -52,6 +54,22 @@ test_expect_success 'post-checkout receives the right args when not switching br test $old = $new && test $flag = 0 ' +test_expect_success 'post-checkout is triggered on rebase' ' + git checkout -b rebase-test master && + rm -f .git/post-checkout.args && + git rebase rebase-on-me && + read old new flag < .git/post-checkout.args && + test $old != $new && test $flag = 1 +' + +test_expect_success 'post-checkout is triggered on rebase with fast-forward' ' + git checkout -b ff-rebase-test rebase-on-me^ && + rm -f .git/post-checkout.args && + git rebase rebase-on-me && + read old new flag < .git/post-checkout.args && + test $old != $new && test $flag = 1 +' + if test "$(git config --bool core.filemode)" = true; then mkdir -p templates/hooks cat >templates/hooks/post-checkout <<'EOF'