[PATCH v2 00/23] contrib/subtree: Collected updates

DORMANTno replies

24 messages, 1 author, 2016-06-15 · open the first message on its own page

[PATCH v2 00/23] contrib/subtree: Collected updates

From: Paul Campbell <hidden>
Date: 2016-06-15 22:56:21

A selection of updates to git-subtree were offered to the list in May of 
last year ($gmane/196667) by Herman van Rink.

At the time the commits were available as either a single commit or a 
large collection of commits and merges to the git-subtree prior to it's
inclusion in contrib/subtree.

The following patches take a selection of these commits and rebase them 
against the tip of master.

The git-subtree tests work (make test), but they don't cover any of
the new commands added nor the use of the .gittrees file for storing
the subtree metadata.

If I could ask the original contributors to add their Signed-off-by, I
would appreciate it.

However I don't have current email addresses for four of them: Peter 
Jaros, Michael Hart, Paul Cartwright and James Roper. If anyone has 
current email address for any of these, please either forward the 
relevant patch(es) to them or let me know so I can do so.

Herman van Rink (8):
  contrib/subtree: Add prune command to OPTS_SPEC
  contrib/subtree: Remove trailing slash from prefix parameter
  contrib/subtree: Teach from-submodule to add new subtree to .gittrees
  contrib/subtree: Document pull-all and push-all
  contrib/subtree: Document from-submodule and prune commands
  contrib/subtree: Add missing commands to SYNOPSIS
  contrib/subtree: Document list command
  contrib/subtree: Convert spaces to tabs and remove some trailing
    whitespace

James Roper (1):
  contrib/subtree: Teach push to use --force option

Matt Hoffman (6):
  contrib/subtree: Teach add to store repository & branch in .gittrees
  contrib/subtree: Rename commands push_all/pull_all to
    push-all/pull-all
  contrib/subtree: Teach push and pull to use .gittrees if needed
  contrib/subtree: Replace invisible carriage return with a visible \r
  contrib/subtree: Add command diff
  contrib/subtree: Add command list

Michael Hart (1):
  contrib/subtree: Teach push to abort if split fails

Nate Jones (1):
  contrib/subtree: Add command prune

Paul Campbell (2):
  contrib/subtree: Parameters repository/branch for push/pull are
    optional
  contrib/subtree: Fix order of case switches so default case is last

Paul Cartwright (1):
  contrib/subtree: Fix typo (s/incldued/included/)

Peter Jaros (1):
  contrib/subtree: Add command from-submodule

bibendi (2):
  contrib/subtree: Teach push and pull to use .gittrees for defaults
  contrib/subtree: Add commands pull_all and push_all

 contrib/subtree/git-subtree.sh  | 203 ++++++++++++++++++++++++++++++++++++----
 contrib/subtree/git-subtree.txt |  46 +++++++--
 2 files changed, 222 insertions(+), 27 deletions(-)

-- 
1.8.2.rc1

[PATCH v2 01/23] contrib/subtree: Fix typo (s/incldued/included/)

From: Paul Campbell <hidden>
Date: 2016-06-15 22:56:21

From: Paul Cartwright <redacted>

Signed-off-by: Paul Campbell <redacted>
---
 contrib/subtree/git-subtree.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt
index 7ba853e..e0957ee 100644
--- a/contrib/subtree/git-subtree.txt
+++ b/contrib/subtree/git-subtree.txt
@@ -270,7 +270,7 @@ git-extensions repository in ~/git-extensions/:
 name
 
 You can omit the --squash flag, but doing so will increase the number
-of commits that are incldued in your local repository.
+of commits that are included in your local repository.
 
 We now have a ~/git-extensions/git-subtree directory containing code
 from the master branch of git://github.com/apenwarr/git-subtree.git
-- 
1.8.2.rc1

[PATCH v2 02/23] contrib/subtree: Add command from-submodule

From: Paul Campbell <hidden>
Date: 2016-06-15 22:56:21

From: Peter Jaros <redacted>

Converts a git-submodule into a git-subtree.

Signed-off-by: Paul Campbell <redacted>

Conflicts:
	.gitignore
	contrib/subtree/git-subtree.sh
	test.sh
---
 contrib/subtree/git-subtree.sh | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 8a23f58..caf4988 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -14,6 +14,7 @@ git subtree merge --prefix=<prefix> <commit>
 git subtree pull  --prefix=<prefix> <repository> <refspec...>
 git subtree push  --prefix=<prefix> <repository> <refspec...>
 git subtree split --prefix=<prefix> <commit...>
+git subtree from-submodule --prefix=<prefix>
 --
 h,help        show the help
 q             quiet
@@ -101,7 +102,7 @@ done
 command="$1"
 shift
 case "$command" in
-	add|merge|pull) default= ;;
+	add|merge|pull|from-submodule) default= ;;
 	split|push) default="--default HEAD" ;;
 	*) die "Unknown command '$command'" ;;
 esac
@@ -721,4 +722,31 @@ cmd_push()
 	fi
 }
 
+cmd_from-submodule()
+{
+	ensure_clean
+
+	local submodule_sha=$(git submodule status $prefix | cut -d ' ' -f 2)
+
+	# Remove references to submodule.
+	git config --remove-section submodule.$prefix
+	git config --file .gitmodules --remove-section submodule.$prefix
+	git add .gitmodules
+
+	# Move submodule aside.
+	local tmp_repo="$(mktemp -d /tmp/git-subtree.XXXXX)"
+	rm -r $tmp_repo
+	mv $prefix $tmp_repo
+	git rm $prefix
+
+	# Commit changes.
+	git commit -m "Remove '$prefix/' submodule"
+
+	# subtree add from submodule repo.
+	cmd_add_repository $tmp_repo HEAD
+
+	# Remove submodule repo.
+	rm -rf $tmp_repo
+}
+
 "cmd_$command" "$@"
-- 
1.8.2.rc1

[PATCH v2 03/23] contrib/subtree: Teach add to store repository & branch in .gittrees

From: Paul Campbell <hidden>
Date: 2016-06-15 22:56:21

From: Matt Hoffman <redacted>

The repository and branch of a subtree added with the add command is
stored in the .gittrees file.

Signed-off-by: Paul Campbell <redacted>
---
 contrib/subtree/git-subtree.sh | 8 ++++++++
 1 file changed, 8 insertions(+)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index caf4988..7b70251 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -528,6 +528,14 @@ cmd_add_repository()
 	revs=FETCH_HEAD
 	set -- $revs
 	cmd_add_commit "$@"
