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

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

From
Paul Campbell <pcampbell@kemitix.net>
Date
Mar 10, 2013, 23:41 UTC
Message-ID
<1362958891-26941-11-git-send-email-pcampbell@kemitix.net>
In-Reply-To
<1362958891-26941-1-git-send-email-pcampbell@kemitix.net>
From: Matt Hoffman <matt.hoffman@quantumretail.com>

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 <pcampbell@kemitix.net>
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
Previous: Paul CampbellNext: Paul Campbell
Message 20 of 33 in “contrib/subtree: Collected updates”
  1. 00/23 contrib/subtree: Collected updatesPaul Campbell, Mar 10, 2013
  2. 01/23 contrib/subtree: Fix typo (s/incldued/included/)Paul Campbell, Mar 10, 2013
  3. 02/23 contrib/subtree: Add command from-submodulePaul Campbell, Mar 10, 2013
  4. Junio C HamanoMar 11, 2013
  5. contrib/subtree: Add command from-submodulePaul Campbell, Mar 24, 2013
  6. 03/23 contrib/subtree: Teach add to store repository & branch in .gittreesPaul Campbell, Mar 10, 2013
  7. Junio C HamanoMar 11, 2013
  8. Paul CampbellMar 24, 2013
  9. contrib/subtree: Teach add to store repository & branch in .gittreesPaul Campbell, Mar 24, 2013
  10. 04/23 contrib/subtree: Teach push and pull to use .gittrees for defaultsPaul Campbell, Mar 10, 2013
  11. Junio C HamanoMar 11, 2013
  12. Paul CampbellMar 24, 2013
  13. 05/23 contrib/subtree: Add commands pull_all and push_allPaul Campbell, Mar 10, 2013
  14. Junio C HamanoMar 11, 2013
  15. Paul CampbellMar 11, 2013
  16. 06/23 contrib/subtree: Rename commands push_all/pull_all to push-all/pull-allPaul Campbell, Mar 10, 2013
  17. 07/23 contrib/subtree: Teach push and pull to use .gittrees if neededPaul Campbell, Mar 10, 2013
  18. 08/23 contrib/subtree: Replace invisible carriage return with a visible \rPaul Campbell, Mar 10, 2013
  19. 09/23 contrib/subtree: Teach push to abort if split failsPaul Campbell, Mar 10, 2013
  20. 10/23 contrib/subtree: Add command diffPaul Campbell, Mar 10, 2013
  21. 11/23 contrib/subtree: Add command listPaul Campbell, Mar 10, 2013
  22. 12/23 contrib/subtree: Add command prunePaul Campbell, Mar 10, 2013
  23. 13/23 contrib/subtree: Add prune command to OPTS_SPECPaul Campbell, Mar 10, 2013
  24. 14/23 contrib/subtree: Remove trailing slash from prefix parameterPaul Campbell, Mar 10, 2013
  25. 15/23 contrib/subtree: Teach from-submodule to add new subtree to .gittreesPaul Campbell, Mar 10, 2013
  26. 16/23 contrib/subtree: Document pull-all and push-allPaul Campbell, Mar 10, 2013
  27. 17/23 contrib/subtree: Document from-submodule and prune commandsPaul Campbell, Mar 10, 2013
  28. 18/23 contrib/subtree: Add missing commands to SYNOPSISPaul Campbell, Mar 10, 2013
  29. 19/23 contrib/subtree: Document list commandPaul Campbell, Mar 10, 2013
  30. 20/23 contrib/subtree: Teach push to use --force optionPaul Campbell, Mar 10, 2013
  31. 21/23 contrib/subtree: Convert spaces to tabs and remove some trailing whitespacePaul Campbell, Mar 10, 2013
  32. 22/23 contrib/subtree: Parameters repository/branch for push/pull are optionalPaul Campbell, Mar 10, 2013
  33. 23/23 contrib/subtree: Fix order of case switches so default case is lastPaul Campbell, Mar 10, 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.