Skip to contentSkip to conversation

tg-patch: fix invocation in sub working tree directory

PATCH In review Bert Wesarg 3 participants 6 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tg-patch: fix invocation in sub working tree directory

tg patch won't work in a sub directory of the working tree, because 'git diff --name-only' prints the names relative to the top working tree.

This is only a quick fix which prefixes all file names with 'git rev-parse --show-cdup'. The right solution would be to cd into the top working tree somewhere in tg.sh.

---
 tg-patch.sh |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
tg-patch.sh +6 -1
index d701c54..e33bab2 100644
@@ -50,13 +50,18 @@ cat_file "$topic:.topmsg"
 echo
 [ -n "$(git grep $diff_opts '^[-]--' ${diff_committed_only:+"$name"} -- ".topmsg")" ] || echo '---'
 
+# if we are in a sub working tree dir, we need to prefix all file names from
+# git diff --name-only with this cdup
+cdup=$(git rev-parse --show-cdup)
+
 # Evil obnoxious hack to work around the lack of git diff --exclude
 git_is_stupid="$(mktemp -t tg-patch-changes.XXXXXX)"
 git diff --name-only $diff_opts "$base_rev" ${diff_committed_only:+"$name"} -- |
 	fgrep -vx ".topdeps" |
 	fgrep -vx ".topmsg" >"$git_is_stupid" || : # fgrep likes to fail randomly?
 if [ -s "$git_is_stupid" ]; then
-	cat "$git_is_stupid" | xargs git diff --patch-with-stat $diff_opts "$base_rev" ${diff_committed_only:+"$name"} --
+	sed -e "s#^#$cdup#" "$git_is_stupid" |
+		xargs git diff --patch-with-stat $diff_opts "$base_rev" ${diff_committed_only:+"$name"} --
 else
 	echo "No changes."
 fi
Signature · 1 line
tg: (d145a7b..) bw/fix-tg-patch-in-sub-dir (depends on: master)
#1 lore raw
Quoted 2 lines · Bert Wesarg

tg patch won't work in a sub directory of the working tree, because 'git diff --name-only' prints the names relative to the top working tree.

Hhhm, that's not exactly the problem.

	git diff --patch-with-stat 45c82b5 t/trivial/typo-kernel -- $path

expects $path to be relative to the top working tree.

IMHO this is a strange behaviour of core git when comparing two trees (and not a tree and the wc). Moreover as the output uses "absolute" paths:

	ukleinek@cassiopeia:~/gsrc/linux-2.6/fs$ git diff --patch-with-stat 45c82b5 t/trivial/typo-kernel -- proc/nommu.c | diffstat -p0
 b/fs/proc/nommu.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                              | Uwe Kleine-König            |
Industrial Linux Solutions                    | http://www.pengutronix.de/  |
#2 lore raw
In reply to Bert Wesarg

Hello again,

Quoted 9 lines · Bert Wesarg
tg-patch.sh +3 -0
@@ -50,13 +50,18 @@ cat_file "$topic:.topmsg"
 echo
 [ -n "$(git grep $diff_opts '^[-]--' ${diff_committed_only:+"$name"} -- ".topmsg")" ] || echo '---'
 
+# if we are in a sub working tree dir, we need to prefix all file names from
+# git diff --name-only with this cdup
+cdup=$(git rev-parse --show-cdup)

tg-patch.sh cat_file "$topic:.topmsg" · line 64

Quoted 10 lines
tg-patch.sh +3 -1
+
 # Evil obnoxious hack to work around the lack of git diff --exclude
 git_is_stupid="$(mktemp -t tg-patch-changes.XXXXXX)"
 git diff --name-only $diff_opts "$base_rev" ${diff_committed_only:+"$name"} -- |
 	fgrep -vx ".topdeps" |
 	fgrep -vx ".topmsg" >"$git_is_stupid" || : # fgrep likes to fail randomly?
 if [ -s "$git_is_stupid" ]; then
