summaryrefslogtreecommitdiff
path: root/contrib/subtree/git-subtree.sh
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@datawire.io>2021-04-27 21:17:47 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-04-28 07:47:19 (GMT)
commit49470cd445166fbe778218c7618ea8ee78ca7d00 (patch)
tree2fb21e14de3ccca4ad261410f449f5a1e305ad1e /contrib/subtree/git-subtree.sh
parent94389e7c81d47102f061b36a93e050d639fe3d40 (diff)
downloadgit-49470cd445166fbe778218c7618ea8ee78ca7d00.zip
git-49470cd445166fbe778218c7618ea8ee78ca7d00.tar.gz
git-49470cd445166fbe778218c7618ea8ee78ca7d00.tar.bz2
subtree: push: allow specifying a local rev other than HEAD
'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 <lukeshu@datawire.io> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'contrib/subtree/git-subtree.sh')
-rwxr-xr-xcontrib/subtree/git-subtree.sh24
1 files changed, 17 insertions, 7 deletions
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 431214a..9e4d9a0 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -27,7 +27,7 @@ git subtree add --prefix=<prefix> <repository> <ref>
git subtree merge --prefix=<prefix> <commit>
git subtree split --prefix=<prefix> [<commit>]
git subtree pull --prefix=<prefix> <repository> <ref>
-git subtree push --prefix=<prefix> <repository> <ref>
+git subtree push --prefix=<prefix> <repository> <refspec>
--
h,help show the help
q quiet
@@ -952,20 +952,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 <repository> <ref>"
+ die "You must provide <repository> <refspec>"
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