zsh-workers
 help / color / mirror / code / Atom feed
* [BUG] vcs_info '%r' doesn't work properly when entered a subdirectory of a git repository through a symlink
@ 2013-11-21  1:45 Hong Xu
  2013-11-21 16:16 ` Bart Schaefer
  2013-11-21 23:13 ` Aaron Schrab
  0 siblings, 2 replies; 10+ messages in thread
From: Hong Xu @ 2013-11-21  1:45 UTC (permalink / raw)
  To: zsh-workers

Hi all,

The vcs_info '%r' generally works perfect, but when I symlinked a 
subdirectory of the root dir of the git repository to somewhere else, 
and cd from the symlink, '%r' doesn't show the correct value, while the 
git repository can be recognized by zsh.

Example:

mkdir -p tmp/repo/sub
cd tmp/repo
git init
ln -s $(pwd)/sub $HOME/sub
cd ~/sub

Then you will see '%r' is not the root directory of the repo (for me 
it's my home directory basename).

Thanks,
Hong


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [BUG] vcs_info '%r' doesn't work properly when entered a subdirectory of a git repository through a symlink
  2013-11-21  1:45 [BUG] vcs_info '%r' doesn't work properly when entered a subdirectory of a git repository through a symlink Hong Xu
@ 2013-11-21 16:16 ` Bart Schaefer
  2013-11-21 19:12   ` Hong Xu
  2013-11-21 23:13 ` Aaron Schrab
  1 sibling, 1 reply; 10+ messages in thread
From: Bart Schaefer @ 2013-11-21 16:16 UTC (permalink / raw)
  To: zsh-workers

On Nov 20,  5:45pm, Hong Xu wrote:
} Subject: [BUG] vcs_info '%r' doesn't work properly when entered a subdirec
}
} The vcs_info '%r' generally works perfect, but when I symlinked a 
} subdirectory of the root dir of the git repository to somewhere else, 
} and cd from the symlink, '%r' doesn't show the correct value

This is coming from VCS_INFO_get_data_git, in this expression:

gitbase=${PWD%/${$( ${vcs_comm[cmd]} rev-parse --show-prefix )%/##}}

This is computing the value for %R, which is then converted with the :t
modifier into a path tail for %r.

I believe the issue is that because you've symlink'd your way into a
subdirectory, $PWD no longer includes the full path that is being
returned by --show-prefix, so the substitution does nothing.

What I don't know is the desired outcome.  Try replacing $PWD in that
function with $(pwd -P) and see if that gives you what you want?  Is
that what everyone would expect here?


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [BUG] vcs_info '%r' doesn't work properly when entered a subdirectory of a git repository through a symlink
  2013-11-21 16:16 ` Bart Schaefer
@ 2013-11-21 19:12   ` Hong Xu
  0 siblings, 0 replies; 10+ messages in thread
From: Hong Xu @ 2013-11-21 19:12 UTC (permalink / raw)
  To: Bart Schaefer, zsh-workers

On 11/21/13, 8:16 AM, Bart Schaefer wrote:
> On Nov 20,  5:45pm, Hong Xu wrote:
> } Subject: [BUG] vcs_info '%r' doesn't work properly when entered a subdirec
> }
> } The vcs_info '%r' generally works perfect, but when I symlinked a
> } subdirectory of the root dir of the git repository to somewhere else,
> } and cd from the symlink, '%r' doesn't show the correct value
>
> This is coming from VCS_INFO_get_data_git, in this expression:
>
> gitbase=${PWD%/${$( ${vcs_comm[cmd]} rev-parse --show-prefix )%/##}}
>
> This is computing the value for %R, which is then converted with the :t
> modifier into a path tail for %r.
>
> I believe the issue is that because you've symlink'd your way into a
> subdirectory, $PWD no longer includes the full path that is being
> returned by --show-prefix, so the substitution does nothing.
>
> What I don't know is the desired outcome.  Try replacing $PWD in that
> function with $(pwd -P) and see if that gives you what you want?  Is
> that what everyone would expect here?
>

Hi Bart,

Yes, $(pwd -P) indeed gives the correct %r. However, %S is incorrect then...

Hong


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re:  vcs_info '%r' doesn't work properly when entered a subdirectory of a git repository through a symlink
  2013-11-21  1:45 [BUG] vcs_info '%r' doesn't work properly when entered a subdirectory of a git repository through a symlink Hong Xu
  2013-11-21 16:16 ` Bart Schaefer
@ 2013-11-21 23:13 ` Aaron Schrab
  2013-11-21 23:26   ` Aaron Schrab
  2013-11-22  0:10   ` Bart Schaefer
  1 sibling, 2 replies; 10+ messages in thread
From: Aaron Schrab @ 2013-11-21 23:13 UTC (permalink / raw)
  To: Hong Xu; +Cc: zsh-workers

At 17:45 -0800 20 Nov 2013, Hong Xu <hong@topbug.net> wrote:
>The vcs_info '%r' generally works perfect, but when I symlinked a 
>subdirectory of the root dir of the git repository to somewhere else, 
>and cd from the symlink, '%r' doesn't show the correct value, while the 
>git repository can be recognized by zsh.

This sounds like it may be the same issue that was addressed by the 
patch in workers:31985 (http://www.zsh.org/mla/workers/2013/msg01038.html),
sent by Clemens Hammacher.  It doesn't look like that patch has been 
applied to the git repository yet, but it looks like a good solution to 
me.

Since the patch is short, I'll include the content here:

diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git 
b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
index c44be39..e6791cb 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
@@ -132,7 +132,7 @@ fi
 
 VCS_INFO_adjust
 VCS_INFO_git_getaction ${gitdir}
-gitbase=${PWD%/${$( ${vcs_comm[cmd]} rev-parse --show-prefix )%/##}}
+gitbase=$( ${vcs_comm[cmd]} rev-parse --show-toplevel )
 rrn=${gitbase:t}
 
 local patchdir=${gitdir}/patches/${gitbranch}

Does that fix the problem for you?


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: vcs_info '%r' doesn't work properly when entered a subdirectory of a git repository through a symlink
  2013-11-21 23:13 ` Aaron Schrab
@ 2013-11-21 23:26   ` Aaron Schrab
  2013-11-22  0:10   ` Bart Schaefer
  1 sibling, 0 replies; 10+ messages in thread
From: Aaron Schrab @ 2013-11-21 23:26 UTC (permalink / raw)
  To: Hong Xu, zsh-workers

At 18:13 -0500 21 Nov 2013, I wrote:
>At 17:45 -0800 20 Nov 2013, Hong Xu <hong@topbug.net> wrote:
>>The vcs_info '%r' generally works perfect, but when I symlinked a 
>>subdirectory of the root dir of the git repository to somewhere 
>>else, and cd from the symlink, '%r' doesn't show the correct value, 
>>while the git repository can be recognized by zsh.
>
>This sounds like it may be the same issue that was addressed by the 
>patch in workers:31985 
>(http://www.zsh.org/mla/workers/2013/msg01038.html),
>sent by Clemens Hammacher.  It doesn't look like that patch has been 
>applied to the git repository yet, but it looks like a good solution 
>to me.
>
>Since the patch is short, I'll include the content here:

Looking at the copy that I got back from the mailing list, I see that I 
mistakenly let my editor do wrapping on that patch which broke it.  
Here's another try at it:

diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
index c44be39..e6791cb 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
@@ -132,7 +132,7 @@ fi
 
 VCS_INFO_adjust
 VCS_INFO_git_getaction ${gitdir}
-gitbase=${PWD%/${$( ${vcs_comm[cmd]} rev-parse --show-prefix )%/##}}
+gitbase=$( ${vcs_comm[cmd]} rev-parse --show-toplevel )
 rrn=${gitbase:t}
 
 local patchdir=${gitdir}/patches/${gitbranch}


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: vcs_info '%r' doesn't work properly when entered a subdirectory of a git repository through a symlink
  2013-11-21 23:13 ` Aaron Schrab
  2013-11-21 23:26   ` Aaron Schrab
@ 2013-11-22  0:10   ` Bart Schaefer
  2013-11-22  1:54     ` Hong Xu
  1 sibling, 1 reply; 10+ messages in thread
From: Bart Schaefer @ 2013-11-22  0:10 UTC (permalink / raw)
  To: zsh-workers

On Nov 21,  6:13pm, Aaron Schrab wrote:
}
} This sounds like it may be the same issue that was addressed by the 
} patch in workers:31985 (http://www.zsh.org/mla/workers/2013/msg01038.html),
} sent by Clemens Hammacher.

That's probably true, but looking at VCS_INFO_reposub I think applying
31985 is still going to break %S in the way Hong already mentioned.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: vcs_info '%r' doesn't work properly when entered a subdirectory of a git repository through a symlink
  2013-11-22  0:10   ` Bart Schaefer
@ 2013-11-22  1:54     ` Hong Xu
  2013-11-28  7:23       ` Hong Xu
  0 siblings, 1 reply; 10+ messages in thread
From: Hong Xu @ 2013-11-22  1:54 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-workers

On Thu Nov 21 16:10:50 2013, Bart Schaefer wrote:
> On Nov 21,  6:13pm, Aaron Schrab wrote:
> }
> } This sounds like it may be the same issue that was addressed by the
> } patch in workers:31985 (http://www.zsh.org/mla/workers/2013/msg01038.html),
> } sent by Clemens Hammacher.
>
> That's probably true, but looking at VCS_INFO_reposub I think applying
> 31985 is still going to break %S in the way Hong already mentioned.

I just tested this patch, yes it did break %S.

Hong


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: vcs_info '%r' doesn't work properly when entered a subdirectory of a git repository through a symlink
  2013-11-22  1:54     ` Hong Xu
@ 2013-11-28  7:23       ` Hong Xu
  2013-11-28 22:03         ` Bart Schaefer
  0 siblings, 1 reply; 10+ messages in thread
From: Hong Xu @ 2013-11-28  7:23 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 694 bytes --]