+  
+  # now add it to our list of repos 
+  git config -f .gittrees --unset subtree.$dir.url
+  git config -f .gittrees --add subtree.$dir.url $repository
+  git config -f .gittrees --unset subtree.$dir.path
+  git config -f .gittrees --add subtree.$dir.path $dir
+  git config -f .gittrees --unset subtree.$dir.branch
+  git config -f .gittrees --add subtree.$dir.branch $refspec
 }
 
 cmd_add_commit()
-- 
1.8.2.rc1

[PATCH v2 04/23] contrib/subtree: Teach push and pull to use .gittrees for defaults

From: Paul Campbell <hidden>
Date: 2016-06-15 22:56:21

From: bibendi <redacted>

Look in the config file .gittrees for a default repository and
refspec or commit when they are not provided on the command line.

Uses the .gittrees config file in a similar way to how git-submodule
uses the .gitmodules file.

Signed-off-by: Paul Campbell <redacted>
---
 contrib/subtree/git-subtree.sh | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 7b70251..1aff956 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -708,21 +708,31 @@ cmd_merge()
 
 cmd_pull()
 {
-	ensure_clean
-	git fetch "$@" || exit $?
-	revs=FETCH_HEAD
-	set -- $revs
-	cmd_merge "$@"
+    if [ $# -ne 1 ]; then
+	    die "You must provide <branch>"
+	fi
+	if [ -e "$dir" ]; then
+	    ensure_clean
+	    repository=$(git config -f .gittrees subtree.$prefix.url)
+	    refspec=$1
+	    git fetch $repository $refspec || exit $?
+	    echo "git fetch using: " $repository $refspec
+	    revs=FETCH_HEAD
+	    set -- $revs
+	    cmd_merge "$@"
+	else
+	    die "'$dir' must already exist. Try 'git subtree add'."
+	fi
 }
 
 cmd_push()
 {
-	if [ $# -ne 2 ]; then
-	    die "You must provide <repository> <refspec>"
+	if [ $# -ne 1 ]; then
+	    die "You must provide <branch>"
 	fi
 	if [ -e "$dir" ]; then
-	    repository=$1
-	    refspec=$2
+	    repository=$(git config -f .gittrees subtree.$prefix.url)
+	    refspec=$1
 	    echo "git push using: " $repository $refspec
 	    git push $repository $(git subtree split --prefix=$prefix):refs/heads/$refspec
 	else
-- 
1.8.2.rc1

[PATCH v2 05/23] contrib/subtree: Add commands pull_all and push_all

From: Paul Campbell <hidden>
Date: 2016-06-15 22:56:21

From: bibendi <redacted>

For each subtree listed in .gittrees perform a push or a pull.

Signed-off-by: Paul Campbell <redacted>

Conflicts:
	contrib/subtree/git-subtree.sh
---
 contrib/subtree/git-subtree.sh | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 1aff956..ddae56e 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -12,6 +12,7 @@ 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 pull_all
 git subtree push  --prefix=<prefix> <repository> <refspec...>
 git subtree split --prefix=<prefix> <commit...>
 git subtree from-submodule --prefix=<prefix>
@@ -102,16 +103,18 @@ done
 command="$1"
 shift
 case "$command" in
-	add|merge|pull|from-submodule) default= ;;
+	add|merge|pull|from-submodule|pull_all|push_all) default= ;;
 	split|push) default="--default HEAD" ;;
 	*) die "Unknown command '$command'" ;;
 esac
 
-if [ -z "$prefix" ]; then
+if [ -z "$prefix" -a "$command" != "pull_all" -a "$command" != "push_all" ]; then
 	die "You must provide the --prefix option."
 fi
 
 case "$command" in
+    pull_all);;
+    push_all);;
 	add) [ -e "$prefix" ] && 
 		die "prefix '$prefix' already exists." ;;
 	*)   [ -e "$prefix" ] || 
@@ -120,7 +123,7 @@ esac
 
 dir="$(dirname "$prefix/.")"
 
-if [ "$command" != "pull" -a "$command" != "add" -a "$command" != "push" ]; then
+if [ "$command" != "pull" -a "$command" != "add" -a "$command" != "push" -a "$command" != "pull_all" ]; then
 	revs=$(git rev-parse $default --revs-only "$@") || exit $?
 	dirs="$(git rev-parse --no-revs --no-flags "$@")" || exit $?
 	if [ -n "$dirs" ]; then
@@ -767,4 +770,20 @@ cmd_from-submodule()
 	rm -rf $tmp_repo
 }
 
+cmd_pull_all()
+{
+    git config -f .gittrees -l | grep subtree | grep path | grep -o '=.*' | grep -o '[^=].*' |
+        while read path; do
+            git subtree pull -P $path master || exit $?
+        done
+}
+
+cmd_push_all()
+{
+    git config -f .gittrees -l | grep subtree | grep path | grep -o '=.*' | grep -o '[^=].*' |
+        while read path; do
+            git subtree push -P $path master || exit $?
+        done
+}
+
 "cmd_$command" "$@"
-- 
1.8.2.rc1

[PATCH v2 06/23] contrib/subtree: Rename commands push_all/pull_all to push-all/pull-all

From: Paul Campbell <hidden>
Date: 2016-06-15 22:56:21

From: Matt Hoffman <redacted>

Changing underscores to dashes (push_all -> push-all)

Signed-off-by: Paul Campbell <redacted>

Conflicts:
	.gitignore
	contrib/subtree/git-subtree.sh
---
 contrib/subtree/git-subtree.sh | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index ddae56e..39d764b 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -12,7 +12,8 @@ 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 pull_all
+git subtree pull-all
+git subtree push-all
 git subtree push  --prefix=<prefix> <repository> <refspec...>
 git subtree split --prefix=<prefix> <commit...>
 git subtree from-submodule --prefix=<prefix>
@@ -103,18 +104,18 @@ done
 command="$1"
 shift
 case "$command" in
-	add|merge|pull|from-submodule|pull_all|push_all) default= ;;
+	add|merge|pull|from-submodule|pull-all|push-all) default= ;;
 	split|push) default="--default HEAD" ;;
 	*) die "Unknown command '$command'" ;;
 esac
 
