{"thread":{"id":"48621","subject":"[PATCH] f4b04cf65 (\"git-subtree: I suggest to add following lines into commit message\", 2018-05-31)","startedAt":"2018-06-01T05:21:05Z","lastAt":"2018-06-01T05:21:05Z","messageCount":1,"participants":["kx"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"348972","messageId":"8c9290a4a097e490b243c64e1f362327@radix.pro","threadId":"48621","inReplyTo":null,"subject":"[PATCH] f4b04cf65 (\"git-subtree: I suggest to add following lines into commit message\", 2018-05-31)","fromName":"kx","fromEmail":"kx@radix.pro","sentAt":"2018-06-01T05:09:33Z","receivedAt":"2018-06-01T05:21:05Z","isPatch":true,"sender":{"key":"kx@radix.pro","avatar":null},"body":" From f4b04cf65c4b220c8127ed2692c057fab76392a9 Mon Sep 17 00:00:00 2001\n From: kx <kx@radix.pro>\nDate: Thu, 31 May 2018 22:47:49 +0300\nSubject: [PATCH 1/3] I suggest to add following lines into commit \nmessage\n  created by 'git subtree add' command:\n\n     git-subtree-repo: https://github.com/.../remote.git\n     git-subtree-ref: master\n\nthis allow us to list externals using 'git subtree --list':\n\nfoo https://github.com/.../remote.git branch master HEAD\n\nAnd also when option '-d' is applayed and remote repository\nhas been updated we can show help message like following:\n\n$ git subtree -d --list\nLooking for externals...\n\nCommit: cc0436022362174bf04b0aac504913d4ccbd8b90\nfoo https://github.com/.../remote.git branch master HEAD\n\nThe 'foo' subtree seems not updated:\n    original revision: e46649ead5b895cd8d27be734241f50fff4daa60\n     reemote revision: b23fec043212d37e549c9c1515ea3b2a955206df\nYou can update 'foo' subtree by following command:\n\n    git subtree pull --prefix=foo https://github.com/.../remote.git \nmaster\n---\n  contrib/subtree/git-subtree.sh  | 141 ++++++++++++++++++++++++++++++++\n  contrib/subtree/git-subtree.txt |   5 ++\n  2 files changed, 146 insertions(+)\n\ndiff --git a/contrib/subtree/git-subtree.sh \nb/contrib/subtree/git-subtree.sh\nindex d3f39a862..969649530 100755\n--- a/contrib/subtree/git-subtree.sh\n+++ b/contrib/subtree/git-subtree.sh\n@@ -15,8 +15,10 @@ git subtree merge --prefix=<prefix> <commit>\n  git subtree pull  --prefix=<prefix> <repository> <ref>\n  git subtree push  --prefix=<prefix> <repository> <ref>\n  git subtree split --prefix=<prefix> <commit...>\n+git subtree --list\n  --\n  h,help        show the help\n+l,list        show externals\n  q             quiet\n  d             show debug messages\n  P,prefix=     the name of the subdir to split out\n@@ -48,6 +50,9 @@ annotate=\n  squash=\n  message=\n  prefix=\n+repo=\n+ref=\n+list=\n\n  debug () {\n  \tif test -n \"$debug\"\n@@ -77,6 +82,119 @@ assert () {\n  \tfi\n  }\n\n+show_externals () {\n+  debug \"Looking for externals...\"\n+  dir=\n+  rev=\n+  updated=\n+  commit=\n+  repo=\n+  ref=\n+  git log --grep=\"^git-subtree-dir: .*\\$\" \\\n+          --no-show-signature --pretty=format:'START \n%H%n%s%n%n%b%nEND%n' |\n+  while read a b junk\n+  do\n+    case \"$a\" in\n+    START)\n+      commit=\"$b\"\n+      ;;\n+    git-subtree-dir:)\n+      if test -n \"$dir\"\n+      then\n+        if test \"$dir\" = \"$b\"\n+        then\n+          break\n+        fi\n+      fi\n+      dir=\"$b\"\n+      ;;\n+    git-subtree-split:)\n+      rev=\"$b\"\n+      ;;\n+    git-subtree-repo:)\n+      repo=\"$b\"\n+      ;;\n+    git-subtree-ref:)\n+      ref=\"$b\"\n+      ;;\n+    END)\n+      if test -n \"$dir\" -a -e \"$dir\"\n+      then\n+        debug \"\"\n+        debug \"Commit: $commit\"\n+        if test -n \"$repo\"\n+        then\n+          output=\"$(git ls-remote $repo)\"\n+          if test -n \"$ref\"\n+          then\n+            if $(echo \"$output\" | grep -q $ref)\n+            then\n+              hash=\"$(echo \"$output\" | grep \"$ref\\$\" | cut -f1 \n-d$'\\t')\"\n+              if test \"$hash\" != \"$rev\"\n+              then\n+                updated=\"$rev\"\n+                rev=\"$hash\"\n+              fi\n+            fi\n+          fi\n+\n+          output=\"$(echo \"$output\" | grep $rev)\"\n+          if test -n \"$output\"\n+          then\n+            echo \"$output\" |\n+            while read h r junk\n+            do\n+              case \"$r\" in\n+                HEAD)\n+                  head=\"yes\"\n+                  ;;\n+                refs/heads/*)\n+                  name=$(basename $r)\n+                  type=\"branch\"\n+                  echo -n \"$dir $repo $type $name\"\n+                  if test \"$head\" = \"yes\"\n+                  then\n+                    echo \" HEAD\"\n+                  else\n+                    echo \" $rev\"\n+                  fi\n+                  break\n+                  ;;\n+                refs/tags/*)\n+                  name=$(basename $r)\n+                  type=\"tag\"\n+                  echo \"$dir $repo $type $name $rev\"\n+                  break\n+                  ;;\n+              esac\n+            done\n+            if test -n \"$updated\"\n+            then\n+              debug \"\"\n+              debug \"The '$dir' subtree seems not updated:\"\n+              debug \"   original revision: $updated\"\n+              debug \"    reemote revision: $rev\"\n+              debug \"You can update '$dir' subtree by following \ncommand:\"\n+              debug \"\"\n+              debug \"   git subtree pull --prefix=$dir $repo $ref\"\n+              debug \"\"\n+            fi\n+          fi\n+        else\n+          echo \"$dir $rev\"\n+        fi\n+      fi\n+\n+      rev=\n+      updated=\n+      commit=\n+      repo=\n+      ref=\n+      ;;\n+    esac\n+  done\n+}\n+\n\n  while test $# -gt 0\n  do\n@@ -137,6 +255,9 @@ do\n  \t--no-squash)\n  \t\tsquash=\n  \t\t;;\n+\t-l)\n+\t\tlist=yes\n+\t\t;;\n  \t--)\n  \t\tbreak\n  \t\t;;\n@@ -149,6 +270,12 @@ done\n  command=\"$1\"\n  shift\n\n+if test \"$list\" = \"yes\"\n+then\n+  show_externals\n+  exit 0\n+fi\n+\n  case \"$command\" in\n  add|merge|pull)\n  \tdefault=\n@@ -421,6 +548,18 @@ add_msg () {\n  \t\tgit-subtree-mainline: $latest_old\n  \t\tgit-subtree-split: $latest_new\n  \tEOF\n+\tif test -n \"$repo\"\n+\tthen\n+\t\tcat <<-EOF\n+\t\t\tgit-subtree-repo: $repo\n+\t\tEOF\n+\tfi\n+\tif test -n \"$ref\"\n+\tthen\n+\t\tcat <<-EOF\n+\t\t\tgit-subtree-ref: $ref\n+\t\tEOF\n+\tfi\n  }\n\n  add_squashed_msg () {\n@@ -622,6 +761,8 @@ cmd_add () {\n  \t\t# branches fetched via the refspec.\n  \t\tensure_valid_ref_format \"$2\"\n\n+\t\trepo=$1\n+\t\tref=$2\n  \t\tcmd_add_repository \"$@\"\n  \telse\n  \t\tsay \"error: parameters were '$@'\"\ndiff --git a/contrib/subtree/git-subtree.txt \nb/contrib/subtree/git-subtree.txt\nindex 352deda69..4927f9767 100644\n--- a/contrib/subtree/git-subtree.txt\n+++ b/contrib/subtree/git-subtree.txt\n@@ -15,6 +15,7 @@ SYNOPSIS\n  'git subtree' push  -P <prefix> <repository> <ref>\n  'git subtree' merge -P <prefix> <commit>\n  'git subtree' split -P <prefix> [OPTIONS] [<commit>]\n+'git subtree' --list\n\n\n  DESCRIPTION\n@@ -131,6 +132,10 @@ OPTIONS\n  --debug::\n  \tProduce even more unnecessary output messages on stderr.\n\n+-l::\n+--list::\n+\tPrint the list of joined subtrees and exit.\n+\n  -P <prefix>::\n  --prefix=<prefix>::\n  \tSpecify the path in the repository to the subtree you\n-- \n2.17.1\n\n\n From cf93ca929b25b948ee41fb921a466205fe979dd1 Mon Sep 17 00:00:00 2001\n From: kx <kx@radix.pro>\nDate: Fri, 1 Jun 2018 00:15:02 +0300\nSubject: [PATCH 2/3] show same subtree once\n\n---\n  contrib/subtree/git-subtree.sh | 4 +++-\n  1 file changed, 3 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/subtree/git-subtree.sh \nb/contrib/subtree/git-subtree.sh\nindex 969649530..65361a2f3 100755\n--- a/contrib/subtree/git-subtree.sh\n+++ b/contrib/subtree/git-subtree.sh\n@@ -85,6 +85,7 @@ assert () {\n  show_externals () {\n    debug \"Looking for externals...\"\n    dir=\n+  pass=\n    rev=\n    updated=\n    commit=\n@@ -118,8 +119,9 @@ show_externals () {\n        ref=\"$b\"\n        ;;\n      END)\n-      if test -n \"$dir\" -a -e \"$dir\"\n+      if test -n \"$dir\" -a -e \"$dir\" -a \"$dir\" != \"$pass\"\n        then\n+        pass=\"$dir\"\n          debug \"\"\n          debug \"Commit: $commit\"\n          if test -n \"$repo\"\n-- \n2.17.1\n\n\n From 548d1a7a739e6d94a4ae0db0dd77953b3cc84010 Mon Sep 17 00:00:00 2001\n From: kx <kx@radix.pro>\nDate: Fri, 1 Jun 2018 01:36:06 +0300\nSubject: [PATCH 3/3] fix situation when one dirname is a substring of \nother\n  dirname\n\n---\n  contrib/subtree/git-subtree.sh | 4 ++--\n  1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/contrib/subtree/git-subtree.sh \nb/contrib/subtree/git-subtree.sh\nindex 65361a2f3..f7326c986 100755\n--- a/contrib/subtree/git-subtree.sh\n+++ b/contrib/subtree/git-subtree.sh\n@@ -119,9 +119,9 @@ show_externals () {\n        ref=\"$b\"\n        ;;\n      END)\n-      if test -n \"$dir\" -a -e \"$dir\" -a \"$dir\" != \"$pass\"\n+      if test -n \"$dir\" -a -e \"$dir\" -a -z \"$(echo -e \"$pass\" | grep \n\"$dir\\$\")\"\n        then\n-        pass=\"$dir\"\n+        pass=\"$pass\\n$dir\\n\"\n          debug \"\"\n          debug \"Commit: $commit\"\n          if test -n \"$repo\"\n-- \n2.17.1\n\n"}]}