submodule update --force

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


I have a situation where I have a full source tree -- top-level
repository and all submodules -- generated via `git clone -n`.  So,
the directory structure and .git directories are intact, but no actual
source files have been checked out.

If I run `git submodule update` from the top level, some submodules
get checked out, but not others.  Weird.

Root cause is in the cmd_update function in git-submodule.sh, which
does essentially this:

sha1 = submodule revision as registered in top-level module
subsha1 = HEAD revision in submodule checkout

if test "$subsha1" != "$sha1"
then
    git checkout $sha1
fi

In the submodule checkouts, HEAD is refs/heads/master.  In *some* of
the submodules, the revision registered in the top-level repository is
the same as HEAD.  So, for those submodules, `git submodule update`
run from the top level is a no-op, because $sha1 = $subsha1.  That's
true even though there are no actual source files checked out in the
submodule.

For other submodules, $sha1 != $subsha1, and `git submodule update`
checks out the source code as expected.

Confusing!

According to the docs for git-submodule:

       -f, --force
           This option is only valid for add and update commands. When
running add, allow adding an otherwise ignored
           submodule path. When running update, throw away local
changes in submodules when switching to a different
           commit.

I'd like to propose amending the documentation thusly:

According to the docs:

       -f, --force
           This option is only valid for add and update commands. When
running add, allow adding an otherwise ignored
           submodule path. When running update, throw away local
changes in submodules when switching to a different
           commit; if not switching to a different commit, a checkout
to HEAD will still be run.

... and here's the patch to implement it:

diff --git a/git-submodule.sh b/git-submodule.sh
index 64a70d6..8b045d9 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -536,7 +536,7 @@ Maybe you want to use 'update --init'?")"
                        die "$(eval_gettext "Unable to find current
revision in submodule path '\$sm_path'")"
                fi

-               if test "$subsha1" != "$sha1"
+               if test "$subsha1" != "$sha1" -o -n "$force"
                then
                        subforce=$force
                        # If we don't already have a -f flag and the
submodule has never been checked out



Thoughts?

Thanks,

Stefan
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Newbies FAQ]     [Linux Kernel Development]     [Free Online Dating]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Free Online Dating]     [Photo]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]     [Linux Resources]

Add to Google