-if [ -z "$prefix" -a "$command" != "pull_all" -a "$command" != "push_all" ]; then
+if [ -z "$prefix" -a "$command" != "pull-all" -a "$command" != "push-all" ]; then
 	die "You must provide the --prefix option."
 fi
 
 case "$command" in
-    pull_all);;
-    push_all);;
+    pull-all);;
+    push-all);;
 	add) [ -e "$prefix" ] && 
 		die "prefix '$prefix' already exists." ;;
 	*)   [ -e "$prefix" ] || 
@@ -123,7 +124,7 @@ esac
 
 dir="$(dirname "$prefix/.")"
 
-if [ "$command" != "pull" -a "$command" != "add" -a "$command" != "push" -a "$command" != "pull_all" ]; then
+if [ "$command" != "pull" -a "$command" != "add" -a "$command" != "push" -a "$command" != "pull-all" ]; then
 	revs=$(git rev-parse $default --revs-only "$@") || exit $?
 	dirs="$(git rev-parse --no-revs --no-flags "$@")" || exit $?
 	if [ -n "$dirs" ]; then
@@ -770,7 +771,7 @@ cmd_from-submodule()
 	rm -rf $tmp_repo
 }
 
-cmd_pull_all()
+cmd_pull-all()
 {
     git config -f .gittrees -l | grep subtree | grep path | grep -o '=.*' | grep -o '[^=].*' |
         while read path; do
@@ -778,7 +779,7 @@ cmd_pull_all()
         done
 }
 
