{"thread":{"id":"32892","subject":"[PATCH 1/4] contrib/subtree: Store subtree sources in .gitsubtree and use for push/pull","startedAt":"2013-02-12T23:21:34Z","lastAt":"2013-02-18T20:50:22Z","messageCount":3,"participants":["Paul Campbell","greened@obbligato.org"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"209437","messageId":"CALeLG_kuXdF_F4ScRLPLm5h5cV_9p=EZYrWdjoWBrO99WFyi2Q@mail.gmail.com","threadId":"32892","inReplyTo":null,"subject":"[PATCH 1/4] contrib/subtree: Store subtree sources in .gitsubtree and use for push/pull","fromName":"Paul Campbell","fromEmail":"pcampbell@kemitix.net","sentAt":"2013-02-12T23:21:34Z","receivedAt":"2013-02-12T23:21:34Z","isPatch":true,"sender":{"key":"pcampbell@kemitix.net","avatar":"https://gravatar.com/avatar/57584e05501b694929004e43fcd7308f4ad64df2eb0474cd8c7e5f93662bb0f1?d=mp&s=160"},"body":"Having to remember what subtree came from what source is a waste of\ndeveloper memory and doesn't transfer easily to other developers.\n\ngit subtree push/pull operations would typically be to/from the same\nsource that the original subtree was cloned from with git subtree add.\n\n\nThe <repository> and <refspec>, or <commit>, used in the git subtree add\noperation are stored in .gitsubtree. One line each delimited by a space:\n<prefix> <repository> <refspec> or <prefix> . <commit>.\n\nSubsequent git subtree push/pull operations now default to the values\nstored in .gitsubtree, unless overridden from the command line.\n\nThe .gitsubtree file should be tracked as part of the repo as it\ndescribes where parts of the tree came from and can be used to update\nto/from that source.\n\nSigned-off-by: Paul Campbell <pcampbell@kemitix.net>\n---\n contrib/subtree/git-subtree.sh | 42 +++++++++++++++++++++++++++++++++++++-----\n 1 file changed, 37 insertions(+), 5 deletions(-)\n\ndiff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh\nindex 920c664..02aae30 100755\n--- a/contrib/subtree/git-subtree.sh\n+++ b/contrib/subtree/git-subtree.sh\n@@ -488,6 +488,23 @@ ensure_clean()\n  fi\n }\n\n+subtree_memorize()\n+{\n+ if [ $# -eq 1 ] ; then\n+ echo \"$dir . $@\" >> .gitsubtree\n+ elif [ $# -eq 2 ]; then\n+ echo \"$dir $@\" >> .gitsubtree\n+ else\n+ # don't know how to handle this\n+ echo \"Not memorizing subtree: $dir $@\"\n+ fi\n+}\n+\n+subtree_remember()\n+{\n+ grep \"^$dir \" .gitsubtree || die \"Subtree $dir isn't in .gitsubtree\"\n+}\n+\n cmd_add()\n {\n  if [ -e \"$dir\" ]; then\n@@ -496,6 +513,7 @@ cmd_add()\n\n  ensure_clean\n\n+ subtree_memorize \"$@\"\n  if [ $# -eq 1 ]; then\n  \"cmd_add_commit\" \"$@\"\n  elif [ $# -eq 2 ]; then\n@@ -688,7 +706,17 @@ cmd_merge()\n cmd_pull()\n {\n  ensure_clean\n- git fetch \"$@\" || exit $?\n+ if [ $# -eq 0 ]; then\n+ memory=($(subtree_remember))\n+ echo \"Pulling into '$dir' from '${memory[1]}' '${memory[2]}'\"\n+ repository=${memory[1]}\n+ refspec=${memory[2]}\n+ echo \"git fetch using: \" $repository $refspec\n+ git fetch \"$repository\" \"$refspec\" || exit $?\n+ else\n+ echo \"git fetch using: $@\"\n+ git fetch \"$@\" || exit $?\n+ fi\n  revs=FETCH_HEAD\n  set -- $revs\n  cmd_merge \"$@\"\n@@ -696,12 +724,16 @@ cmd_pull()\n\n cmd_push()\n {\n- if [ $# -ne 2 ]; then\n-    die \"You must provide <repository> <refspec>\"\n+ repository=$1\n+ refspec=$2\n+ if [ $# -eq 0 ]; then\n+ memo=($(subtree_remember))\n+ repository=${memo[1]}\n+ refspec=${memo[2]}\n+ elif [ $# -ne 2 ]; then\n+ die \"You must provide <repository> <refspec> or a <prefix> listed in\n.gitsubtree\"\n  fi\n  if [ -e \"$dir\" ]; then\n-    repository=$1\n-    refspec=$2\n     echo \"git push using: \" $repository $refspec\n     git push $repository $(git subtree split\n--prefix=$prefix):refs/heads/$refspec\n  else\n--\n1.8.1.3.566.gaa39828\n\n\n--\nPaul [W] Campbell\n"},{"id":"209718","messageId":"87bobh4bmz.fsf@waller.obbligato.org","threadId":"32892","inReplyTo":"CALeLG_kuXdF_F4ScRLPLm5h5cV_9p=EZYrWdjoWBrO99WFyi2Q@mail.gmail.com","subject":"Re: [PATCH 1/4] contrib/subtree: Store subtree sources in .gitsubtree and use for push/pull","fromName":"","fromEmail":"greened@obbligato.org","sentAt":"2013-02-18T20:20:36Z","receivedAt":"2013-02-18T20:20:36Z","isPatch":true,"sender":{"key":"greened@obbligato.org","avatar":"https://avatars.githubusercontent.com/u/5291869?v=4"},"body":"Paul Campbell <pcampbell@kemitix.net> writes:\n\n> Subsequent git subtree push/pull operations now default to the values\n> stored in .gitsubtree, unless overridden from the command line.\n>\n> The .gitsubtree file should be tracked as part of the repo as it\n> describes where parts of the tree came from and can be used to update\n> to/from that source.\n\nI agree with the basic idea but have some questions about the\nimplementation.\n\nIs there precedent of git commands storing information in hidden files\nand requiring those files to be added to the repository and tracked?  It\nseems like a bit of a kludge.\n\nCould we use notes or something for this?\n\nI'm not necessarily against the patches, I just want to make sure we\ndon't go down a road that won't be acceptable later on.\n\n                           -David\n"},{"id":"209722","messageId":"CALeLG_mfYwVow-A=10kXKHWn7HO311yy5smRcFY6Gx5W3qNDdg@mail.gmail.com","threadId":"32892","inReplyTo":"87bobh4bmz.fsf@waller.obbligato.org","subject":"Re: [PATCH 1/4] contrib/subtree: Store subtree sources in .gitsubtree and use for push/pull","fromName":"Paul Campbell","fromEmail":"pcampbell@kemitix.net","sentAt":"2013-02-18T20:50:22Z","receivedAt":"2013-02-18T20:50:22Z","isPatch":true,"sender":{"key":"pcampbell@kemitix.net","avatar":"https://gravatar.com/avatar/57584e05501b694929004e43fcd7308f4ad64df2eb0474cd8c7e5f93662bb0f1?d=mp&s=160"},"body":"On Mon, Feb 18, 2013 at 8:20 PM,  <greened@obbligato.org> wrote:\n> Paul Campbell <pcampbell@kemitix.net> writes:\n>\n>> Subsequent git subtree push/pull operations now default to the values\n>> stored in .gitsubtree, unless overridden from the command line.\n>>\n>> The .gitsubtree file should be tracked as part of the repo as it\n>> describes where parts of the tree came from and can be used to update\n>> to/from that source.\n>\n> I agree with the basic idea but have some questions about the\n> implementation.\n>\n> Is there precedent of git commands storing information in hidden files\n> and requiring those files to be added to the repository and tracked?  It\n> seems like a bit of a kludge.\n>\n> Could we use notes or something for this?\n>\n> I'm not necessarily against the patches, I just want to make sure we\n> don't go down a road that won't be acceptable later on.\n>\n>                            -David\n\nI'm not familiar with git notes. Adding that the my to-read list.\n\nI took my inspiration from git submodules which uses the .gitmodules\nfile for a similar purpose.\n\n-- \nPaul [W] Campbell\n"}]}