git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/4] contrib/subtree: Store subtree sources in .gitsubtree and use for push/pull

From
Paul Campbell <pcampbell@kemitix.net>
Date
Feb 12, 2013, 23:21 UTC
Message-ID
<CALeLG_kuXdF_F4ScRLPLm5h5cV_9p=EZYrWdjoWBrO99WFyi2Q@mail.gmail.com>

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 <pcampbell@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
Next: greened@obbligato.org
Message 1 of 3 in “contrib/subtree: Store subtree sources in .gitsubtree and use for push/pull”
  1. 1/4 contrib/subtree: Store subtree sources in .gitsubtree and use for push/pullPaul Campbell, Feb 12, 2013
  2. greened@obbligato.orgFeb 18, 2013
  3. Paul CampbellFeb 18, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.