-cmd_push_all()
+cmd_push-all()
 {
     git config -f .gittrees -l | grep subtree | grep path | grep -o '=.*' | grep -o '[^=].*' |
         while read path; do
-- 
1.8.2.rc1

[PATCH v2 07/23] contrib/subtree: Teach push and pull to use .gittrees if needed

From: Paul Campbell <hidden>
Date: 2016-06-15 22:56:21

From: Matt Hoffman <redacted>

Only when a repository and/or branch are not supplied on the command
line will push and pull look for them in the .gittrees file.

Signed-off-by: Paul Campbell <redacted>
---
 contrib/subtree/git-subtree.sh | 32 ++++++++++++++++++++++++--------
 1 file changed, 24 insertions(+), 8 deletions(-)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 39d764b..98c508b 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -712,13 +712,21 @@ cmd_merge()
 
 cmd_pull()
 {
-    if [ $# -ne 1 ]; then
-	    die "You must provide <branch>"
+  if [ $# -gt 2 ]; then
+	    die "You should provide either <refspec> or <repository> <refspec>"
 	fi
 	if [ -e "$dir" ]; then
 	    ensure_clean
-	    repository=$(git config -f .gittrees subtree.$prefix.url)
-	    refspec=$1
+      if [ $# -eq 1 ]; then 
+	      repository=$(git config -f .gittrees subtree.$prefix.url)
+	      refspec=$1
+      elif [ $# -eq 2 ]; then 
+        repository=$1
+        refspec=$2
+      else 
+	      repository=$(git config -f .gittrees subtree.$prefix.url)
+        refspec=$(git config -f .gittrees subtree.$prefix.branch)
+      fi
 	    git fetch $repository $refspec || exit $?
 	    echo "git fetch using: " $repository $refspec
 	    revs=FETCH_HEAD
@@ -731,12 +739,20 @@ cmd_pull()
 
 cmd_push()
 {
-	if [ $# -ne 1 ]; then
-	    die "You must provide <branch>"
+	if [ $# -gt 2 ]; then
+	    die "You shold provide either <refspec> or <repository> <refspec>"
 	fi
 	if [ -e "$dir" ]; then
-	    repository=$(git config -f .gittrees subtree.$prefix.url)
-	    refspec=$1
+      if [ $# -eq 1 ]; then 
+	      repository=$(git config -f .gittrees subtree.$prefix.url)
+        refspec=$1
+      elif [ $# -eq 2 ]; then 
+        repository=$1
+        refspec=$2
+      else
+	      repository=$(git config -f .gittrees subtree.$prefix.url)
+        refspec=$(git config -f .gittrees subtree.$prefix.branch)
+      fi
 	    echo "git push using: " $repository $refspec
 	    git push $repository $(git subtree split --prefix=$prefix):refs/heads/$refspec
 	else
-- 
1.8.2.rc1

[PATCH v2 08/23] contrib/subtree: Replace invisible carriage return with a visible \r

From: Paul Campbell <hidden>
Date: 2016-06-15 22:56:21

From: Matt Hoffman <redacted>

The ctrl-M (^M) character used for the carriage return (CR) is not visible
in all (most) text editors and is often silently converted to a new
line (NL) or CR/NL combo.

'say' is a wrapper for echo with accepts the option -e to interperet
escaped characters. \r becomes a CR, yet is not munged by text
editors.

Signed-off-by: Paul Campbell <redacted>

Conflicts:
	git-subtree.sh
---
 contrib/subtree/git-subtree.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 98c508b..8056851 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -605,7 +605,7 @@ cmd_split()
 	eval "$grl" |
 	while read rev parents; do
 		revcount=$(($revcount + 1))
-		say -n "$revcount/$revmax ($createcount)
"
+		say -ne "$revcount/$revmax ($createcount)\r"
 		debug "Processing commit: $rev"
 		exists=$(cache_get $rev)
 		if [ -n "$exists" ]; then
-- 
1.8.2.rc1

[PATCH v2 09/23] contrib/subtree: Teach push to abort if split fails

From: Paul Campbell <hidden>
Date: 2016-06-15 22:56:21

From: Michael Hart <redacted>

Added a check to ensure that split succeeds before trying to push.

Signed-off-by: Paul Campbell <redacted>
---
 contrib/subtree/git-subtree.sh | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 8056851..ae9f87f 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -754,7 +754,12 @@ cmd_push()
         refspec=$(git config -f .gittrees subtree.$prefix.branch)
       fi
 	    echo "git push using: " $repository $refspec
-	    git push $repository $(git subtree split --prefix=$prefix):refs/heads/$refspec
+	    rev=$(git subtree split --prefix=$prefix)
+	    if [ -n "$rev" ]; then
+	        git push $repository $rev:refs/heads/$refspec
+	    else
+	        die "Couldn't push, 'git subtree split' failed."
+	    fi
 	else
 	    die "'$dir' must already exist. Try 'git subtree add'."
 	fi
-- 
1.8.2.rc1

[PATCH v2 10/23] contrib/subtree: Add command diff

From: Paul Campbell <hidden>
Date: 2016-06-15 22:56:21

From: Matt Hoffman <redacted>

Fetches the remote repo as a temporary git-remote then uses
git-diff-tree to do comparison before removing the temporary
git-remote.

Signed-off-by: Paul Campbell <redacted>

Conflicts:
	git-subtree.sh
---
 contrib/subtree/git-subtree.sh | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index ae9f87f..4c3f3c0 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -16,6 +16,7 @@ git subtree pull-all
 git subtree push-all
 git subtree push  --prefix=<prefix> <repository> <refspec...>
 git subtree split --prefix=<prefix> <commit...>
+git subtree diff  --prefix=<prefix> [<repository> [<refspec>...]]
 git subtree from-submodule --prefix=<prefix>
 --
 h,help        show the help
@@ -105,8 +106,8 @@ command="$1"
 shift
 case "$command" in
 	add|merge|pull|from-submodule|pull-all|push-all) default= ;;
-	split|push) default="--default HEAD" ;;
 	*) die "Unknown command '$command'" ;;
+    split|push|diff) default="--default HEAD" ;;
 esac
 
 if [ -z "$prefix" -a "$command" != "pull-all" -a "$command" != "push-all" ]; then
@@ -737,6 +738,37 @@ cmd_pull()
 	fi
 }
 
+cmd_diff() 
+{
+    if [ -e "$dir" ]; then
+        if [ $# -eq 1 ]; then 
+            repository=$(git config -f .gittrees subtree.$prefix.url)
+            refspec=$1
+        elif [ $# -eq 2 ]; then 
+            repository=$1
+            refspec=$2
+        else
+            repository=$(git config -f .gittrees subtree.$prefix.url)
+            refspec=$(git config -f .gittrees subtree.$prefix.branch)
+        fi
+        # this is ugly, but I don't know of a better way to do it. My git-fu is weak. 
+        # git diff-tree expects a treeish, but I have only a repository and branch name.
+        # I don't know how to turn that into a treeish without creating a remote.
+        # Please change this if you know a better way! 
+        tmp_remote=__diff-tmp
+        git remote rm $tmp_remote > /dev/null 2>&1
+        git remote add -t $refspec $tmp_remote $repository > /dev/null
+        # we fetch as a separate step so we can pass -q (quiet), which isn't an option for "git remote"
+        # could this instead be "git fetch -q $repository $refspec" and leave aside creating the remote?
+        # Still need a treeish for the diff-tree command...
+        git fetch -q $tmp_remote 
+        git diff-tree -p refs/remotes/$tmp_remote/$refspec
+        git remote rm $tmp_remote > /dev/null 2>&1
+    else 
+        die "Cannot resolve directory '$dir'. Please point to an existing subtree directory to diff. Try 'git subtree add' to add a subtree."
+    fi
+}
+
 cmd_push()
 {
 	if [ $# -gt 2 ]; then
-- 
1.8.2.rc1

[PATCH v2 11/23] contrib/subtree: Add command list

From: Paul Campbell <hidden>
Date: 2016-06-15 22:56:21

From: Matt Hoffman <redacted>

Lists subtrees from the .gittrees file.

Signed-off-by: Paul Campbell <redacted>

Conflicts:
	git-subtree.sh
---
 contrib/subtree/git-subtree.sh | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 4c3f3c0..7d08064 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -107,10 +107,10 @@ shift
 case "$command" in
 	add|merge|pull|from-submodule|pull-all|push-all) default= ;;
 	*) die "Unknown command '$command'" ;;
-    split|push|diff) default="--default HEAD" ;;
+    split|push|diff|list) default="--default HEAD" ;;
 esac
 
-if [ -z "$prefix" -a "$command" != "pull-all" -a "$command" != "push-all" ]; then
+if [ -z "$prefix" -a "$command" != "pull-all" -a "$command" != "push-all" -a "$command" != "list" ]; then
 	die "You must provide the --prefix option."
 fi
 
@@ -824,6 +824,21 @@ cmd_from-submodule()
 	rm -rf $tmp_repo
 }
 
+subtree_list() 
+{
+    git config -f .gittrees -l | grep subtree | grep path | grep -o '=.*' | grep -o '[^=].*' |
+    while read path; do 
+        repository=$(git config -f .gittrees subtree.$path.url)
+        refspec=$(git config -f .gittrees subtree.$path.branch)
+        echo "    $path        (merged from $repository branch $refspec) "
+    done
+}
+
+cmd_list()
+{
+  subtree_list 
+}
+
 cmd_pull-all()
 {
     git config -f .gittrees -l | grep subtree | grep path | grep -o '=.*' | grep -o '[^=].*' |
-- 
1.8.2.rc1

[PATCH v2 12/23] contrib/subtree: Add command prune

From: Paul Campbell <hidden>
Date: 2016-06-15 22:56:21

From: Nate Jones <redacted>

Removes entries in .gittrees where the subtree files are
no longer present on disk.

Signed-off-by: Paul Campbell <redacted>

Conflicts:
	git-subtree.sh
---
 contrib/subtree/git-subtree.sh | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 7d08064..0c41383 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -105,12 +105,12 @@ done
 command="$1"
 shift
 case "$command" in
-	add|merge|pull|from-submodule|pull-all|push-all) default= ;;
+    add|merge|pull|from-submodule|pull-all|push-all|prune) default= ;;
 	*) die "Unknown command '$command'" ;;
     split|push|diff|list) default="--default HEAD" ;;
 esac
 
-if [ -z "$prefix" -a "$command" != "pull-all" -a "$command" != "push-all" -a "$command" != "list" ]; then
+if [ -z "$prefix" -a "$command" != "pull-all" -a "$command" != "push-all" -a "$command" != "list" -a "$command" != "prune" ]; then
 	die "You must provide the --prefix option."
 fi
 
@@ -839,6 +839,17 @@ cmd_list()
   subtree_list 
 }
 
+cmd_prune()
+{
+    git config -f .gittrees -l | grep subtree | grep path | grep -o '=.*' | grep -o '[^=].*' |
+    while read path; do
+        if [ ! -e "$path" ]; then
+            echo "pruning $path"
+            git config -f .gittrees --remove-section subtree.$path
+        fi
+    done
+}
+
 cmd_pull-all()
 {
     git config -f .gittrees -l | grep subtree | grep path | grep -o '=.*' | grep -o '[^=].*' |
-- 
1.8.2.rc1

[PATCH v2 13/23] contrib/subtree: Add prune command to OPTS_SPEC

From: Paul Campbell <hidden>
Date: 2016-06-15 22:56:21

From: Herman van Rink <redacted>

Signed-off-by: Paul Campbell <redacted>

Conflicts:
	git-subtree.sh
---
 contrib/subtree/git-subtree.sh | 1 +
 1 file changed, 1 insertion(+)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 0c41383..d67fe5a 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -18,6 +18,7 @@ git subtree push  --prefix=<prefix> <repository> <refspec...>
 git subtree split --prefix=<prefix> <commit...>
 git subtree diff  --prefix=<prefix> [<repository> [<refspec>...]]
 git subtree from-submodule --prefix=<prefix>
+git subtree prune
 --
 h,help        show the help
 q             quiet
-- 
1.8.2.rc1

[PATCH v2 14/23] contrib/subtree: Remove trailing slash from prefix parameter

From: Paul Campbell <hidden>
Date: 2016-06-15 22:56:21

From: Herman van Rink <redacted>

Conflicts:
	git-subtree.sh

Signed-off-by: Paul Campbell <redacted>
---
 contrib/subtree/git-subtree.sh | 3 +++
 1 file changed, 3 insertions(+)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index d67fe5a..ae7d1fe 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -103,6 +103,9 @@ while [ $# -gt 0 ]; do
 	esac
 done
 
+# Remove trailing slash
+prefix="${prefix%/}";
+
 command="$1"
 shift
 case "$command" in
-- 
1.8.2.rc1

[PATCH v2 15/23] contrib/subtree: Teach from-submodule to add new subtree to .gittrees

From: Paul Campbell <hidden>
Date: 2016-06-15 22:56:21

From: Herman van Rink <redacted>

Signed-off-by: Paul Campbell <redacted>

Conflicts:
	git-subtree.sh
---
 contrib/subtree/git-subtree.sh | 5 +++++
 1 file changed, 5 insertions(+)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index ae7d1fe..84c90c7 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -806,6 +806,7 @@ cmd_from-submodule()
 	ensure_clean
 
 	local submodule_sha=$(git submodule status $prefix | cut -d ' ' -f 2)
+	local submodule_orig_repo=$(git config --file .gitmodules submodule.$prefix.url)
 
 	# Remove references to submodule.
 	git config --remove-section submodule.$prefix
@@ -824,6 +825,10 @@ cmd_from-submodule()
 	# subtree add from submodule repo.
 	cmd_add_repository $tmp_repo HEAD
 
+	# Update .gittrees with the original repo url
+	git config --file .gittrees --unset subtree.$prefix.url
+	git config --file .gittrees subtree.$prefix.url $submodule_orig_repo
+
 	# Remove submodule repo.
 	rm -rf $tmp_repo
 }
-- 
1.8.2.rc1

[PATCH v2 16/23] contrib/subtree: Document pull-all and push-all

From: Paul Campbell <hidden>
Date: 2016-06-15 22:56:21

From: Herman van Rink <redacted>

Signed-off-by: Paul Campbell <redacted>
---
 contrib/subtree/git-subtree.txt | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt
index e0957ee..c8fc103 100644
--- a/contrib/subtree/git-subtree.txt
+++ b/contrib/subtree/git-subtree.txt
@@ -92,13 +92,19 @@ pull::
 	Exactly like 'merge', but parallels 'git pull' in that
 	it fetches the given commit from the specified remote
 	repository.
-	
+
+pull-all::
+	Perform a pull operation on all in .gittrees registered subtrees.
+
 push::
 	Does a 'split' (see below) using the <prefix> supplied
 	and then does a 'git push' to push the result to the 
 	repository and refspec. This can be used to push your
 	subtree to different branches of the remote repository.
 
+push-all::
+	Perform a pull operation on all in .gittrees registered subtrees.
+
 split::
 	Extract a new, synthetic project history from the
 	history of the <prefix> subtree.  The new history
-- 
1.8.2.rc1

[PATCH v2 17/23] contrib/subtree: Document from-submodule and prune commands

From: Paul Campbell <hidden>
Date: 2016-06-15 22:56:21

From: Herman van Rink <redacted>

Signed-off-by: Paul Campbell <redacted>
---
 contrib/subtree/git-subtree.txt | 10 ++++++++++
 1 file changed, 10 insertions(+)
diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt
index c8fc103..48ba158 100644
--- a/contrib/subtree/git-subtree.txt
+++ b/contrib/subtree/git-subtree.txt
@@ -129,6 +129,16 @@ split::
 	Note that if you use '--squash' when you merge, you
 	should usually not just '--rejoin' when you split.
 
+from-submodule::
+	Convert a git submodule to a subtree.
+	The module is removed from the .gitmodules file and
+	the repo contents are integrated as a subtree.
+
+prune::
+	Cleanup .gittrees entries for which the subtree nolonger exists.
+
+diff::
+	TO BE DOCUMENTED
 
 OPTIONS
 -------
-- 
1.8.2.rc1

[PATCH v2 18/23] contrib/subtree: Add missing commands to SYNOPSIS

From: Paul Campbell <hidden>
Date: 2016-06-15 22:56:21

From: Herman van Rink <redacted>

Add pull-all, push-all, from-submodule, prune and diff commands
to SYNOPSIS.

Add alternate parameter option for add command.

Use long-form option for specifying prefix.

Signed-off-by: Paul Campbell <redacted>

Conflicts:
	contrib/subtree/git-subtree.txt
---
 contrib/subtree/git-subtree.txt | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt
index 48ba158..b485ab5 100644
--- a/contrib/subtree/git-subtree.txt
+++ b/contrib/subtree/git-subtree.txt
@@ -9,13 +9,16 @@ git-subtree - Merge subtrees together and split repository into subtrees
 SYNOPSIS
 --------
 [verse]
-'git subtree' add   -P <prefix> <refspec>
-'git subtree' add   -P <prefix> <repository> <refspec>
-'git subtree' pull  -P <prefix> <repository> <refspec...>
-'git subtree' push  -P <prefix> <repository> <refspec...>
-'git subtree' merge -P <prefix> <commit>
-'git subtree' split -P <prefix> [OPTIONS] [<commit>]
-
+'git subtree' add   --prefix=<prefix> <repository> <refspec>
+'git subtree' merge --prefix=<prefix> <commit>
+'git subtree' pull  --prefix=<prefix> [<repository> [<refspec>...]]
+'git subtree' pull-all
+'git subtree' push-all
+'git subtree' push  --prefix=<prefix> [<repository> [<refspec>...]]
+'git subtree' split --prefix=<prefix> <commit...>
+'git subtree' from-submodule --prefix=<prefix>
+'git subtree' prune
+'git subtree' diff  --prefix=<prefix> [<repository> [<refspec>...]]
 
 DESCRIPTION
 -----------
-- 
1.8.2.rc1

[PATCH v2 19/23] contrib/subtree: Document list command

From: Paul Campbell <hidden>
Date: 2016-06-15 22:56:21

From: Herman van Rink <redacted>

Signed-off-by: Paul Campbell <redacted>

Conflicts:
	git-subtree.sh
---
 contrib/subtree/git-subtree.sh  | 1 +
 contrib/subtree/git-subtree.txt | 4 ++++
 2 files changed, 5 insertions(+)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 84c90c7..4605203 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -15,6 +15,7 @@ git subtree pull  --prefix=<prefix> <repository> <refspec...>
 git subtree pull-all
 git subtree push-all
 git subtree push  --prefix=<prefix> <repository> <refspec...>
+git subtree list
 git subtree split --prefix=<prefix> <commit...>
 git subtree diff  --prefix=<prefix> [<repository> [<refspec>...]]
 git subtree from-submodule --prefix=<prefix>
diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt
index b485ab5..385bde8 100644
--- a/contrib/subtree/git-subtree.txt
+++ b/contrib/subtree/git-subtree.txt
@@ -15,6 +15,7 @@ SYNOPSIS
 'git subtree' pull-all
 'git subtree' push-all
 'git subtree' push  --prefix=<prefix> [<repository> [<refspec>...]]
+'git subtree' list
 'git subtree' split --prefix=<prefix> <commit...>
 'git subtree' from-submodule --prefix=<prefix>
 'git subtree' prune
@@ -108,6 +109,9 @@ push::
 push-all::
 	Perform a pull operation on all in .gittrees registered subtrees.
 
+list::
+	Show a list of the in .gittrees registered subtrees
+
 split::
 	Extract a new, synthetic project history from the
 	history of the <prefix> subtree.  The new history
-- 
1.8.2.rc1

[PATCH v2 20/23] contrib/subtree: Teach push to use --force option

From: Paul Campbell <hidden>
Date: 2016-06-15 22:56:21

From: James Roper <redacted>

Signed-off-by: Paul Campbell <redacted>

Conflicts:
	contrib/subtree/git-subtree.sh

Signed-off-by: Paul Campbell <redacted>
---
 contrib/subtree/git-subtree.sh  | 9 ++++++++-
 contrib/subtree/git-subtree.txt | 5 +++++
 2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 4605203..3582a55 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -32,6 +32,8 @@ b,branch=     create a new branch from the split subtree
 ignore-joins  ignore prior --rejoin commits
 onto=         try connecting new tree to an existing one
 rejoin        merge the new branch back into HEAD
+ options for 'push'
+f,force       use force push
  options for 'add', 'merge', 'pull' and 'push'
 squash        merge subtree changes as a single commit
 "
@@ -90,6 +92,7 @@ while [ $# -gt 0 ]; do
 		-b) branch="$1"; shift ;;
 		-P) prefix="$1"; shift ;;
 		-m) message="$1"; shift ;;
