From patchwork Thu Feb 7 06:32: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: 10800423 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 1AB3A13B4 for ; Thu, 7 Feb 2019 06:33:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 077A22BF49 for ; Thu, 7 Feb 2019 06:33:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EB3062D120; Thu, 7 Feb 2019 06:33: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 81CA62BF49 for ; Thu, 7 Feb 2019 06:33:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726900AbfBGGdB (ORCPT ); Thu, 7 Feb 2019 01:33:01 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:43274 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726758AbfBGGdA (ORCPT ); Thu, 7 Feb 2019 01:33:00 -0500 Received: by mail-pl1-f195.google.com with SMTP id gn14so4331773plb.10 for ; Wed, 06 Feb 2019 22:32:59 -0800 (PST) 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=U7FgL/y2qmXuw5zzWD7t3Y6oBH9U6y8z7ZMPEBV9Tls=; b=alsrd1vf2FoEks9xpQ4DCZ6o6MIU1KWtEw5PcQDwL9htTJ1EntghthWH5YzwC+m+RG SZvUxHNpgQ/EX6hsaJlMIjGx2XMRlc5LpQAy86lhKg9uldwNn5hBF0aT53k+CJENlo3P RZNEQ/likD5/r78q9l+umdzqddM5kGvUxCAzL+U6bEAuvt3zjvWXnAzpDlxjkVC6oc21 HqmhaMPFUSY4zixWxNo9HuX2Kc16Cez/QMKBnh7F/dWeA5eA4W4iN5wjFX4nkyZ0Nfm8 mQ/8gPg/jA1AKnXx7GzK25N1rCVvHLJl+6KM3XxFzZap2P3Nd4ZvARn6ZMnKfydbDDR/ pABQ== 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=U7FgL/y2qmXuw5zzWD7t3Y6oBH9U6y8z7ZMPEBV9Tls=; b=Ni889EUQ3MA2HSZ4C0jfMtqpePJssKRKNw4yDpWveSMCjOOLuWCFqzkvDFeMF0Q767 0PLlzqXgSkcNe+rSnCVaXV8XoNHoHJJ9dhtN7LItf3mGrJ9wPmAsFgR1B7mizwG4PuNq gSXlkBSrMSh7Dfu2idEb9KaENlISp7VhdqQCz4dTYgX4qcUMnNcPFF2ZiBTbMAZkkMRd x6U2t+x+3UA2whhfYWFAvtr224eIlsehmtp2yEU96n9cMGV/08JFL8jjPjpXnNYUVzWj 5W68KEvWbifKH29HAFp259mOXLANecBA1W2LamylqI8CADXAXQgZVIDmYbhxaLkZXFbv f5Rw== X-Gm-Message-State: AHQUAubGGHiM0ZXnNnfuYDs5KTD07+B5h8HZsJcHDjEv2pFgox/W2Z2k G0Im3uGkcynnxmTU/+7HbPOoN+Mt X-Google-Smtp-Source: AHgI3IZ1LYlWBsqQIEb5aWSNIOC5D52WvHMrhbNrmegSd+QYdkvQmTqlhsRTeQiAGlBPGrXPfR9pTA== X-Received: by 2002:a17:902:a50a:: with SMTP id s10mr14228174plq.278.1549521179138; Wed, 06 Feb 2019 22:32:59 -0800 (PST) Received: from archbookpro.localdomain (c-73-222-73-77.hsd1.ca.comcast.net. [73.222.73.77]) by smtp.gmail.com with ESMTPSA id h8sm9175700pgv.27.2019.02.06.22.32.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 06 Feb 2019 22:32:58 -0800 (PST) Date: Wed, 6 Feb 2019 22:32:56 -0800 From: Denton Liu To: git@vger.kernel.org Cc: gitster@pobox.com Subject: [PATCH v2 1/3] git-submodule.txt: document default behavior without --branch Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.2 (2019-01-07) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This behavior is mentioned in gitmodules.txt but not in git-submodule.txt so we copy the information over so that it is not missed. Signed-off-by: Denton Liu --- Documentation/git-submodule.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt index ba3c4df550..9951c68744 100644 --- a/Documentation/git-submodule.txt +++ b/Documentation/git-submodule.txt @@ -261,7 +261,8 @@ OPTIONS The name of the branch is recorded as `submodule..branch` in `.gitmodules` for `update --remote`. A special value of `.` is used to indicate that the name of the branch in the submodule should be the - same name as the current branch in the current repository. + same name as the current branch in the current repository. If the + option is not specified, it defaults to 'master'. -f:: --force:: From patchwork Thu Feb 7 06:32: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: 10800427 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 D8F111390 for ; Thu, 7 Feb 2019 06:33:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C70C02BF49 for ; Thu, 7 Feb 2019 06:33:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B85EB2D120; Thu, 7 Feb 2019 06:33:07 +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 3AB8A2BF49 for ; Thu, 7 Feb 2019 06:33:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726914AbfBGGdG (ORCPT ); Thu, 7 Feb 2019 01:33:06 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:37581 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726758AbfBGGdD (ORCPT ); Thu, 7 Feb 2019 01:33:03 -0500 Received: by mail-pf1-f195.google.com with SMTP id y126so4347552pfb.4 for ; Wed, 06 Feb 2019 22:33:02 -0800 (PST) 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=Kf9e4LRyCqZCmqgsE54RptfKjip3VWXLKuzyyiaBXOw=; b=ewObR1s+vO23eL2/HzzsgnODrGnxIWxsoBaZg0zl6WCzAzQNxWMX313uZBWGEstnMb 4773WUPtUcxH0JxQKlCYpHwXVZyThdAHRPWbj7IwmjfMIYyOXpF9aV5NC6tUcfLbQ0kj ysIMXrNnZ9nJSgZDhLKK7ctcc05cyVTyDmbrtNrdrRZu2Ej4Itpf6qFP01UqD2xG/X+I Hl+OXPB1nCeCQgP+7xLk/x19i5ZEIjPNWWYotMAOz/nZqNV6niSPggjs6N5K/g7FsbJp pozFJNrVY7XW1pq43c5F7xjoJ9HBLKDT5qws4+LXKoOjPYwx3z/7QopReobc7YXFkg1d R/Pg== 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=Kf9e4LRyCqZCmqgsE54RptfKjip3VWXLKuzyyiaBXOw=; b=ntpo7WFhUjCFpqFkjrpyBwtR+Dx8jTKiDpfZ39jSSeZlE9JBOElH1pfk4Kog4uGS+A lJ1zwgRnf8BM3btHrVRmvbEOOCSk/xZ6/jD4UIShh2kQdZau7B7fNqHa2XQfgul2TjLh rSbk9tSAcJTp96ljyOpEUse/waajzHFU55imrIWe04CqT4vVcTtkvAhbz7Dk2SxxR9Ua Uu9RTxayJN90UMW2RY2AE/uRReRBWP1gTHqdf+vKByTrHyBL6wbCrXQMjtOMUv967b25 eBGQQYYCrP+/I4D1c7uNh67rf+jEDsXsgI3Kizg18dtnT/j0Bx6r5ZHnapdKvvJmJCbR 8nKw== X-Gm-Message-State: AHQUAuY38NFwgAztJZHMNPYFXMfTbQexl406tU8uKi5WvAuE2WSNiPGI vcFQmSZ9yDB24nfTz/bnvfZa95Jz X-Google-Smtp-Source: AHgI3IZTeM1zpnzDgpBIFV8EKSSsPqS//RKvE/KoDXLlwYgh7gsAMr51Ejo4XFYLZcZl+c/LPKIqhw== X-Received: by 2002:a63:2c8c:: with SMTP id s134mr12162787pgs.269.1549521181898; Wed, 06 Feb 2019 22:33:01 -0800 (PST) Received: from archbookpro.localdomain (c-73-222-73-77.hsd1.ca.comcast.net. [73.222.73.77]) by smtp.gmail.com with ESMTPSA id a13sm8965133pgq.65.2019.02.06.22.33.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 06 Feb 2019 22:33:01 -0800 (PST) Date: Wed, 6 Feb 2019 22:32:59 -0800 From: Denton Liu To: git@vger.kernel.org Cc: gitster@pobox.com Subject: [PATCH v2 2/3] submodule--helper: teach config subcommand --unset Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.2 (2019-01-07) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This teaches submodule--helper config the --unset option, which removes the specified configuration key from the .gitmodule file. Signed-off-by: Denton Liu --- builtin/submodule--helper.c | 18 ++++++++++++------ t/t7411-submodule-config.sh | 9 +++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 0e140f176c..5a4a7b1993 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2147,17 +2147,22 @@ static int check_name(int argc, const char **argv, const char *prefix) static int module_config(int argc, const char **argv, const char *prefix) { enum { - CHECK_WRITEABLE = 1 - } command = 0; + NONE, + CHECK_WRITEABLE, + DO_UNSET + } command = NONE; struct option module_config_options[] = { OPT_CMDMODE(0, "check-writeable", &command, N_("check if it is safe to write to the .gitmodules file"), CHECK_WRITEABLE), + OPT_CMDMODE(0, "unset", &command, + N_("unset the config in the .gitmodules file"), + DO_UNSET), OPT_END() }; const char *const git_submodule_helper_usage[] = { - N_("git submodule--helper config name [value]"), + N_("git submodule--helper config name [--unset] [value]"), N_("git submodule--helper config --check-writeable"), NULL }; @@ -2169,15 +2174,16 @@ static int module_config(int argc, const char **argv, const char *prefix) return is_writing_gitmodules_ok() ? 0 : -1; /* Equivalent to ACTION_GET in builtin/config.c */ - if (argc == 2) + if (argc == 2 && command != DO_UNSET) return print_config_from_gitmodules(the_repository, argv[1]); /* Equivalent to ACTION_SET in builtin/config.c */ - if (argc == 3) { + if (argc == 3 || (argc == 2 && command == DO_UNSET)) { if (!is_writing_gitmodules_ok()) die(_("please make sure that the .gitmodules file is in the working tree")); - return config_set_in_gitmodules_file_gently(argv[1], argv[2]); + const char *value = (argc == 3) ? argv[2] : NULL; + return config_set_in_gitmodules_file_gently(argv[1], value); } usage_with_options(git_submodule_helper_usage, module_config_options); diff --git a/t/t7411-submodule-config.sh b/t/t7411-submodule-config.sh index 89690b7adb..fcc0fb82d8 100755 --- a/t/t7411-submodule-config.sh +++ b/t/t7411-submodule-config.sh @@ -142,6 +142,15 @@ test_expect_success 'reading submodules config from the working tree with "submo ) ' +test_expect_success 'unsetting submodules config from the working tree with "submodule--helper config --unset"' ' + (cd super && + git submodule--helper config --unset submodule.submodule.url && + git submodule--helper config submodule.submodule.url >actual && + test_must_be_empty actual + ) +' + + test_expect_success 'writing submodules config with "submodule--helper config"' ' (cd super && echo "new_url" >expect && From patchwork Thu Feb 7 06:33: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: 10800429 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 D992B13B4 for ; Thu, 7 Feb 2019 06:33:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C646D2BF49 for ; Thu, 7 Feb 2019 06:33:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BAC632D120; Thu, 7 Feb 2019 06:33: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 163322BF49 for ; Thu, 7 Feb 2019 06:33:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726915AbfBGGdG (ORCPT ); Thu, 7 Feb 2019 01:33:06 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:35389 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726905AbfBGGdG (ORCPT ); Thu, 7 Feb 2019 01:33:06 -0500 Received: by mail-pg1-f195.google.com with SMTP id s198so4093290pgs.2 for ; Wed, 06 Feb 2019 22:33:05 -0800 (PST) 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=2vZigOQSAutpt8Vt9YztXEdTmgbs1OwefroYN1/aRT4=; b=md3344Mnt4bNSzderUH+ahWH0Ht4UQbXG4H7Fz510LLXhImYnSs3XnvUrpZa3+biO8 SodDY+ghgF0oTci7nN392FiwCuU1tJdu870Y676v99vPFbCoSpcsH/trqxhI4TmI19xK tz5d0AzMgIx1XQiPt3PJio9uzxGqB0la3S0IrUwO2Kp69Nd8IHBxgigxcANyzHzu3NCd DCqHmynwPgeENsiAhu95R0Baqeyec+WfdVaP+2FK27DBe3+E8TFKNjVvdGG9RZdqLCv1 8jgf189EIUysi+pejkh6HYS2M/zb+qkPB6zZy1K1BUFnPF+GF94Pq9wns4vt98/MGiOw RZtQ== 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=2vZigOQSAutpt8Vt9YztXEdTmgbs1OwefroYN1/aRT4=; b=P/Id+IvHD7F8bbx3DOfM/2gErqOGTPO81KEoy7PXsW7AjLbeFXye7G32LqMrzPKqTm f1C1kNg3PbumRarVvfRIUDU+wUqwmGog74NUa5a4Zxvlfy6zk4yJekYf5Oc+Dhazk6aL XgFVOj9Xri4l1+3fkrc5BWNU7KiofucIczANFfhiv9/1n0Z7TZN5Mp2Cb7I8TU52zNxI m1Dts9+NCiSKjfH3RUjuDXEO788A5pYP2Cf0U4VyH3Nu4+mY0XCHRWtw9uX2KdtQ8NUM oqa6KekCa2hRjKvA/foGSxO4BDbZzQflGp8dOUohMNsr7Mfay+NjROrTA+kpuzHEfOuY k/2A== X-Gm-Message-State: AHQUAub9zbX54EyEo64AaM5upHFO4vq1UY8p3c6HgH2vp3wHQHE191Zo EDwycI6qbTAb8NB5MxbYXFZBB3sY X-Google-Smtp-Source: AHgI3IY9CziSnWw5DjYqYmYl/riuZzBQ7BuoBoD1OsXjy+tu/Hej3BA8Ku7gNCLMqI1pLpaq//7M6w== X-Received: by 2002:a63:7044:: with SMTP id a4mr13161026pgn.359.1549521184587; Wed, 06 Feb 2019 22:33:04 -0800 (PST) Received: from archbookpro.localdomain (c-73-222-73-77.hsd1.ca.comcast.net. [73.222.73.77]) by smtp.gmail.com with ESMTPSA id p81sm674776pfi.45.2019.02.06.22.33.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 06 Feb 2019 22:33:03 -0800 (PST) Date: Wed, 6 Feb 2019 22:33:02 -0800 From: Denton Liu To: git@vger.kernel.org Cc: gitster@pobox.com Subject: [PATCH v2 3/3] submodule: teach set-branch subcommand Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.2 (2019-01-07) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This teaches git-submodule the set-branch subcommand which allows the branch of a submodule to be set through a porcelain command without having to manually manipulate the .gitmodules file. --- Documentation/git-submodule.txt | 7 ++ contrib/completion/git-completion.bash | 5 +- git-submodule.sh | 75 +++++++++++++++++++-- t/t7419-submodule-set-branch.sh | 93 ++++++++++++++++++++++++++ 4 files changed, 175 insertions(+), 5 deletions(-) create mode 100755 t/t7419-submodule-set-branch.sh diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt index 9951c68744..cb838ee556 100644 --- a/Documentation/git-submodule.txt +++ b/Documentation/git-submodule.txt @@ -14,6 +14,7 @@ SYNOPSIS 'git submodule' [--quiet] init [--] [...] 'git submodule' [--quiet] deinit [-f|--force] (--all|[--] ...) 'git submodule' [--quiet] update [] [--] [...] +'git submodule' [--quiet] set-branch [] [--] 'git submodule' [--quiet] summary [] [--] [...] 'git submodule' [--quiet] foreach [--recursive] 'git submodule' [--quiet] sync [--recursive] [--] [...] @@ -168,6 +169,12 @@ submodule with the `--init` option. If `--recursive` is specified, this command will recurse into the registered submodules, and update any nested submodules within. -- +set-branch ((-d|--default)|(-b|--branch )) [--] :: + Sets the default remote tracking branch for the submodule. The + `--branch` option allows the remote branch to be specified. The + `--default` option removes the submodule..branch configuration + key, which causes the tracking branch to default to 'master'. +-- summary [--cached|--files] [(-n|--summary-limit) ] [commit] [--] [...]:: Show commit summary between the given commit (defaults to HEAD) and working tree/index. For a submodule in question, a series of commits diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 499e56f83d..8b3b5a9d34 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -2573,7 +2573,7 @@ _git_submodule () { __git_has_doubledash && return - local subcommands="add status init deinit update summary foreach sync" + local subcommands="add status init deinit update set-branch summary foreach sync" local subcommand="$(__git_find_on_cmdline "$subcommands")" if [ -z "$subcommand" ]; then case "$cur" in @@ -2604,6 +2604,9 @@ _git_submodule () --force --rebase --merge --reference --depth --recursive --jobs " ;; + set-branch,--*) + __gitcomp "--default --branch" + ;; summary,--*) __gitcomp "--cached --files --summary-limit" ;; diff --git a/git-submodule.sh b/git-submodule.sh index 5e608f8bad..43ec756602 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -10,6 +10,7 @@ USAGE="[--quiet] add [-b ] [-f|--force] [--name ] [--reference ...] or: $dashless [--quiet] deinit [-f|--force] (--all| [--] ...) or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--reference ] [--recursive] [--] [...] + or: $dashless [--quiet] set-branch (--default|--branch ) [--] or: $dashless [--quiet] summary [--cached|--files] [--summary-limit ] [commit] [--] [...] or: $dashless [--quiet] foreach [--recursive] or: $dashless [--quiet] sync [--recursive] [--] [...] @@ -684,6 +685,72 @@ cmd_update() } } +# +# Configures a submodule's default branch +# +# $@ = requested path +# +cmd_set_branch() { + unset_branch=false + branch= + + while test $# -ne 0 + do + case "$1" in + -q|--quiet) + # we don't do anything with this but we need to accept it + ;; + -d|--default) + unset_branch=true + ;; + -b|--branch) + case "$2" in '') usage ;; esac + branch=$2 + shift + ;; + --) + shift + break + ;; + -*) + usage + ;; + *) + break + ;; + esac + shift + done + + if test $# -ne 1 + then + usage + fi + + # we can't use `git submodule--helper name` here because internally, it + # hashes the path so a trailing slash could lead to an unintentional no match + name="$(git submodule--helper list "$1" | cut -f2)" + if test -z "$name" + then + exit 1 + fi + + test -n "$branch"; has_branch=$? + test "$unset_branch" = true; has_unset_branch=$? + + if test $((!$has_branch != !$has_unset_branch)) -eq 0 + then + usage + fi + + if test $has_branch -eq 0 + then + git submodule--helper config submodule."$name".branch "$branch" + else + git submodule--helper config --unset submodule."$name".branch + fi +} + # # Show commit summary for submodules in index or working tree # @@ -980,7 +1047,7 @@ cmd_absorbgitdirs() while test $# != 0 && test -z "$command" do case "$1" in - add | foreach | init | deinit | update | status | summary | sync | absorbgitdirs) + add | foreach | init | deinit | update | set-branch | status | summary | sync | absorbgitdirs) command=$1 ;; -q|--quiet) @@ -1021,8 +1088,8 @@ then fi fi -# "-b branch" is accepted only by "add" -if test -n "$branch" && test "$command" != add +# "-b branch" is accepted only by "add" and "set-branch" +if test -n "$branch" && (test "$command" != add || test "$command" != set-branch) then usage fi @@ -1033,4 +1100,4 @@ then usage fi -"cmd_$command" "$@" +"cmd_$(echo $command | sed -e s/-/_/g)" "$@" diff --git a/t/t7419-submodule-set-branch.sh b/t/t7419-submodule-set-branch.sh new file mode 100755 index 0000000000..c4b370ea85 --- /dev/null +++ b/t/t7419-submodule-set-branch.sh @@ -0,0 +1,93 @@ +#!/bin/sh +# +# Copyright (c) 2019 Denton Liu +# + +test_description='Test submodules set-branch subcommand + +This test verifies that the set-branch subcommand of git-submodule is working +as expected. +' + +TEST_NO_CREATE_REPO=1 +. ./test-lib.sh + +test_expect_success 'submodule config cache setup' ' + mkdir submodule && + (cd submodule && + git init && + echo a >a && + git add . && + git commit -ma && + git checkout -b topic && + echo b >a && + git add . && + git commit -mb + ) && + mkdir super && + (cd super && + git init && + git submodule add ../submodule && + git commit -m "add submodule" + ) +' + +test_expect_success 'ensure submodule branch is unset' ' + (cd super && + test_must_fail grep branch .gitmodules + ) +' + +test_expect_success 'test submodule set-branch --branch' ' + (cd super && + git submodule set-branch --branch topic submodule && + grep "branch = topic" .gitmodules && + git submodule update --remote && + cat <<-\EOF >expect && + b + EOF + git -C submodule show -s --pretty=%s >actual && + test_cmp expect actual + ) +' + +test_expect_success 'test submodule set-branch --default' ' + (cd super && + git submodule set-branch --default submodule && + test_must_fail grep branch .gitmodules && + git submodule update --remote && + cat <<-\EOF >expect && + a + EOF + git -C submodule show -s --pretty=%s >actual && + test_cmp expect actual + ) +' + +test_expect_success 'test submodule set-branch -b' ' + (cd super && + git submodule set-branch -b topic submodule && + grep "branch = topic" .gitmodules && + git submodule update --remote && + cat <<-\EOF >expect && + b + EOF + git -C submodule show -s --pretty=%s >actual && + test_cmp expect actual + ) +' + +test_expect_success 'test submodule set-branch -d' ' + (cd super && + git submodule set-branch -d submodule && + test_must_fail grep branch .gitmodules && + git submodule update --remote && + cat <<-\EOF >expect && + a + EOF + git -C submodule show -s --pretty=%s >actual && + test_cmp expect actual + ) +' + +test_done