Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Closed
wants to merge 2 commits into from

3 participants

@stephenfrank

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"

Before

$ git submodule status | awk '{ print $2 }'
my_module
path/to/other_module

After

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

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

@travisbot

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

@travisbot

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

@carsomyr

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

@stephenfrank

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.

@stephenfrank

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 :)

@carsomyr

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

@stephenfrank

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;
done

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?

@carsomyr

@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
2  lib/capistrano/recipes/deploy/scm/git.rb
@@ -190,7 +190,7 @@ def sync(revision, destination)
if variable(:git_enable_submodules)
execute << "#{git} submodule #{verbose} init"
- execute << "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; done"
+ execute << "for mod in `#{git} submodule status | awk '{ print $2 }' | sed -E 's/.*\\/(.+)/\\1/'`; do #{git} config -f .git/config submodule.${mod}.url `#{git} config -f .gitmodules --get submodule.${mod}.url` && echo Synced $mod; done"
execute << "#{git} submodule #{verbose} sync"
if false == variable(:git_submodules_recursive)
execute << "#{git} submodule #{verbose} update --init"
View
2  test/deploy/scm/git_test.rb
@@ -127,7 +127,7 @@ def test_sync
# with submodules
@config[:git_enable_submodules] = true
- assert_equal "cd #{dest} && #{git} fetch -q origin && #{git} fetch --tags -q origin && #{git} reset -q --hard #{rev} && #{git} submodule -q init && 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; done && #{git} submodule -q sync && export GIT_RECURSIVE=$([ ! \"`#{git} --version`\" \\< \"git version 1.6.5\" ] && echo --recursive) && #{git} submodule -q update --init $GIT_RECURSIVE && #{git} clean -q -d -x -f", @source.sync(rev, dest)
+ assert_equal "cd #{dest} && #{git} fetch -q origin && #{git} fetch --tags -q origin && #{git} reset -q --hard #{rev} && #{git} submodule -q init && for mod in `#{git} submodule status | awk '{ print $2 }' | sed -E 's/.*\\/(.+)/\\1/'`; do #{git} config -f .git/config submodule.${mod}.url `#{git} config -f .gitmodules --get submodule.${mod}.url` && echo Synced $mod; done && #{git} submodule -q sync && export GIT_RECURSIVE=$([ ! \"`#{git} --version`\" \\< \"git version 1.6.5\" ] && echo --recursive) && #{git} submodule -q update --init $GIT_RECURSIVE && #{git} clean -q -d -x -f", @source.sync(rev, dest)
end
def test_sync_with_remote
Something went wrong with that request. Please try again.