* Re: git locate
2010-01-21 0:11 ` SungHyun Nam
@ 2010-01-21 9:42 ` Michael J Gruber
2010-01-21 9:51 ` Štěpán Němec
2010-02-15 13:20 ` Sverre Rabbelier
2 siblings, 0 replies; 17+ messages in thread
From: Michael J Gruber @ 2010-01-21 9:42 UTC (permalink / raw)
To: SungHyun Nam; +Cc: Git List
SungHyun Nam venit, vidit, dixit 21.01.2010 01:11:
> Hello,
>
> Johannes Schindelin wrote:
>>
>> On Tue, 19 Jan 2010, Jakub Narebski wrote:
>>
>>> Johannes Schindelin<Johannes.Schindelin@gmx.de> writes:
>>>
>>>> On Wed, 20 Jan 2010, John Tapsell wrote:
>>>>
>>>>> Could we add a: git locate<filename> or git find<filename>
>>>>
>>>> How about "git ls-files \*<filename>"?
>>>
>>> Or "git ls-files '*filename'...
>>>
>>> ... but how to make an (git) alias for this?
>>
>> Add something like this to your $HOME/.gitconfig:
>>
>> [alias]
>> locate = !sh -c 'git ls-files "\\*$1"' -
>
> The alias 'git locate' and the command 'git ls-files' runs
> differently if I run them in a subdirectory.
> Is it expected?
>
> [master] ~/srcs/git[299]$ git locate urls.txt
> Documentation/urls.txt
> [master] ~/srcs/git[300]$ git ls-files '*urls.txt'
> Documentation/urls.txt
> [master] ~/srcs/git[301]$ cd t
> [master] ~/srcs/git/t[302]$ git locate urls.txt
> Documentation/urls.txt
> [master] ~/srcs/git/t[303]$ git ls-files '*urls.txt'
> [master] ~/srcs/git/t[304]$
Yes, aliases with "!" are executed from the root of the worktree,
ls-files from the current wd.
Michael
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: git locate
2010-01-21 0:11 ` SungHyun Nam
2010-01-21 9:42 ` Michael J Gruber
@ 2010-01-21 9:51 ` Štěpán Němec
2010-02-15 13:20 ` Sverre Rabbelier
2 siblings, 0 replies; 17+ messages in thread
From: Štěpán Němec @ 2010-01-21 9:51 UTC (permalink / raw)
To: SungHyun Nam; +Cc: Git List
On Thu, Jan 21, 2010 at 09:11:20AM +0900, SungHyun Nam wrote:
> Hello,
>
> Johannes Schindelin wrote:
> >
> >On Tue, 19 Jan 2010, Jakub Narebski wrote:
> >
> >>Johannes Schindelin<Johannes.Schindelin@gmx.de> writes:
> >>
> >>>On Wed, 20 Jan 2010, John Tapsell wrote:
> >>>
> >>>> Could we add a: git locate<filename> or git find<filename>
> >>>
> >>>How about "git ls-files \*<filename>"?
> >>
> >>Or "git ls-files '*filename'...
> >>
> >>... but how to make an (git) alias for this?
> >
> >Add something like this to your $HOME/.gitconfig:
> >
> >[alias]
> > locate = !sh -c 'git ls-files "\\*$1"' -
>
> The alias 'git locate' and the command 'git ls-files' runs
> differently if I run them in a subdirectory.
> Is it expected?
>
> [master] ~/srcs/git[299]$ git locate urls.txt
> Documentation/urls.txt
> [master] ~/srcs/git[300]$ git ls-files '*urls.txt'
> Documentation/urls.txt
> [master] ~/srcs/git[301]$ cd t
> [master] ~/srcs/git/t[302]$ git locate urls.txt
> Documentation/urls.txt
> [master] ~/srcs/git/t[303]$ git ls-files '*urls.txt'
> [master] ~/srcs/git/t[304]$
Yeah, as stated in another part of the Wiki page Dscho referred to
(namely the "Serve repo on the spot" section):
"It makes use of the fact that (currently, as of git 1.5.6.1) non-git
alias are executed from the top-level dir of a repo."
("non-git" == those starting with "!", which is the case here)
Štěpán
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: git locate
2010-01-21 0:11 ` SungHyun Nam
2010-01-21 9:42 ` Michael J Gruber
2010-01-21 9:51 ` Štěpán Němec
@ 2010-02-15 13:20 ` Sverre Rabbelier
2010-06-02 5:00 ` John Tapsell
2 siblings, 1 reply; 17+ messages in thread
From: Sverre Rabbelier @ 2010-02-15 13:20 UTC (permalink / raw)
To: SungHyun Nam; +Cc: Git List
Heya,
On Thu, Jan 21, 2010 at 01:11, SungHyun Nam <goweol@gmail.com> wrote:
> The alias 'git locate' and the command 'git ls-files' runs
> differently if I run them in a subdirectory.
> Is it expected?
I just ran into this (I wanted to alias 'git find' but to me the 'run
ls-files from cwd' is desirable. Also, I prefer to have a trailing
glob as well, so I added one :). An easy solution is to drop
'git-find' in your path somewhere:
sverre@laptop-sverre:~/bin$ cat git-find
#!/bin/bash
git ls-files "*$1*"
--
Cheers,
Sverre Rabbelier
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: git locate
2010-02-15 13:20 ` Sverre Rabbelier
@ 2010-06-02 5:00 ` John Tapsell
2010-06-02 10:02 ` John Tapsell
0 siblings, 1 reply; 17+ messages in thread
From: John Tapsell @ 2010-06-02 5:00 UTC (permalink / raw)
To: Git List
On 15 February 2010 22:20, Sverre Rabbelier <srabbelier@gmail.com> wrote:
> Heya,
>
> On Thu, Jan 21, 2010 at 01:11, SungHyun Nam <goweol@gmail.com> wrote:
>> The alias 'git locate' and the command 'git ls-files' runs
>> differently if I run them in a subdirectory.
>> Is it expected?
>
> I just ran into this (I wanted to alias 'git find' but to me the 'run
> ls-files from cwd' is desirable. Also, I prefer to have a trailing
> glob as well, so I added one :). An easy solution is to drop
> 'git-find' in your path somewhere:
I have finally settled on:
[alias]
locate = !sh -c 'git ls-files | grep --color=auto "$1"' -
This acts as if there is a leading and trailing wildcard, and also
colors the output nicely.
Can we add this as default please? There didn't seem to be any
resistance in this thread to making it default, just that nobody did
it :)
John
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: git locate
2010-06-02 5:00 ` John Tapsell
@ 2010-06-02 10:02 ` John Tapsell
2010-06-02 10:23 ` Bruce Stephens
2010-06-02 11:29 ` Nguyen Thai Ngoc Duy
0 siblings, 2 replies; 17+ messages in thread
From: John Tapsell @ 2010-06-02 10:02 UTC (permalink / raw)
To: Git List
On 2 June 2010 14:00, John Tapsell <johnflux@gmail.com> wrote:
> On 15 February 2010 22:20, Sverre Rabbelier <srabbelier@gmail.com> wrote:
>> Heya,
>>
>> On Thu, Jan 21, 2010 at 01:11, SungHyun Nam <goweol@gmail.com> wrote:
>>> The alias 'git locate' and the command 'git ls-files' runs
>>> differently if I run them in a subdirectory.
>>> Is it expected?
>>
>> I just ran into this (I wanted to alias 'git find' but to me the 'run
>> ls-files from cwd' is desirable. Also, I prefer to have a trailing
>> glob as well, so I added one :). An easy solution is to drop
>> 'git-find' in your path somewhere:
>
> I have finally settled on:
>
> [alias]
> locate = !sh -c 'git ls-files | grep --color=auto "$1"' -
Actually could someone help me with this.. the trouble is that this
returns paths relative to the root.
Can I get it to find all the files, but relative to where I am now?
John
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: git locate
2010-06-02 10:02 ` John Tapsell
@ 2010-06-02 10:23 ` Bruce Stephens
2010-06-02 11:27 ` Matthieu Moy
2010-06-03 13:39 ` Clemens Buchacher
2010-06-02 11:29 ` Nguyen Thai Ngoc Duy
1 sibling, 2 replies; 17+ messages in thread
From: Bruce Stephens @ 2010-06-02 10:23 UTC (permalink / raw)
To: John Tapsell; +Cc: Git List
John Tapsell <johnflux@gmail.com> writes:
[...]
> Actually could someone help me with this.. the trouble is that this
> returns paths relative to the root.
>
> Can I get it to find all the files, but relative to where I am now?
Something like this is probably part of the answer, which allows an
alias like this to work:
locate = !cd $GIT_CWD && sh -c 'git ls-files "*$1*"' -
That doesn't give you all the files (just those below where you are).
diff --git a/git.c b/git.c
index 99f0363..81c877b 100644
--- a/git.c
+++ b/git.c
@@ -178,6 +178,10 @@ static int handle_alias(int *argcp, const char ***argv)
}
trace_printf("trace: alias to shell cmd: %s => %s\n",
alias_command, alias_string + 1);
+ if (!subdir || !*subdir)
+ setenv("GIT_CWD", "./", 1);
+ else
+ setenv("GIT_CWD", subdir, 1);
ret = system(alias_string + 1);
if (ret >= 0 && WIFEXITED(ret) &&
WEXITSTATUS(ret) != 127)
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: git locate
2010-06-02 10:23 ` Bruce Stephens
@ 2010-06-02 11:27 ` Matthieu Moy
2010-06-03 13:39 ` Clemens Buchacher
1 sibling, 0 replies; 17+ messages in thread
From: Matthieu Moy @ 2010-06-02 11:27 UTC (permalink / raw)
To: Bruce Stephens; +Cc: John Tapsell, Git List
Bruce Stephens <bruce.stephens@isode.com> writes:
> John Tapsell <johnflux@gmail.com> writes:
>
> [...]
>
>> Actually could someone help me with this.. the trouble is that this
>> returns paths relative to the root.
>>
>> Can I get it to find all the files, but relative to where I am now?
>
> Something like this is probably part of the answer, which allows an
> alias like this to work:
>
> locate = !cd $GIT_CWD && sh -c 'git ls-files "*$1*"' -
There's a patch pending to do more or less the same thing:
http://thread.gmane.org/gmane.comp.version-control.git/146360/focus=146450
Read Junio's reply there:
http://thread.gmane.org/gmane.comp.version-control.git/146360/focus=146450
--
Matthieu Moy
http://www-verimag.imag.fr/~moy/
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: git locate
2010-06-02 10:23 ` Bruce Stephens
2010-06-02 11:27 ` Matthieu Moy
@ 2010-06-03 13:39 ` Clemens Buchacher
1 sibling, 0 replies; 17+ messages in thread
From: Clemens Buchacher @ 2010-06-03 13:39 UTC (permalink / raw)
To: Bruce Stephens; +Cc: John Tapsell, Git List
On Wed, Jun 02, 2010 at 11:23:32AM +0100, Bruce Stephens wrote:
> Something like this is probably part of the answer, which allows an
> alias like this to work:
>
> locate = !cd $GIT_CWD && sh -c 'git ls-files "*$1*"' -
>
> That doesn't give you all the files (just those below where you are).
Once relative path support for ls-files is done (patch pending) you
can do git ls-files $(git rev-parse --show-cdup).
Clemens
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: git locate
2010-06-02 10:02 ` John Tapsell
2010-06-02 10:23 ` Bruce Stephens
@ 2010-06-02 11:29 ` Nguyen Thai Ngoc Duy
1 sibling, 0 replies; 17+ messages in thread
From: Nguyen Thai Ngoc Duy @ 2010-06-02 11:29 UTC (permalink / raw)
To: John Tapsell; +Cc: Git List
On Wed, Jun 2, 2010 at 12:02 PM, John Tapsell <johnflux@gmail.com> wrote:
> On 2 June 2010 14:00, John Tapsell <johnflux@gmail.com> wrote:
>> On 15 February 2010 22:20, Sverre Rabbelier <srabbelier@gmail.com> wrote:
>>> Heya,
>>>
>>> On Thu, Jan 21, 2010 at 01:11, SungHyun Nam <goweol@gmail.com> wrote:
>>>> The alias 'git locate' and the command 'git ls-files' runs
>>>> differently if I run them in a subdirectory.
>>>> Is it expected?
>>>
>>> I just ran into this (I wanted to alias 'git find' but to me the 'run
>>> ls-files from cwd' is desirable. Also, I prefer to have a trailing
>>> glob as well, so I added one :). An easy solution is to drop
>>> 'git-find' in your path somewhere:
>>
>> I have finally settled on:
>>
>> [alias]
>> locate = !sh -c 'git ls-files | grep --color=auto "$1"' -
>
>
> Actually could someone help me with this.. the trouble is that this
> returns paths relative to the root.
>
> Can I get it to find all the files, but relative to where I am now?
Make it a git command, not an alias. You'll then be fine. put
git-locate somewhere in your $PATH
--<--
#!/bin/sh
git ls-files | grep --color=auto "$1"
--<--
Of course you need to chmod u+x for it.
--
Duy
^ permalink raw reply [flat|nested] 17+ messages in thread