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/from that source.
Signed-off-by: Paul Campbell pcampb...@kemitix.net
---
contrib/subtree/git-subtree.sh | 42 +-
1 file changed, 37 insertions(+), 5 deletions(-)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 920c664..02aae30 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -488,6 +488,23 @@ ensure_clean()
fi
}
+subtree_memorize()
+{
+ if [ $# -eq 1 ] ; then
+ echo $dir . $@ .gitsubtree
+ elif [ $# -eq 2 ]; then
+ echo $dir $@ .gitsubtree
+ else
+ # don't know how to handle this
+ echo Not memorizing subtree: $dir $@
+ fi
+}
+
+subtree_remember()
+{
+ grep ^$dir .gitsubtree || die Subtree $dir isn't in .gitsubtree
+}
+
cmd_add()
{
if [ -e $dir ]; then
@@ -496,6 +513,7 @@ cmd_add()
ensure_clean
+ subtree_memorize $@
if [ $# -eq 1 ]; then
cmd_add_commit $@
elif [ $# -eq 2 ]; then
@@ -688,7 +706,17 @@ cmd_merge()
cmd_pull()
{
ensure_clean
- git fetch $@ || exit $?
+ if [ $# -eq 0 ]; then
+ memory=($(subtree_remember))
+ echo Pulling into '$dir' from '${memory[1]}' '${memory[2]}'
+ repository=${memory[1]}
+ refspec=${memory[2]}
+ 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 $@
@@ -696,12 +724,16 @@ cmd_pull()
cmd_push()
{
- if [ $# -ne 2 ]; then
-die You must provide repository refspec
+ repository=$1
+ refspec=$2
+ if [ $# -eq 0 ]; then
+ memo=($(subtree_remember))
+ repository=${memo[1]}
+ refspec=${memo[2]}
+ elif [ $# -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
else
--
1.8.1.3.566.gaa39828
--
Paul [W] Campbell
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html