+        -f|--force) force=1 ;;
 		--no-prefix) prefix= ;;
 		--onto) onto="$1"; shift ;;
 		--no-onto) onto= ;;
@@ -790,10 +793,14 @@ cmd_push()
 	      repository=$(git config -f .gittrees subtree.$prefix.url)
         refspec=$(git config -f .gittrees subtree.$prefix.branch)
       fi
+        push_opts=
+        if [ "$force" == "1" ]; then 
+            push_opts="$push_opts --force"
+        fi
 	    echo "git push using: " $repository $refspec
 	    rev=$(git subtree split --prefix=$prefix)
 	    if [ -n "$rev" ]; then
-	        git push $repository $rev:refs/heads/$refspec
+	        git push $push_opts $repository $rev:refs/heads/$refspec
 	    else
 	        die "Couldn't push, 'git subtree split' failed."
 	    fi
diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt
index 385bde8..9e9eb9e 100644
--- a/contrib/subtree/git-subtree.txt
+++ b/contrib/subtree/git-subtree.txt
@@ -278,6 +278,11 @@ OPTIONS FOR split
 	'--rejoin' when you split, because you don't want the
 	subproject's history to be part of your project anyway.
 
+OPTIONS FOR push
+----------------
+-f::
+--force::
+    Uses 'git push --force'.
 
 EXAMPLE 1. Add command
 ----------------------
