From: Paul Campbell <pcampbell@kemitix.net>
To: git@vger.kernel.org
Cc: Adam Tkac <atkac@redhat.com>,
"David A. Greene" <greened@obbligato.org>,
"Jesper L. Nielsen" <lyager@gmail.com>,
Michael Schubert <mschub@elegosoft.com>,
Techlive Zheng <techlivezheng@gmail.com>
Subject: [PATCH v2 1/3] contrib/subtree: Store subtree sources in .gitsubtree and use for push/pull
Date: Fri, 15 Feb 2013 22:42:13 +0000 [thread overview]
Message-ID: <CALeLG_kgyGHYAc+5Hac2XSud95G3Xc2uxeG9sB3mC8qnPib3og@mail.gmail.com> (raw)
Add the prefix, repository and refspec in the file .gitsubtree when
git subtree add is used. Then when a git subtree push or pull is needed
the repository and refspec from .gitsubtree are used as the default
values.
Having to remember what subtree came from what source is a waste of
developer memory and doesn't transfer easily to other developers.
git subtree push/pull operations would typically be to/from the same
source that the original subtree was cloned from with git subtree add.
The <repository> and <refspec>, or <commit>, used in the git subtree add
operation are stored in .gitsubtree. One line each, delimited by a space:
"<prefix> <repository> <refspec>" or "<prefix> . <commit>".
Subsequent git subtree push/pull operations now default to the values
stored in .gitsubtree, unless overridden from the command line.
The .gitsubtree file should be tracked as part of the repo as it
describes where parts of the tree came from and can be used to update
to and from that source.
Signed-off-by: Paul Campbell <pcampbell@kemitix.net>
---
Reworked my previous patch paying closer attention to the coding style
documentation and renamed my new functions to make more sense.
contrib/subtree/git-subtree.sh | 75 +++++++++++++++++++++++++++++++++++-------
1 file changed, 64 insertions(+), 11 deletions(-)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 51146bd..6dc8999 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -11,8 +11,8 @@ OPTS_SPEC="\
git subtree add --prefix=<prefix> <commit>
git subtree add --prefix=<prefix> <repository> <commit>
git subtree merge --prefix=<prefix> <commit>
-git subtree pull --prefix=<prefix> <repository> <refspec...>
-git subtree push --prefix=<prefix> <repository> <refspec...>
+git subtree pull --prefix=<prefix> [<repository> <refspec...>]
+git subtree push --prefix=<prefix> [<repository> <refspec...>]
git subtree split --prefix=<prefix> <commit...>
--
h,help show the help
@@ -489,6 +489,28 @@ ensure_clean()
fi
}
+add_subtree () {
+ if ( grep "^$dir " .gitsubtree )
+ then
+ # remove $dir from .gitsubtree - there's probably a clever way to
do this with sed
+ grep -v "^$dir " .gitsubtree > .gitsubtree.temp
+ rm .gitsubtree
+ mv .gitsubtree.temp .gitsubtree
+ fi
+ if test $# -eq 1
+ then
+ # Only a commit provided, thus use the current repository
+ echo "$dir . $@" >> .gitsubtree
+ elif test $# -eq 2
+ then
+ echo "$dir $@" >> .gitsubtree
+ fi
+}
+
+get_subtree () {
+ grep "^$dir " .gitsubtree || die "Subtree not found in .gitsubtree: " "$dir"
+}
+
cmd_add()
{
if [ -e "$dir" ]; then
@@ -497,6 +519,8 @@ cmd_add()
ensure_clean
+ add_subtree "$@"
+
if [ $# -eq 1 ]; then
git rev-parse -q --verify "$1^{commit}" >/dev/null ||
die "'$1' does not refer to a commit"
@@ -700,7 +724,23 @@ cmd_merge()
cmd_pull()
{
ensure_clean
- git fetch "$@" || exit $?
+ if test $# -eq 0
+ then
+ subtree=($(get_subtree))
+ repository=${subtree[1]}
+ refspec=${subtree[2]}
+ if test "$repository" == "."
+ then
+ echo "Pulling into $dir from branch $refspec"
+ else
+ echo "Pulling into '$dir' from '$repository' '$refspec'"
+ fi
+ echo "git fetch using: " $repository $refspec
+ git fetch "$repository" "$refspec" || exit $?
+ else
+ echo "git fetch using: $@"
+ git fetch "$@" || exit $?
+ fi
revs=FETCH_HEAD
set -- $revs
cmd_merge "$@"
@@ -708,16 +748,29 @@ cmd_pull()
cmd_push()
{
- if [ $# -ne 2 ]; then
- die "You must provide <repository> <refspec>"
+ repository=$1
+ refspec=$2
+ if test $# -eq 0
+ then
+ subtree=($(get_subtree))
+ repository=${subtree[1]}
+ refspec=${subtree[2]}
+ if test "$repository" == "."
+ then
+ echo "Pushing from $dir into branch $refspec"
+ else
+ echo "Pushing from $dir into $repository $refspec"
+ fi
+ elif test $# -ne 2
+ then
+ die "You must provide <repository> <refspec>, or a <prefix> listed
in .gitsubtree"
fi
- if [ -e "$dir" ]; then
- repository=$1
- refspec=$2
- echo "git push using: " $repository $refspec
- git push $repository $(git subtree split
--prefix=$prefix):refs/heads/$refspec
+ if test -e "$dir"
+ then
+ echo "git push using: " $repository $refspec
+ git push $repository $(git subtree split
--prefix=$prefix):refs/heads/$refspec
else
- die "'$dir' must already exist. Try 'git subtree add'."
+ die "'$dir' must already exist. Try 'git subtree add'."
fi
}
--
1.8.1.3.605.g02339dd
reply other threads:[~2013-02-15 22:42 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CALeLG_kgyGHYAc+5Hac2XSud95G3Xc2uxeG9sB3mC8qnPib3og@mail.gmail.com \
--to=pcampbell@kemitix.net \
--cc=atkac@redhat.com \
--cc=git@vger.kernel.org \
--cc=greened@obbligato.org \
--cc=lyager@gmail.com \
--cc=mschub@elegosoft.com \
--cc=techlivezheng@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).