git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/4] contrib/subtree: Store subtree sources in .gitsubtree and use for push/pull
@ 2013-02-12 23:21 Paul Campbell
  2013-02-18 20:20 ` greened
  0 siblings, 1 reply; 3+ messages in thread
From: Paul Campbell @ 2013-02-12 23:21 UTC (permalink / raw)
  To: git; +Cc: David A. Greene, Michael Schubert

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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/4] contrib/subtree: Store subtree sources in .gitsubtree and use for push/pull
  2013-02-12 23:21 [PATCH 1/4] contrib/subtree: Store subtree sources in .gitsubtree and use for push/pull Paul Campbell
@ 2013-02-18 20:20 ` greened
  2013-02-18 20:50   ` Paul Campbell
  0 siblings, 1 reply; 3+ messages in thread
From: greened @ 2013-02-18 20:20 UTC (permalink / raw)
  To: Paul Campbell; +Cc: git, Junio C Hamano

Paul Campbell <pcampbell@kemitix.net> writes:

> 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.

I agree with the basic idea but have some questions about the
implementation.

Is there precedent of git commands storing information in hidden files
and requiring those files to be added to the repository and tracked?  It
seems like a bit of a kludge.

Could we use notes or something for this?

I'm not necessarily against the patches, I just want to make sure we
don't go down a road that won't be acceptable later on.

                           -David

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/4] contrib/subtree: Store subtree sources in .gitsubtree and use for push/pull
  2013-02-18 20:20 ` greened
@ 2013-02-18 20:50   ` Paul Campbell
  0 siblings, 0 replies; 3+ messages in thread
From: Paul Campbell @ 2013-02-18 20:50 UTC (permalink / raw)
  To: greened; +Cc: git, Junio C Hamano

On Mon, Feb 18, 2013 at 8:20 PM,  <greened@obbligato.org> wrote:
> Paul Campbell <pcampbell@kemitix.net> writes:
>
>> 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.
>
> I agree with the basic idea but have some questions about the
> implementation.
>
> Is there precedent of git commands storing information in hidden files
> and requiring those files to be added to the repository and tracked?  It
> seems like a bit of a kludge.
>
> Could we use notes or something for this?
>
> I'm not necessarily against the patches, I just want to make sure we
> don't go down a road that won't be acceptable later on.
>
>                            -David

I'm not familiar with git notes. Adding that the my to-read list.

I took my inspiration from git submodules which uses the .gitmodules
file for a similar purpose.

-- 
Paul [W] Campbell

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-02-18 20:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-12 23:21 [PATCH 1/4] contrib/subtree: Store subtree sources in .gitsubtree and use for push/pull Paul Campbell
2013-02-18 20:20 ` greened
2013-02-18 20:50   ` Paul Campbell

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).