From patchwork Thu Dec 20 21:55:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Orgad Shaneh X-Patchwork-Id: 10739633 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 6D1B01399 for ; Thu, 20 Dec 2018 21:56:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C5CD28A38 for ; Thu, 20 Dec 2018 21:56:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4F72F28B29; Thu, 20 Dec 2018 21:56:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DE78428A38 for ; Thu, 20 Dec 2018 21:56:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390066AbeLTV4K (ORCPT ); Thu, 20 Dec 2018 16:56:10 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:38079 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730700AbeLTV4J (ORCPT ); Thu, 20 Dec 2018 16:56:09 -0500 Received: by mail-wr1-f65.google.com with SMTP id v13so3275304wrw.5 for ; Thu, 20 Dec 2018 13:56:08 -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=E9ez7rg+Ye+gpvhejUVhBtLyVrqnOnUQSo1WvomeTuc=; b=YMg2Hq1IN34kpdHwKSRthLR+FgcJlox9mxRUyViEnBdy8vD1VjrigScw1B1S31f69H LYqcvAhW7SIL6158yDlorKU2nvfbjIOEo6LxJVljWXKH1np/Ftcoq1kKQ0GfT88wkHCE J2/uW+T7utwZ7iQfKyMpYXTcGAzqzq8ThsY/2SQj7o/5OPX4JkdRxtZ3rAiSyaETa4iJ fntoVoyp+u+7J6JvTOEv/tb9D4rNE4TqBFTJ9VQOqq5ZfjjeZNhR4k76vOS1G4dIH9QP EFF6Y9VSdrO0DLl0fCxyvCBDrRXubQs+duETCWRedJ7QhLaSvwq19hCAixK8IL5MccnI VIDQ== 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=E9ez7rg+Ye+gpvhejUVhBtLyVrqnOnUQSo1WvomeTuc=; b=l014Ue8pKR0OZZdDntO5Lako92os//c3H3jTkbEuArdqLdskIGbislnyszxIhgHg9n 3P6l2HZMphBusIB95hscmazMrTUMmkvnoRXftAJr9dBWPL//4cuOR0Wlnjp/LtZsrxZ8 nHqZme6WuiJs/gLBEMfSCk5rqB62fDlFWXFpanDli9d1P9TEp6EB47sIJoDPeSO6Ej5Z gO6977SO+FGc8nEBziogDZMLSfQ6wIgBTz0KuxGgGxEw2iBC4oX6gAxDItV4c+APIE4J FLxnkMdo1YOhwqlsScXX45QJ3QS9G7BlKrFQhnWu4w83G6KeifGlqCiA8s/uFsh73XYm QrYQ== X-Gm-Message-State: AA+aEWYN8lelhtwPbrA4xs8jYq762k8zG4N9D+igRd5GuTQ4nUnP9Vy1 ree337l3A+mKFp/L58K1ybT2vDpy X-Google-Smtp-Source: AFSGD/UmkVnPXtmv6GykiNLIPpWebNpli2jGY9N73D+4sDoyGguGk9frTCaGANAXbw5HT8OdNWqv9w== X-Received: by 2002:a05:6000:120a:: with SMTP id e10mr24400829wrx.85.1545342967410; Thu, 20 Dec 2018 13:56:07 -0800 (PST) Received: from localhost.localdomain ([95.86.125.58]) by smtp.gmail.com with ESMTPSA id b18sm8453017wrr.43.2018.12.20.13.56.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Dec 2018 13:56:06 -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:55:58 +0200 Message-Id: <20181220215559.22454-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..868d6f7272 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:55:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Orgad Shaneh X-Patchwork-Id: 10739635 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 2078F1399 for ; Thu, 20 Dec 2018 21:56:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 10A9D28A38 for ; Thu, 20 Dec 2018 21:56:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 04A8328B29; Thu, 20 Dec 2018 21:56: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 A3AD628A38 for ; Thu, 20 Dec 2018 21:56:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390085AbeLTV4O (ORCPT ); Thu, 20 Dec 2018 16:56:14 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:52952 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730700AbeLTV4N (ORCPT ); Thu, 20 Dec 2018 16:56:13 -0500 Received: by mail-wm1-f65.google.com with SMTP id m1so3543610wml.2 for ; Thu, 20 Dec 2018 13:56:11 -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=TQWQEKydtGuh1E56wh8XKeL4jAB756aJUqFiVDCeEWk=; b=Yxk8+oiEF7EWkOcNHouHZ1f3JmJa7RRtYlsrazg2qvsA/c2wlRGFx1l0TPoSTXs3Bl VAtGLKFBdjYUmIBUQjKEhfC9mWKOYK7Jwfs4iX5pduIKnR8wDBi2qHbcAR70zmHR9u99 XfCj//r2aUQLQkJri0dWzQfrmClVBtb1t3OocUlSm1fRl7n73QFEkByOLxF+V0zxSXBr dSPxIcA6cJnbasbpJlsvljmTU+uBqWEm5XuHmuiQUua5Q+3iF+AIuIwRLXoFpUjStBmO T1YLCScJN9KzCClFWnp5IuqwIppaoX29GEMxmKzxAuFmAGM1oMyTEzKscEclCdFJR3rW B47g== 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=TQWQEKydtGuh1E56wh8XKeL4jAB756aJUqFiVDCeEWk=; b=GcqY3MWRcY9UhfZUxVWfCCTClIsGfJsR8I85mp7wyaKFRVdCREk3YLFu8I122RTd2Z 9dJ0hF1s37MeAiAvUYANLY/9hk9iM0JG7+gUN5e7cQCDzk9J98Y2lQrRvW4PxHou7hnq JzmbcS9+DKEBoKFt25DpBjB3gMI6aarh/nxHrQvkWxeR2v4sb4dueyzNwUYiFTUR6+wX bAMmYziWwGM/AYfTGEhxc1e24uD18PSr9Q6CVB4IOiwB+jMyZZvcRBAl6CSqkSkfe+WP eyYO7c2CVweMnGgKab1TBDL4HRYllkJm86Rhcgcd7TCIn2nVq4NYfnVR2H7wn1btnw/m o+OA== X-Gm-Message-State: AJcUukfCwobcntQ5LRxfkedTL5v46sVsDbDtU6ropV15euH0IC4ujLBi RTAIpTxz1bz70S0y4cHDpmedZLR1 X-Google-Smtp-Source: ALg8bN4Vk7zg/wWIw53gD09ep5FQrXSQnaTI62dIyR6FY10kuYlmW5cF3HDsn1GnWLoG5ZEa+z12XA== X-Received: by 2002:a1c:f916:: with SMTP id x22mr317215wmh.87.1545342970533; Thu, 20 Dec 2018 13:56:10 -0800 (PST) Received: from localhost.localdomain ([95.86.125.58]) by smtp.gmail.com with ESMTPSA id b18sm8453017wrr.43.2018.12.20.13.56.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Dec 2018 13:56:10 -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:55:59 +0200 Message-Id: <20181220215559.22454-2-orgads@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20181220215559.22454-1-orgads@gmail.com> References: <20181220215559.22454-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 868d6f7272..ed4cc6e945 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'