From patchwork Fri Apr 23 19:42:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luke Shumaker X-Patchwork-Id: 12221627 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 114B1C43461 for ; Fri, 23 Apr 2021 19:43:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E1A416128B for ; Fri, 23 Apr 2021 19:43:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244017AbhDWTn7 (ORCPT ); Fri, 23 Apr 2021 15:43:59 -0400 Received: from mav.lukeshu.com ([104.207.138.63]:35522 "EHLO mav.lukeshu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243905AbhDWTno (ORCPT ); Fri, 23 Apr 2021 15:43:44 -0400 Received: from lukeshu-dw-thinkpad (unknown [IPv6:2601:281:8200:26:4e34:88ff:fe48:5521]) by mav.lukeshu.com (Postfix) with ESMTPSA id C06EB80594; Fri, 23 Apr 2021 15:43:06 -0400 (EDT) From: Luke Shumaker To: git@vger.kernel.org Cc: Avery Pennarun , Charles Bailey , Danny Lin , "David A . Greene" , David Aguilar , Jakub Suder , James Denholm , Jeff King , Jonathan Nieder , Junio C Hamano , =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41j?= =?utf-8?b?IER1eQ==?= , Roger L Strain , Techlive Zheng , Luke Shumaker Subject: [PATCH 29/30] subtree: push: allow specifying a local rev other than HEAD Date: Fri, 23 Apr 2021 13:42:29 -0600 Message-Id: <20210423194230.1388945-30-lukeshu@lukeshu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210423194230.1388945-1-lukeshu@lukeshu.com> References: <20210423194230.1388945-1-lukeshu@lukeshu.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Luke Shumaker 'git subtree split' lets you specify a rev other than HEAD. 'git push' lets you specify a mapping between a local thing and a remot ref. So smash those together, and have 'git subtree push' let you specify which local thing to run split on and push the result of that split to the remote ref. Signed-off-by: Luke Shumaker --- contrib/subtree/git-subtree.sh | 24 +++++++++++++++++------- contrib/subtree/git-subtree.txt | 14 ++++++++------ contrib/subtree/t/t7900-subtree.sh | 22 ++++++++++++++++++++++ 3 files changed, 47 insertions(+), 13 deletions(-) diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index 2846bd21b4..7361d8de3f 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -11,7 +11,7 @@ git subtree add --prefix= git subtree merge --prefix= git subtree split --prefix= [] git subtree pull --prefix= -git subtree push --prefix= +git subtree push --prefix= -- h,help show the help q quiet @@ -921,20 +921,30 @@ cmd_pull () { cmd_merge FETCH_HEAD } -# Usage: cmd_push REPOSITORY REMOTEREF +# Usage: cmd_push REPOSITORY [+][LOCALREV:]REMOTEREF cmd_push () { if test $# -ne 2 then - die "You must provide " + die "You must provide " fi - ensure_valid_ref_format "$2" if test -e "$dir" then repository=$1 - refspec=$2 + refspec=${2#+} + remoteref=${refspec#*:} + if test "$remoteref" = "$refspec" + then + localrevname_presplit=HEAD + else + localrevname_presplit=${refspec%%:*} + fi + ensure_valid_ref_format "$remoteref" + localrev_presplit=$(git rev-parse -q --verify "$localrevname_presplit^{commit}") || + die "'$localrevname_presplit' does not refer to a commit" + echo "git push using: " "$repository" "$refspec" - localrev=$(cmd_split) || die - git push "$repository" "$localrev":"refs/heads/$refspec" + localrev=$(cmd_split "$localrev_presplit") || die + git push "$repository" "$localrev":"refs/heads/$remoteref" else die "'$dir' must already exist. Try 'git subtree add'." fi diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt index a597d61d0f..c049827cb5 100644 --- a/contrib/subtree/git-subtree.txt +++ b/contrib/subtree/git-subtree.txt @@ -16,7 +16,7 @@ SYNOPSIS [verse] 'git subtree' [] -P pull -'git subtree' [] -P push +'git subtree' [] -P push DESCRIPTION ----------- @@ -115,11 +115,13 @@ pull :: it fetches the given ref from the specified remote repository. -push :: - Does a 'split' using the subtree of HEAD and then - does a 'git push' to push the result to the and - . This can be used to push your subtree to - different branches of the remote repository. +push [+][:]:: + Does a 'split' using the subtree of + and then does a 'git push' to push the result to the + and . This can be used to push your + subtree to different branches of the remote repository. Just + as with 'split', if no is given, then HEAD is + used. The optional leading '+' is ignored. OPTIONS FOR ALL COMMANDS ------------------------ diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh index e89e46fe65..fb85eed5fc 100755 --- a/contrib/subtree/t/t7900-subtree.sh +++ b/contrib/subtree/t/t7900-subtree.sh @@ -799,6 +799,28 @@ test_expect_success 'push "sub dir"/ with --branch for an incompatible branch' ' ) ' +test_expect_success 'push "sub dir"/ with a local rev' ' + subtree_test_create_repo "$test_count" && + subtree_test_create_repo "$test_count/sub proj" && + test_create_commit "$test_count" main1 && + test_create_commit "$test_count/sub proj" sub1 && + ( + cd "$test_count" && + git fetch ./"sub proj" HEAD && + git subtree add --prefix="sub dir" FETCH_HEAD + ) && + test_create_commit "$test_count" "sub dir"/main-sub1 && + test_create_commit "$test_count" "sub dir"/main-sub2 && + ( + cd "$test_count" && + bad_tree=$(git rev-parse --verify HEAD:"sub dir") && + good_tree=$(git rev-parse --verify HEAD^:"sub dir") && + git subtree push --prefix="sub dir" --annotate="*" ./"sub proj" HEAD^:from-mainline && + split_tree=$(git -C "sub proj" rev-parse --verify refs/heads/from-mainline:) && + test "$split_tree" = "$good_tree" + ) +' + # # Validity checking #