# [TopGit PATCH] tg-patch: fix invocation in sub working tree directory

6 messages from 2009-03-16 to 2009-03-17. Participants: Bert Wesarg, Junio C Hamano, Uwe Kleine-König.
Thread: https://gitlist.dev/t/18334

## Bert Wesarg, 2009-03-16 22:08

Subject: [TopGit PATCH] tg-patch: fix invocation in sub working tree directory
Message-ID: <1237241299-25515-1-git-send-email-bert.wesarg@googlemail.com>
URL: https://gitlist.dev/e/1237241299-25515-1-git-send-email-bert.wesarg%40googlemail.com

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

Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>

---
 tg-patch.sh |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/tg-patch.sh b/tg-patch.sh
index d701c54..e33bab2 100644
--- a/tg-patch.sh
+++ b/tg-patch.sh
@@ -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
-- 
tg: (d145a7b..) bw/fix-tg-patch-in-sub-dir (depends on: master)

```

## Junio C Hamano, 2009-03-16 22:33

Subject: Re: [TopGit PATCH] tg-patch: fix invocation in sub working tree directory
Message-ID: <7vbps1umg9.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vbps1umg9.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <1237241299-25515-1-git-send-email-bert.wesarg@googlemail.com>

```
Bert Wesarg <bert.wesarg@googlemail.com> writes:

> 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"?

> 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.
>
> Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
>
> ---
>  tg-patch.sh |    7 ++++++-
>  1 files changed, 6 insertions(+), 1 deletions(-)
>
> diff --git a/tg-patch.sh b/tg-patch.sh
> index d701c54..e33bab2 100644
> --- a/tg-patch.sh
> +++ b/tg-patch.sh
> @@ -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?

```

## Bert Wesarg, 2009-03-16 23:25

Subject: Re: [TopGit PATCH] tg-patch: fix invocation in sub working tree directory
Message-ID: <36ca99e90903161625x317556f4hc826aabd01494ca0@mail.gmail.com>
URL: https://gitlist.dev/e/36ca99e90903161625x317556f4hc826aabd01494ca0%40mail.gmail.com
In-Reply-To: <7vbps1umg9.fsf@gitster.siamese.dyndns.org>

```
On Mon, Mar 16, 2009 at 23:33, Junio C Hamano <gitster@pobox.com> wrote:
> Bert Wesarg <bert.wesarg@googlemail.com> writes:
>
>> 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.

>
>> 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.
>>
>> Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
>>
>> ---
>>  tg-patch.sh |    7 ++++++-
>>  1 files changed, 6 insertions(+), 1 deletions(-)
>>
>> diff --git a/tg-patch.sh b/tg-patch.sh
>> index d701c54..e33bab2 100644
>> --- a/tg-patch.sh
>> +++ b/tg-patch.sh
>> @@ -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?
Do 'git rev-parse --show-cdup' return anything other than slashes and dots?

Bert

```

## Junio C Hamano, 2009-03-17 00:24

Subject: Re: [TopGit PATCH] tg-patch: fix invocation in sub working tree directory
Message-ID: <7vwsapt2rw.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vwsapt2rw.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <36ca99e90903161625x317556f4hc826aabd01494ca0@mail.gmail.com>

```
Bert Wesarg <bert.wesarg@googlemail.com> writes:

> On Mon, Mar 16, 2009 at 23:33, Junio C Hamano <gitster@pobox.com> wrote:
>> Bert Wesarg <bert.wesarg@googlemail.com> writes:
>>
>>> 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).

```

## Uwe Kleine-König, 2009-03-17 08:02

Subject: Re: [TopGit PATCH] tg-patch: fix invocation in sub working tree directory
Message-ID: <20090317080211.GA21794@pengutronix.de>
URL: https://gitlist.dev/e/20090317080211.GA21794%40pengutronix.de
In-Reply-To: <1237241299-25515-1-git-send-email-bert.wesarg@googlemail.com>

```
On Mon, Mar 16, 2009 at 11:08:19PM +0100, Bert Wesarg wrote:
> 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

-- 
Pengutronix e.K.                              | Uwe Kleine-König            |
Industrial Linux Solutions                    | http://www.pengutronix.de/  |

```

## Uwe Kleine-König, 2009-03-17 08:33

Subject: Re: [TopGit PATCH] tg-patch: fix invocation in sub working tree directory
Message-ID: <20090317083326.GA22384@pengutronix.de>
URL: https://gitlist.dev/e/20090317083326.GA22384%40pengutronix.de
In-Reply-To: <1237241299-25515-1-git-send-email-bert.wesarg@googlemail.com>

```
Hello again,

On Mon, Mar 16, 2009 at 11:08:19PM +0100, Bert Wesarg wrote:
> --- a/tg-patch.sh
> +++ b/tg-patch.sh
> @@ -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"} --
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

-- 
Pengutronix e.K.                              | Uwe Kleine-König            |
Industrial Linux Solutions                    | http://www.pengutronix.de/  |

```
