Trimmed additional 'path/to/submodule' when awking submodule status #261

wants to merge 2 commits into


None yet

3 participants


In my deployment of a repository with git submodules which were in paths other than the root the current method of grabbing the module "name" from "git submodule status" didn't work. The entire path to the submodule was being placed into "config -f .git/config submodule.${mod}.url"


$ git submodule status | awk '{ print $2 }'


$ git submodule status | awk '{ print $2 }' | sed -E 's/.*\/(.+)/\1/'

I thought a pull request might be more helpful than listing this in the issues. Use it, or don't! :)


This pull request fails (merged e29a848 into 30a942c).


This pull request passes (merged 18abb95 into 30a942c).


@stephenfrank Holy moley, awk and sed together on one line! Is there any way for you to do pure awk or pure sed?


Maybe? I wasn't getting anywhere with awk because (from my searching) it doesn't support regex with match groups. I'm sure a match pattern that in pure sed could also do the job.


I've done my homework by attempting to find a match pattern for sed that would trim the output in one invocation. I couldn't find an elegant match pattern (okay I lie, I couldn't get any pattern to work).

So unless anyone else can verify this bug and weigh in with a better solution that's all I can manage :)


@stephenfrank In your example, why is the first submodule trimmed but not the second? Is it because of the .gitmodules definition?

[submodule "foo"]
    path = foo
    url = ../foo

[submodule "bar"]
    path = folder/bar
    url = ../bar

In the above example, are you saying that the first case would succeed, but the second case would fail?


Hi again,

Yes, in my experience (albeit only on my latest project, so no other examples) the above example would fail on the second submodule update.

Just to recap the current method for fetching submodules is like this:

for mod in `#{git} submodule status | awk '{ print $2 }'`; do
    #{git} config -f .git/config submodule.${mod}.url `#{git} config -f .gitmodules --get submodule.${mod}.url`
    && echo Synced $mod;

Instead of printing foo and then bar, the submodule status command prints foo and then folder/bar which in the context of the script fails when attempting submodule.folder/bar.url.

I wonder (just thought of this now), if cating the contents of .gitmodules and selecting the pattern [submodule "(.*?)"] would work and be a more precise method?


@stephenfrank Sorry for dropping the ball on this one. I have reviewed the offending line and have decided to take it out altogether. While it may be necessary, I am prepared to handle the corner case as it arises in another issue. Am I introducing a bug? Possibly. Note that since git has changed the way it lays out submodules, doing #{git} config -f .git/config cannot be right anyways.

@carsomyr carsomyr closed this Oct 23, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment