From patchwork Fri Feb 8 11:21:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10802881 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 B1A0613B5 for ; Fri, 8 Feb 2019 11:21:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A123F2D13E for ; Fri, 8 Feb 2019 11:21:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 93DD52D2A4; Fri, 8 Feb 2019 11:21:38 +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 D70C82D144 for ; Fri, 8 Feb 2019 11:21:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727239AbfBHLVc (ORCPT ); Fri, 8 Feb 2019 06:21:32 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:34440 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726068AbfBHLVc (ORCPT ); Fri, 8 Feb 2019 06:21:32 -0500 Received: by mail-pf1-f196.google.com with SMTP id j18so1543438pfe.1 for ; Fri, 08 Feb 2019 03:21:31 -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=DFZENMtGuzmAV7kZTBr2oM8uubuin3VxWAc/z4Tw6UM=; b=qunQmBqK8aXFGIkbLJ2Puz2Smago0Q3bMGZAIcy79rCnGMvgoq+lYrtkS9yW4ySbF9 H1Pa3ZpSYxMdSQx0z4nW8jz4aMfwHh0LZAkJ3+u1IYCKdXEsjKBipSf45MBKFdLJN+Q5 n9cGkEBTJ1PYwbSuDzoXGEnUuU5CkSsNChC5rQ8R454xDVOpzvHnxB+9sEJqd/LQ7AyR s403YNZWJbvK9FA3NDnJ3Y1Iae3+fuFRNgUDKtuPVf3D662Y0fL0zCkfQUr+/mMlIh4Y XT1nmiT1QVI8TAI2aluIy2lwLxH1Nr0Y/CvoP1Ic7fYz6hxrtEIezC8/u+KwAVE/Sa1K 4Eow== 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=DFZENMtGuzmAV7kZTBr2oM8uubuin3VxWAc/z4Tw6UM=; b=VcVoK8vmp79MDB8+RGUlXUr9Dt6lGrTrIS/opytWtoJjS4vRBfjmSZF88W3ntJoZma 1k5IHy8TIlmesu/51tlO6v+94u5ML9EQMc2D8Vi3FKt+DMDyLYeUDq7xx4ArG0nzlqID Hz5HkPXiryXpQy6Xj/hwWLruutIRvmzbQnRZLMtvXlot4JL8GhB9lEOMgFgr7QX+IbPv RCaW0EmxkR072B2BOiLzpMELrLXiIqSTWL2yRgyVBNKGQ52FlJ/1ok098AYH4q7j1ZjS ZRKx9WQEuEGsPko6S+mkce5S3dby+9EyE09GZgrFGfNZU5nn4ui37hfww9ZNPEt6aaBA +xRQ== X-Gm-Message-State: AHQUAuYjXMH+vl2NVzRHzkWtCuaf8GhGF4azXuJURKw8/kY0YHOHfeK1 JGWqiN8k6lnySplqtAil1YEK8Lz3 X-Google-Smtp-Source: AHgI3IbW09UhhkRppk24osVseT+NKnebQKzasLDhkQL8mGZxfI2qGjiHCc69PrmYcgUFGGYfbIr56g== X-Received: by 2002:a62:81c1:: with SMTP id t184mr22210661pfd.40.1549624891372; Fri, 08 Feb 2019 03:21:31 -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 t90sm2586414pfj.23.2019.02.08.03.21.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 08 Feb 2019 03:21:30 -0800 (PST) Date: Fri, 8 Feb 2019 03:21:28 -0800 From: Denton Liu To: git@vger.kernel.org Cc: gitster@pobox.com Subject: [PATCH v4 1/3] git-submodule.txt: "--branch " option defaults to 'master' Message-ID: <2ba8751212b634dd18e16011b1714588e43502e1.1549624679.git.liu.denton@gmail.com> 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. Also, add the missed argument to the -b/--branch option. Signed-off-by: Denton Liu --- Documentation/git-submodule.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt index ba3c4df550..4150148fa3 100644 --- a/Documentation/git-submodule.txt +++ b/Documentation/git-submodule.txt @@ -255,13 +255,14 @@ OPTIONS This option is only valid for the deinit command. Unregister all submodules in the working tree. --b:: ---branch:: +-b :: +--branch :: Branch of repository to add as submodule. 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 Fri Feb 8 11:21:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10802879 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 9520213BF for ; Fri, 8 Feb 2019 11:21:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8424E2D127 for ; Fri, 8 Feb 2019 11:21:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 783F22D1DE; Fri, 8 Feb 2019 11:21: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 08E762D13E for ; Fri, 8 Feb 2019 11:21:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727182AbfBHLVf (ORCPT ); Fri, 8 Feb 2019 06:21:35 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:41381 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726068AbfBHLVf (ORCPT ); Fri, 8 Feb 2019 06:21:35 -0500 Received: by mail-pf1-f196.google.com with SMTP id b7so1527592pfi.8 for ; Fri, 08 Feb 2019 03:21:34 -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=gmPLZydiL8Cx8rABMoM1PM2RP7+7iShM38FR2ZJgZ2g=; b=mk9tGENZxkQRqK3T6MjVW9R/3fHmsexyF9HeFk+U27YzkxQCUEuKDzYdboMOOdsIh0 NGAWUPrte2anJFmCBsCCBT7rkwxQ3p4LH1DSvAZvGLF0WrZiNdCGWj3wEpErL/hsbKGw xrsTKqfWSKvtk/WZzOvnJeMBJcdaR9YmgXnbJNqbldF2uIp3HgBCx2ngl5Kw87LCU3yq yJd1kPp0E7zULVW9ewDsTnZd+3gy2Sob3xDO8gvGKMcca8zIWW9DyhsdloiW4vjFMUyY 5VDQvkd9eEY8EHo6x2XD5eMV1rF5kFcLUPUeJ7S/71QCmFhcOXHOWVuT0OPiBP5/8/eC u9+A== 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=gmPLZydiL8Cx8rABMoM1PM2RP7+7iShM38FR2ZJgZ2g=; b=OqR2dcMsVPvT0guNQFNmxqOvAWyVvAT4zqXZi4arvhSIJbabav+vQpa6M0Iz9oPfgR F/qNpKkSUbQCju3QN2q6N2YoAiCMPvhWHWz4bAZ/9bq/uFS2qHxrzQHme8P/XvJa16sv r4lQDPWGwyABEbKYLHRyKsi7OxM10/XhbivJHJdhBxK4qw679w79MeYqtDmrFXFBq6Ks 9kguwvfBth7qVnsSUYQIRluprgsrD5a4Ox025wbGNXYSPksF8+W+s5N+PqNvMg0JmP6t KPK3LQ3N8AzeFuqQeN3n0yJy3U92SCtDfvtN4e8IyI0T/3uEfExyZXG2+qLZsBGIeD+R dRrg== X-Gm-Message-State: AHQUAua1GVtCTPtJ9huBnychFpeAqnhaHAXT2ZnIQ871r0qVf9mw0uRD Tk1Rlvx+N5jDKnKCHffe5DCmEiYR X-Google-Smtp-Source: AHgI3IbApeD1fzq0YNDSpk5WkB6lbXg57wJ9WsJfYW1YKRDl3dLECUgcwvs3LMkOWXJJasaBJNIt+g== X-Received: by 2002:a63:fc59:: with SMTP id r25mr4734520pgk.302.1549624894039; Fri, 08 Feb 2019 03:21:34 -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 g20sm3231799pfg.85.2019.02.08.03.21.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 08 Feb 2019 03:21:33 -0800 (PST) Date: Fri, 8 Feb 2019 03:21:31 -0800 From: Denton Liu To: git@vger.kernel.org Cc: gitster@pobox.com Subject: [PATCH v4 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 | 17 ++++++++++++----- t/t7411-submodule-config.sh | 9 +++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 0e140f176c..449e56f30c 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 + CHECK_WRITEABLE = 1, + DO_UNSET = 2 } command = 0; 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 []"), + N_("git submodule--helper config --unset "), N_("git submodule--helper config --check-writeable"), NULL }; @@ -2169,15 +2174,17 @@ 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)) { + const char *value = (argc == 3) ? argv[2] : NULL; + 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]); + 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 Fri Feb 8 11:21:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 10802885 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 774DD922 for ; Fri, 8 Feb 2019 11:21:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 641572D13E for ; Fri, 8 Feb 2019 11:21:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 57A242D1DE; Fri, 8 Feb 2019 11:21:43 +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 97D742D13E for ; Fri, 8 Feb 2019 11:21:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727262AbfBHLVi (ORCPT ); Fri, 8 Feb 2019 06:21:38 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:34447 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726068AbfBHLVi (ORCPT ); Fri, 8 Feb 2019 06:21:38 -0500 Received: by mail-pf1-f195.google.com with SMTP id j18so1543537pfe.1 for ; Fri, 08 Feb 2019 03:21:37 -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=1mzOcIy+7HPLayzQsYtXq7G3ykNjVf0oOnwFWZDqUko=; b=EoLc5aceWwe390TXMZpK6T/vZm5jdE7ZkFnDGglV4NYOehKOh0zDDCWcaSMvETAxdX Pmj5l4DxaPsM3hyxBUNjkvz6Z0/OAgcWA7ypHvXLxqcs1BSM+klgV/+a8g4mIO0f0kml UtY7oEWwsKsIpXnNBcFBcOcAAW1WF9ak4tslZCi+xRtHbLGVSOStfP1Rr6WbDdp1Mg3q HhYa6CaubfqyAeGex5tHl4bukcg9Hcsm+UEyKWs5IN0qMYNk/Z6MMOR2FDRgrP7CMVH3 V9cf+wX+vSMBMGr/mZfDGuTiV7HRJfw18re2djgck/AmwxqoSH5mw7vFyp+QDkJzxSWa V4gQ== 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=1mzOcIy+7HPLayzQsYtXq7G3ykNjVf0oOnwFWZDqUko=; b=RvF7qBC1Yha/Gn++25PSzZvTd+IN3m5LsLTHQ+G3asEsBNU52Cak35BPKBs9vNGiMI y0zMcOo2BGP+v46QXIrHxd7OE/FT/Fh4IhTAPknMvKAeymvq6aKW+sdE36HFoJ2BhJWg 2p/5Pw3tMASoSf112odiDfcYh05iIlNkrs/zkUwkUfl4smgFre8rhE1tVrEEr1zCVR91 C4EeEAqklkaRnVV7+PmgRTAqu42wOdWTjnAaQgS+Blgi/I5mrgSnyFMcHZ/cTTonUXZj v/CxtkL/f/BZ2igQre/1A+pXjTX93tJicL22rl3HdTnc1WPhf6Q8p3Ks5j5nah5fKsrv itQQ== X-Gm-Message-State: AHQUAuZcFKlGkOC8EjhYZ5lnOI9J1fou3Vn4X/Jg3v4ksGeehn7xylaQ 4cSQ9KKDgGSfAEw8sMY7qwygA0Wh X-Google-Smtp-Source: AHgI3Ib35pDYcRWVOaX2feeryTW4AHN5DbDtwfNAJGSFrTLv7KvIu85Lxr3CxNjLCCsT6HEV2R4v1A== X-Received: by 2002:a62:6503:: with SMTP id z3mr21144892pfb.169.1549624896609; Fri, 08 Feb 2019 03:21:36 -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 w128sm3148181pfw.79.2019.02.08.03.21.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 08 Feb 2019 03:21:36 -0800 (PST) Date: Fri, 8 Feb 2019 03:21:34 -0800 From: Denton Liu To: git@vger.kernel.org Cc: gitster@pobox.com Subject: [PATCH v4 3/3] submodule: teach set-branch subcommand Message-ID: <77af7e4b2fc094d8cd31164625ef3339e97e1cd5.1549624679.git.liu.denton@gmail.com> 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. Signed-off-by: Denton Liu --- 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 4150148fa3..4daf144180 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