-- 
1.8.2.rc1

[PATCH v2 23/23] contrib/subtree: Fix order of case switches so default case is last

From: Paul Campbell <hidden>
Date: 2016-06-15 22:56:21

Signed-off-by: Paul Campbell <redacted>
---
 contrib/subtree/git-subtree.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index aaee6ae..fb6f044 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -113,9 +113,9 @@ prefix="${prefix%/}";
 command="$1"
 shift
 case "$command" in
-    add|merge|pull|from-submodule|pull-all|push-all|prune) default= ;;
+	add|merge|pull|pull-all|push-all|from-submodule|prune) default= ;;
+	split|push|diff|list) default="--default HEAD" ;;
 	*) die "Unknown command '$command'" ;;
-    split|push|diff|list) default="--default HEAD" ;;
 esac
 
 if [ -z "$prefix" -a "$command" != "pull-all" -a "$command" != "push-all" -a "$command" != "list" -a "$command" != "prune" ]; then
-- 
1.8.2.rc1

[PATCH v2 21/23] contrib/subtree: Convert spaces to tabs and remove some trailing whitespace

From: Paul Campbell <hidden>
Date: 2016-06-15 22:56:21

From: Herman van Rink <redacted>

Signed-off-by: Paul Campbell <redacted>

Conflicts:
	contrib/subtree/.gitignore
	contrib/subtree/git-subtree.sh
	contrib/subtree/test.sh
---