On 11/21/13, 5:54 PM, Hong Xu wrote:
> On Thu Nov 21 16:10:50 2013, Bart Schaefer wrote:
>> On Nov 21,  6:13pm, Aaron Schrab wrote:
>> }
>> } This sounds like it may be the same issue that was addressed by the
>> } patch in workers:31985
>> (http://www.zsh.org/mla/workers/2013/msg01038.html),
>> } sent by Clemens Hammacher.
>>
>> That's probably true, but looking at VCS_INFO_reposub I think applying
>> 31985 is still going to break %S in the way Hong already mentioned.
>
> I just tested this patch, yes it did break %S.


I tested the attached patch and it fixes the issue without breaking %S 
for me. Please give it a try, and if it is good, could you include this 
patch?

Thanks!
Hong


[-- Attachment #2: vcs_git.patch --]
[-- Type: text/plain, Size: 1006 bytes --]

diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
index c44be39..cd8f064 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
@@ -132,7 +132,7 @@ fi
 
 VCS_INFO_adjust
 VCS_INFO_git_getaction ${gitdir}
-gitbase=${PWD%/${$( ${vcs_comm[cmd]} rev-parse --show-prefix )%/##}}
+gitbase=${$(pwd -P)%/${$( ${vcs_comm[cmd]} rev-parse --show-prefix )%/##}}
 rrn=${gitbase:t}
 
 local patchdir=${gitdir}/patches/${gitbranch}
diff --git a/Functions/VCS_Info/VCS_INFO_reposub b/Functions/VCS_Info/VCS_INFO_reposub
index 0fab863..1c16f0e 100644
--- a/Functions/VCS_Info/VCS_INFO_reposub
+++ b/Functions/VCS_Info/VCS_INFO_reposub
@@ -5,9 +5,9 @@
 setopt localoptions extendedglob NO_shwordsplit
 local base=${1%%/##}
 
-[[ ${PWD} == ${base}/* ]] || {
+[[ $(pwd -P) == ${base}/* ]] || {
     printf '.'
     return 1
 }
-printf '%s' ${PWD#$base/}
+printf '%s' ${$(pwd -P)#$base/}
 return 0

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: vcs_info '%r' doesn't work properly when entered a subdirectory of a git repository through a symlink
  2013-11-28  7:23       ` Hong Xu
@ 2013-11-28 22:03         ` Bart Schaefer
  2013-11-29  0:43           ` Hong Xu
  0 siblings, 1 reply; 10+ messages in thread
From: Bart Schaefer @ 2013-11-28 22:03 UTC (permalink / raw)
  To: Hong Xu; +Cc: zsh-workers

On Nov 27, 11:23pm, Hong Xu wrote:
}
} I tested the attached patch and it fixes the issue without breaking %S 
} for me. Please give it a try, and if it is good, could you include this 
} patch?


Does the following also work for you?  I'd like to preserve 31985 if
possible.

diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
index c44be39..e6791cb 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
@@ -132,7 +132,7 @@ fi
 
 VCS_INFO_adjust
 VCS_INFO_git_getaction ${gitdir}
-gitbase=${PWD%/${$( ${vcs_comm[cmd]} rev-parse --show-prefix )%/##}}
+gitbase=$( ${vcs_comm[cmd]} rev-parse --show-toplevel )
 rrn=${gitbase:t}
 
 local patchdir=${gitdir}/patches/${gitbranch}
diff --git a/Functions/VCS_Info/VCS_INFO_reposub b/Functions/VCS_Info/VCS_INFO_reposub
index 0fab863..1c16f0e 100644
--- a/Functions/VCS_Info/VCS_INFO_reposub
+++ b/Functions/VCS_Info/VCS_INFO_reposub
@@ -5,9 +5,9 @@
 setopt localoptions extendedglob NO_shwordsplit
 local base=${1%%/##}
 
-[[ ${PWD} == ${base}/* ]] || {
+[[ $(pwd -P) == ${base}/* ]] || {
     printf '.'
     return 1
 }
-printf '%s' ${PWD#$base/}
+printf '%s' ${$(pwd -P)#$base/}
 return 0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: vcs_info '%r' doesn't work properly when entered a subdirectory of a git repository through a symlink
  2013-11-28 22:03         ` Bart Schaefer
@ 2013-11-29  0:43           ` Hong Xu
  0 siblings, 0 replies; 10+ messages in thread
From: Hong Xu @ 2013-11-29  0:43 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-workers

On Thu Nov 28 14:03:27 2013, Bart Schaefer wrote:
> On Nov 27, 11:23pm, Hong Xu wrote:
> }
> } I tested the attached patch and it fixes the issue without breaking %S
> } for me. Please give it a try, and if it is good, could you include this
> } patch?
>
>
> Does the following also work for you?  I'd like to preserve 31985 if
> possible.
>
> <...>

Yes the patch also works for me. I can see that this patch is more 
reasonable, as hg also uses the same way.

Hong


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2013-11-29  0:43 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-21  1:45 [BUG] vcs_info '%r' doesn't work properly when entered a subdirectory of a git repository through a symlink Hong Xu
2013-11-21 16:16 ` Bart Schaefer
2013-11-21 19:12   ` Hong Xu
2013-11-21 23:13 ` Aaron Schrab
2013-11-21 23:26   ` Aaron Schrab
2013-11-22  0:10   ` Bart Schaefer
2013-11-22  1:54     ` Hong Xu
2013-11-28  7:23       ` Hong Xu
2013-11-28 22:03         ` Bart Schaefer
2013-11-29  0:43           ` Hong Xu

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).