From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS53758 23.128.96.0/24 X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id C25811F934 for ; Mon, 26 Apr 2021 17:48:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237742AbhDZRtF (ORCPT ); Mon, 26 Apr 2021 13:49:05 -0400 Received: from mav.lukeshu.com ([104.207.138.63]:39298 "EHLO mav.lukeshu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237593AbhDZRsn (ORCPT ); Mon, 26 Apr 2021 13:48:43 -0400 Received: from lukeshu-dw-thinkpad (unknown [IPv6:2601:281:8200:26:4e34:88ff:fe48:5521]) by mav.lukeshu.com (Postfix) with ESMTPSA id 5A16F80595; Mon, 26 Apr 2021 13:48:01 -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?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= , Roger L Strain , Techlive Zheng , Eric Sunshine , =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= , Luke Shumaker Subject: [PATCH v2 29/30] subtree: push: allow specifying a local rev other than HEAD Date: Mon, 26 Apr 2021 11:45:24 -0600 Message-Id: <20210426174525.3937858-30-lukeshu@lukeshu.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210426174525.3937858-1-lukeshu@lukeshu.com> References: <20210423194230.1388945-1-lukeshu@lukeshu.com> <20210426174525.3937858-1-lukeshu@lukeshu.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 1e5ac82f9b..678dd1dc19 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -27,7 +27,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 @@ -950,20 +950,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 1282aa705f..559b64aa96 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 8bc0e488aa..8a3530305e 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 # -- 2.31.1