It's a nasty formatting only patch and I won't be surprised or too dissappiointed
if this doesn't make it. Or are the rules for this more lax for contrib? How else
can contrib be brought in-line with coding standards?

 contrib/subtree/git-subtree.sh | 213 +++++++++++++++++++++--------------------
 1 file changed, 109 insertions(+), 104 deletions(-)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 3582a55..263ea9f 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -92,7 +92,7 @@ while [ $# -gt 0 ]; do
 		-b) branch="$1"; shift ;;
 		-P) prefix="$1"; shift ;;
 		-m) message="$1"; shift ;;
-        -f|--force) force=1 ;;
+		-f|--force) force=1 ;;
 		--no-prefix) prefix= ;;
 		--onto) onto="$1"; shift ;;
 		--no-onto) onto= ;;
@@ -123,8 +123,10 @@ if [ -z "$prefix" -a "$command" != "pull-all" -a "$command" != "push-all" -a "$c
 fi
 
 case "$command" in
-    pull-all);;
-    push-all);;
+	pull-all);;
+	push-all);;
+	list);;
+	prune);;
 	add) [ -e "$prefix" ] && 
 		die "prefix '$prefix' already exists." ;;
 	*)   [ -e "$prefix" ] || 
@@ -541,14 +543,14 @@ cmd_add_repository()
 	revs=FETCH_HEAD
 	set -- $revs
 	cmd_add_commit "$@"
-  
-  # now add it to our list of repos 
-  git config -f .gittrees --unset subtree.$dir.url
-  git config -f .gittrees --add subtree.$dir.url $repository
-  git config -f .gittrees --unset subtree.$dir.path
-  git config -f .gittrees --add subtree.$dir.path $dir
-  git config -f .gittrees --unset subtree.$dir.branch
-  git config -f .gittrees --add subtree.$dir.branch $refspec
+
+	# now add it to our list of repos
+	git config -f .gittrees --unset subtree.$dir.url
+	git config -f .gittrees --add subtree.$dir.url $repository
+	git config -f .gittrees --unset subtree.$dir.path
+	git config -f .gittrees --add subtree.$dir.path $dir
+	git config -f .gittrees --unset subtree.$dir.branch
+	git config -f .gittrees --add subtree.$dir.branch $refspec
 }
 
 cmd_add_commit()
