Discussion:
let git grep consider sub projects
Olaf Hering
2014-10-07 08:29:14 UTC
Permalink
How can I teach 'git grep $string' to also consider subprojects?

The build system of xen.git clones 4 other trees into a directory in its
source tree during build. It would be nice if my 'git grep' searches
also in these cloned subdirs. Somehow there must be some knowledge
because 'git clean -dfx' leaves them alone, while 'git clean -dffx'
wipes everything.

Olaf

PS: Sometimes I miss a 'git clean -dfx --also-sub-repos' useful to
really clean everything before starting over.
Junio C Hamano
2014-10-07 18:25:53 UTC
Permalink
Post by Olaf Hering
How can I teach 'git grep $string' to also consider subprojects?
The build system of xen.git clones 4 other trees into a directory in its
source tree during build. It would be nice if my 'git grep' searches
also in these cloned subdirs. Somehow there must be some knowledge
because 'git clean -dfx' leaves them alone, while 'git clean -dffx'
wipes everything.
Olaf
PS: Sometimes I miss a 'git clean -dfx --also-sub-repos' useful to
really clean everything before starting over.
Is "submodule foreach" under-advertised or with less than adequate
features?
Mikael Magnusson
2014-10-07 19:12:46 UTC
Permalink
Post by Junio C Hamano
Post by Olaf Hering
How can I teach 'git grep $string' to also consider subprojects?
The build system of xen.git clones 4 other trees into a directory in its
source tree during build. It would be nice if my 'git grep' searches
also in these cloned subdirs. Somehow there must be some knowledge
because 'git clean -dfx' leaves them alone, while 'git clean -dffx'
wipes everything.
Olaf
PS: Sometimes I miss a 'git clean -dfx --also-sub-repos' useful to
really clean everything before starting over.
Is "submodule foreach" under-advertised or with less than adequate
features?
It sounds like in these use cases, you would want the commands to run
on all the submodules but also in the parent repo, am I wrong in
thinking that git submodule foreach does only the former part? So you
would either need to make a wrapper thing yourself or run the command
twice.

In the first case with the git grep, I can also imagine that with some
nontrivial patterns, having to quote the metacharacters not only once,
but twice, can be a significant annoyance. Eg, first protect it from
git submodule foreach parsing it, and then from the shell running the
individual commands.
--
Mikael Magnusson
Jens Lehmann
2014-10-08 06:48:09 UTC
Permalink
Post by Mikael Magnusson
Post by Junio C Hamano
Post by Olaf Hering
How can I teach 'git grep $string' to also consider subprojects?
The build system of xen.git clones 4 other trees into a directory in its
source tree during build. It would be nice if my 'git grep' searches
also in these cloned subdirs. Somehow there must be some knowledge
because 'git clean -dfx' leaves them alone, while 'git clean -dffx'
wipes everything.
Olaf
PS: Sometimes I miss a 'git clean -dfx --also-sub-repos' useful to
really clean everything before starting over.
Is "submodule foreach" under-advertised or with less than adequate
features?
It sounds like in these use cases, you would want the commands to run
on all the submodules but also in the parent repo, am I wrong in
thinking that git submodule foreach does only the former part? So you
would either need to make a wrapper thing yourself or run the command
twice.
Yep, the workaround for a command "git foo" that hasn't learned the
--recurse-submodules option yet is

git foo && git submodule foreach --recursive git foo
Post by Mikael Magnusson
In the first case with the git grep, I can also imagine that with some
nontrivial patterns, having to quote the metacharacters not only once,
but twice, can be a significant annoyance. Eg, first protect it from
git submodule foreach parsing it, and then from the shell running the
individual commands.
The long term goal is to teach git grep and git clean - and others -
the --recurse-submodules option. I'd be happy to help if someone
wants to work on that, as I'm busy working on another topic.
Olaf Hering
2014-10-08 06:59:47 UTC
Permalink
Post by Jens Lehmann
git foo && git submodule foreach --recursive git foo
Looks like a submodule is yet another thing, or I have to learn what a
submodule is:

***@bax:~/xen $ find . -name .git
./.git
./tools/qemu-xen-dir-remote/.git
./tools/qemu-xen-traditional-dir-remote/.git
./tools/firmware/seabios-dir-remote/.git
***@bax:~/xen $ git submodule foreach --recursive git show
***@bax:~/xen $

xen does essentially 'git clone $url1 dir/url1-dir;git clone $url2
dir/url2-dir'. So the top level .git does not really know about
dir/*-dir.

Olaf
Jens Lehmann
2014-10-08 07:24:37 UTC
Permalink
Post by Olaf Hering
Post by Jens Lehmann
git foo && git submodule foreach --recursive git foo
Looks like a submodule is yet another thing, or I have to learn what a
./.git
./tools/qemu-xen-dir-remote/.git
./tools/qemu-xen-traditional-dir-remote/.git
./tools/firmware/seabios-dir-remote/.git
xen does essentially 'git clone $url1 dir/url1-dir;git clone $url2
dir/url2-dir'. So the top level .git does not really know about
dir/*-dir.
Okay, I just checked that xen doesn't use submodules but uses simple
embedded repos ignored by the .gitignore file. From a quick glance
it looks like handling the sub projects is scripted in the Makefiles.
This is perfectly fine, but then you can't really expect git commands
to know about these sub projects. Or am I missing something?
Olaf Hering
2014-10-08 07:31:40 UTC
Permalink
Post by Jens Lehmann
Okay, I just checked that xen doesn't use submodules but uses simple
embedded repos ignored by the .gitignore file. From a quick glance
it looks like handling the sub projects is scripted in the Makefiles.
This is perfectly fine, but then you can't really expect git commands
to know about these sub projects. Or am I missing something?
I just did not know about the submodule command. And I did not realize
that they are in .gitignore, which should have been obvious.

I will check if using submodule instead of plain clone can be done,
without breaking anyones workflow.


Olaf

Loading...