-	cat "$git_is_stupid" | xargs git diff --patch-with-stat $diff_opts "$base_rev" ${diff_committed_only:+"$name"} --
+	sed -e "s#^#$cdup#" "$git_is_stupid" |
+		xargs git diff --patch-with-stat $diff_opts "$base_rev" ${diff_committed_only:+"$name"} --

My not move pretty_tree from tg-export.sh to tg.sh and use that. i.e.

	git diff $someopts "$(pretty_tree "$base_rev")" "$(pretty_tree "...")"

then we wouldn't need that git_is_stupid-hack and the relative path name thinggy wouldn hurt us.

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                              | Uwe Kleine-König            |
Industrial Linux Solutions                    | http://www.pengutronix.de/  |
#3 lore raw
In reply to Bert Wesarg
Quoted 2 lines · Bert Wesarg

tg patch won't work in a sub directory of the working tree, because 'git diff --name-only' prints the names relative to the top working tree.

"diff --relative --name-only"?

Quoted 15 lines

This is only a quick fix which prefixes all file names with 'git rev-parse --show-cdup'. The right solution would be to cd into the top working tree somewhere in tg.sh.

---
 tg-patch.sh |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
tg-patch.sh +0 -0
index d701c54..e33bab2 100644

tg-patch.sh cat_file "$topic:.topmsg" · line 63

Quoted 8 lines
tg-patch.sh +4 -0
@@ -50,13 +50,18 @@ cat_file "$topic:.topmsg"
 echo
 [ -n "$(git grep $diff_opts '^[-]--' ${diff_committed_only:+"$name"} -- ".topmsg")" ] || echo '---'
 
+# if we are in a sub working tree dir, we need to prefix all file names from
+# git diff --name-only with this cdup
+cdup=$(git rev-parse --show-cdup)
...
+	sed -e "s#^#$cdup#" "$git_is_stupid" |

Do TopGit folks care about special characters in pathnames?

#4 lore raw
Quoted 6 lines · Junio C Hamano
Quoted 2 lines · Bert Wesarg

tg patch won't work in a sub directory of the working tree, because 'git diff --name-only' prints the names relative to the top working tree.

"diff --relative --name-only"?

No, unfortunately. In my bug case the changed file was in another subtree, and --relative restricts the output to only files under the current subtree.

Quoted 19 lines
Quoted 19 lines

This is only a quick fix which prefixes all file names with 'git rev-parse --show-cdup'. The right solution would be to cd into the top working tree somewhere in tg.sh.

---
 tg-patch.sh |    7 ++++++-

 1 files changed, 6 insertions(+), 1 deletions(-)
tg-patch.sh +0 -0
index d701c54..e33bab2 100644
@@ -50,13 +50,18 @@ cat_file "$topic:.topmsg"

 echo
 [ -n "$(git grep $diff_opts '^[-]--' ${diff_committed_only:+"$name"} -- ".topmsg")" ] || echo '---'

Quoted 7 lines

tg-patch.sh cat_file "$topic:.topmsg" · line 63

Quoted 5 lines
tg-patch.sh +4 -0
+# if we are in a sub working tree dir, we need to prefix all file names from
+# git diff --name-only with this cdup
+cdup=$(git rev-parse --show-cdup)
...
+     sed -e "s#^#$cdup#" "$git_is_stupid" |

Do TopGit folks care about special characters in pathnames?

Do 'git rev-parse --show-cdup' return anything other than slashes and dots?

Bert

#5 lore raw
Quoted 11 lines · Bert Wesarg
Quoted 6 lines · Junio C Hamano
Quoted 2 lines · Bert Wesarg

tg patch won't work in a sub directory of the working tree, because 'git diff --name-only' prints the names relative to the top working tree.

"diff --relative --name-only"?

No, unfortunately. In my bug case the changed file was in another subtree, and --relative restricts the output to only files under the current subtree.

Ah, Ok, then insertion of cdup output does make sense (after all cdup was designed to be used that way).