@@ -721,89 +723,91 @@ cmd_merge()
 
 cmd_pull()
 {
-  if [ $# -gt 2 ]; then
-	    die "You should provide either <refspec> or <repository> <refspec>"
+	if [ $# -gt 2 ]; then
+		die "You should provide either <refspec> or <repository> <refspec>"
 	fi
 	if [ -e "$dir" ]; then
-	    ensure_clean
-      if [ $# -eq 1 ]; then 
-	      repository=$(git config -f .gittrees subtree.$prefix.url)
-	      refspec=$1
-      elif [ $# -eq 2 ]; then 
-        repository=$1
-        refspec=$2
-      else 
-	      repository=$(git config -f .gittrees subtree.$prefix.url)
-        refspec=$(git config -f .gittrees subtree.$prefix.branch)
-      fi
-	    git fetch $repository $refspec || exit $?
-	    echo "git fetch using: " $repository $refspec
-	    revs=FETCH_HEAD
-	    set -- $revs
-	    cmd_merge "$@"
+		ensure_clean
+		if [ $# -eq 1 ]; then
+			repository=$(git config -f .gittrees subtree.$prefix.url)
+			refspec=$1
+		elif [ $# -eq 2 ]; then
+			repository=$1
+			refspec=$2
+		else
+			repository=$(git config -f .gittrees subtree.$prefix.url)
+			refspec=$(git config -f .gittrees subtree.$prefix.branch)
+		fi
+		git fetch $repository $refspec || exit $?
+		echo "git fetch using: " $repository $refspec
+		revs=FETCH_HEAD
+		set -- $revs
+		cmd_merge "$@"
 	else
-	    die "'$dir' must already exist. Try 'git subtree add'."
+		die "'$dir' must already exist. Try 'git subtree add'."
 	fi
 }
 
-cmd_diff() 
-{
-    if [ -e "$dir" ]; then
-        if [ $# -eq 1 ]; then 
-            repository=$(git config -f .gittrees subtree.$prefix.url)
-            refspec=$1
-        elif [ $# -eq 2 ]; then 
-            repository=$1
-            refspec=$2
-        else
-            repository=$(git config -f .gittrees subtree.$prefix.url)
-            refspec=$(git config -f .gittrees subtree.$prefix.branch)
-        fi
-        # this is ugly, but I don't know of a better way to do it. My git-fu is weak. 
-        # git diff-tree expects a treeish, but I have only a repository and branch name.
-        # I don't know how to turn that into a treeish without creating a remote.
-        # Please change this if you know a better way! 
-        tmp_remote=__diff-tmp
-        git remote rm $tmp_remote > /dev/null 2>&1
-        git remote add -t $refspec $tmp_remote $repository > /dev/null
-        # we fetch as a separate step so we can pass -q (quiet), which isn't an option for "git remote"
-        # could this instead be "git fetch -q $repository $refspec" and leave aside creating the remote?
-        # Still need a treeish for the diff-tree command...
-        git fetch -q $tmp_remote 
-        git diff-tree -p refs/remotes/$tmp_remote/$refspec
-        git remote rm $tmp_remote > /dev/null 2>&1
-    else 
-        die "Cannot resolve directory '$dir'. Please point to an existing subtree directory to diff. Try 'git subtree add' to add a subtree."
-    fi
+cmd_diff()
+{
+	if [ -e "$dir" ]; then
+		if [ $# -eq 1 ]; then
+			repository=$(git config -f .gittrees subtree.$prefix.url)
+			refspec=$1
+		elif [ $# -eq 2 ]; then
+			repository=$1
+			refspec=$2
+		else
+			repository=$(git config -f .gittrees subtree.$prefix.url)
+			refspec=$(git config -f .gittrees subtree.$prefix.branch)
+		fi
+		# this is ugly, but I don't know of a better way to do it. My git-fu is weak.
+		# git diff-tree expects a treeish, but I have only a repository and branch name.
+		# I don't know how to turn that into a treeish without creating a remote.
+		# Please change this if you know a better way!
+		tmp_remote=__diff-tmp
+		git remote rm $tmp_remote > /dev/null 2>&1
+		git remote add -t $refspec $tmp_remote $repository > /dev/null
+		# we fetch as a separate step so we can pass -q (quiet), which isn't an option for "git remote"
+		# could this instead be "git fetch -q $repository $refspec" and leave aside creating the remote?
+		# Still need a treeish for the diff-tree command...
+		git fetch -q $tmp_remote
+		git diff-tree -p refs/remotes/$tmp_remote/$refspec
+		git remote rm $tmp_remote > /dev/null 2>&1
+	else
+		die "Cannot resolve directory '$dir'. Please point to an existing subtree directory to diff. Try 'git subtree add' to add a subtree."
+	fi
 }
 
 cmd_push()
 {
 	if [ $# -gt 2 ]; then
-	    die "You shold provide either <refspec> or <repository> <refspec>"
+		die "You shold provide either <refspec> or <repository> <refspec>"
 	fi
 	if [ -e "$dir" ]; then
-      if [ $# -eq 1 ]; then 
-	      repository=$(git config -f .gittrees subtree.$prefix.url)
-        refspec=$1
-      elif [ $# -eq 2 ]; then 
-        repository=$1
-        refspec=$2
-      else
-	      repository=$(git config -f .gittrees subtree.$prefix.url)
-        refspec=$(git config -f .gittrees subtree.$prefix.branch)
-      fi
-        push_opts=
-        if [ "$force" == "1" ]; then 
-            push_opts="$push_opts --force"
-        fi
-	    echo "git push using: " $repository $refspec
-	    rev=$(git subtree split --prefix=$prefix)
-	    if [ -n "$rev" ]; then
-	        git push $push_opts $repository $rev:refs/heads/$refspec
-	    else
-	        die "Couldn't push, 'git subtree split' failed."
-	    fi
+		if [ $# -eq 1 ]; then
+			repository=$(git config -f .gittrees subtree.$prefix.url)
+			refspec=$1
+		elif [ $# -eq 2 ]; then
+			repository=$1
+			refspec=$2
+		else
+			repository=$(git config -f .gittrees subtree.$prefix.url)
+			refspec=$(git config -f .gittrees subtree.$prefix.branch)
+		fi
+
+		push_opts=
+		if [ "$force" == "1" ]; then
+		  push_opts="$push_opts --force"
+		fi
+
+		echo "git push using: " $repository $refspec
+		rev=$(git subtree split --prefix=$prefix)
+		if [ -n "$rev" ]; then
+			git push $push_opts $repository $rev:refs/heads/$refspec
+		else
+			die "Couldn't push, 'git subtree split' failed."
+		fi
 	else
 	    die "'$dir' must already exist. Try 'git subtree add'."
 	fi
@@ -831,6 +835,7 @@ cmd_from-submodule()
 	git commit -m "Remove '$prefix/' submodule"
 
 	# subtree add from submodule repo.
+	# TODO: Could be determin HEAD to be a specific branch
 	cmd_add_repository $tmp_repo HEAD
 
 	# Update .gittrees with the original repo url
@@ -841,46 +846,46 @@ cmd_from-submodule()
 	rm -rf $tmp_repo
 }
 
-subtree_list() 
+subtree_list()
 {
-    git config -f .gittrees -l | grep subtree | grep path | grep -o '=.*' | grep -o '[^=].*' |
-    while read path; do 
-        repository=$(git config -f .gittrees subtree.$path.url)
-        refspec=$(git config -f .gittrees subtree.$path.branch)
-        echo "    $path        (merged from $repository branch $refspec) "
-    done
+	git config -f .gittrees -l | grep subtree | grep path | grep -o '=.*' | grep -o '[^=].*' |
+	while read path; do
+		repository=$(git config -f .gittrees subtree.$path.url)
+		refspec=$(git config -f .gittrees subtree.$path.branch)
+		echo "	$path		(merged from $repository branch $refspec) "
+	done
 }
 
 cmd_list()
 {
-  subtree_list 
+  subtree_list
 }
 
 cmd_prune()
 {
-    git config -f .gittrees -l | grep subtree | grep path | grep -o '=.*' | grep -o '[^=].*' |
-    while read path; do
-        if [ ! -e "$path" ]; then
-            echo "pruning $path"
-            git config -f .gittrees --remove-section subtree.$path
-        fi
-    done
+	git config -f .gittrees -l | grep subtree | grep path | grep -o '=.*' | grep -o '[^=].*' |
+	while read path; do
+		if [ ! -e "$path" ]; then
+			echo "pruning $path"
+			git config -f .gittrees --remove-section subtree.$path
+		fi
+	done
 }
 
 cmd_pull-all()
 {
-    git config -f .gittrees -l | grep subtree | grep path | grep -o '=.*' | grep -o '[^=].*' |
-        while read path; do
-            git subtree pull -P $path master || exit $?
-        done
+	git config -f .gittrees -l | grep subtree | grep path | grep -o '=.*' | grep -o '[^=].*' |
+	while read path; do
+		git subtree pull -P $path $(git config -f .gittrees subtree.$path.url) $(git config -f .gittrees subtree.$path.branch) || exit $?
+	done
 }
 
 cmd_push-all()
 {
-    git config -f .gittrees -l | grep subtree | grep path | grep -o '=.*' | grep -o '[^=].*' |
-        while read path; do
-            git subtree push -P $path master || exit $?
-        done
+	git config -f .gittrees -l | grep subtree | grep path | grep -o '=.*' | grep -o '[^=].*' |
+	while read path; do
+		git subtree push -P $path $(git config -f .gittrees subtree.$path.url) $(git config -f .gittrees subtree.$path.branch) || exit $?
+	done
 }
 
 "cmd_$command" "$@"
-- 
1.8.2.rc1

[PATCH v2 22/23] contrib/subtree: Parameters repository/branch for push/pull are optional

From: Paul Campbell <hidden>
Date: 2016-06-15 22:56:21

Signed-off-by: Paul Campbell <redacted>
---
 contrib/subtree/git-subtree.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 263ea9f..aaee6ae 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -11,10 +11,10 @@ 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 pull  --prefix=<prefix> [<repository> [<refspec>...]]
 git subtree pull-all
 git subtree push-all
-git subtree push  --prefix=<prefix> <repository> <refspec...>
+git subtree push  --prefix=<prefix> [<repository> [<refspec>...]]
 git subtree list
 git subtree split --prefix=<prefix> <commit...>
 git subtree diff  --prefix=<prefix> [<repository> [<refspec>...]]
-- 
1.8.2.rc1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help