The previous code only checked out branches in cmd_add. This commit moves the branch-checkout logic into module_clone, where it can be shared by cmd_add and cmd_update. I also update the initial checkout command to use 'reset' to preserve branches setup during module_clone. With this change, folks cloning submodules for the first time via: $ git submodule update ... will get a local branch instead of a detached HEAD, unless they are using the default checkout-mode updates. This is a change from the previous situation where cmd_update always used checkout-mode logic (regardless of the requested update mode) for updates that triggered an initial clone, which always resulted in a detached HEAD. This commit does not change the logic for updates after the initial clone, which will continue to create detached HEADs for checkout-mode updates, and integrate remote work with the local HEAD (detached or not) in other modes. The motivation for the change is that developers doing local work inside the submodule are likely to select a non-checkout-mode for updates so their local work is integrated with upstream work. Developers who are not doing local submodule work stick with checkout-mode updates so any apparently local work is blown away during updates. For example, if upstream rolls back the remote branch or gitlinked commit to an earlier version, the checkout-mode developer wants their old submodule checkout to be rolled back as well, instead of getting a no-op merge/rebase with the rolled-back reference. By using the update mode to distinguish submodule developers from black-box submodule consumers, we can setup local branches for the developers who will want local branches, and stick with detached HEADs for the developers that don't care. Testing ======= In t7406, just-cloned checkouts now update to the gitlinked hash with 'reset', to preserve the local branch for situations where we're not on a detached HEAD. I also added explicit tests to t7406 for HEAD attachement after cloning updates, showing that it depends on their update mode: * Checkout-mode updates get detached HEADs * Everyone else gets a local branch, matching the configured submodule.<name>.branch and defaulting to master. The 'initial-setup' tag makes it easy to reset the superproject to a known state, as several earlier tests commit to submodules and commit the changed gitlinks to the superproject, but don't push the new submodule commits to the upstream subprojects. This makes it impossible to checkout the current super master, because it references submodule commits that don't exist in the upstream subprojects. For a specific example, see the tests that currently generate the 'two_new_submodule_commits' commits. Documentation ============= I updated the docs to describe the 'submodule update' modes in detail. The old documentation did not distinguish between cloning and non-cloning updates and lacked clarity on which operations would lead to detached HEADs, and which would not. The new documentation addresses these issues while updating the docs to reflect the changes introduced by this commit's explicit local branch creation in module_clone. I also add '--checkout' to the usage summary and group the update-mode options into a single set. Signed-off-by: W. Trevor King <wking@tremily.us> Signed-off-by: Junio C Hamano <gitster@pobox.com>
111 lines
4.0 KiB
Plaintext
111 lines
4.0 KiB
Plaintext
gitmodules(5)
|
|
=============
|
|
|
|
NAME
|
|
----
|
|
gitmodules - defining submodule properties
|
|
|
|
SYNOPSIS
|
|
--------
|
|
$GIT_WORK_DIR/.gitmodules
|
|
|
|
|
|
DESCRIPTION
|
|
-----------
|
|
|
|
The `.gitmodules` file, located in the top-level directory of a Git
|
|
working tree, is a text file with a syntax matching the requirements
|
|
of linkgit:git-config[1].
|
|
|
|
The file contains one subsection per submodule, and the subsection value
|
|
is the name of the submodule. The name is set to the path where the
|
|
submodule has been added unless it was customized with the '--name'
|
|
option of 'git submodule add'. Each submodule section also contains the
|
|
following required keys:
|
|
|
|
submodule.<name>.path::
|
|
Defines the path, relative to the top-level directory of the Git
|
|
working tree, where the submodule is expected to be checked out.
|
|
The path name must not end with a `/`. All submodule paths must
|
|
be unique within the .gitmodules file.
|
|
|
|
submodule.<name>.url::
|
|
Defines a URL from which the submodule repository can be cloned.
|
|
This may be either an absolute URL ready to be passed to
|
|
linkgit:git-clone[1] or (if it begins with ./ or ../) a location
|
|
relative to the superproject's origin repository.
|
|
|
|
submodule.<name>.update::
|
|
Defines what to do when the submodule is updated by the superproject.
|
|
If 'checkout' (the default), the new commit specified in the
|
|
superproject will be checked out in the submodule on a detached HEAD.
|
|
If 'rebase', the current branch of the submodule will be rebased onto
|
|
the commit specified in the superproject. If 'merge', the commit
|
|
specified in the superproject will be merged into the current branch
|
|
in the submodule.
|
|
If 'none', the submodule with name `$name` will not be updated
|
|
by default.
|
|
|
|
This config option is overridden if 'git submodule update' is given
|
|
the '--merge', '--rebase' or '--checkout' options.
|
|
|
|
submodule.<name>.branch::
|
|
A remote branch name for tracking updates in the upstream submodule.
|
|
If the option is not specified, it defaults to 'master'. See the
|
|
`--remote` documentation in linkgit:git-submodule[1] for details.
|
|
+
|
|
This branch name is also used for the local branch created by
|
|
non-checkout cloning updates. See the `update` documentation in
|
|
linkgit:git-submodule[1] for details.
|
|
|
|
submodule.<name>.fetchRecurseSubmodules::
|
|
This option can be used to control recursive fetching of this
|
|
submodule. If this option is also present in the submodules entry in
|
|
.git/config of the superproject, the setting there will override the
|
|
one found in .gitmodules.
|
|
Both settings can be overridden on the command line by using the
|
|
"--[no-]recurse-submodules" option to "git fetch" and "git pull".
|
|
|
|
submodule.<name>.ignore::
|
|
Defines under what circumstances "git status" and the diff family show
|
|
a submodule as modified. When set to "all", it will never be considered
|
|
modified, "dirty" will ignore all changes to the submodules work tree and
|
|
takes only differences between the HEAD of the submodule and the commit
|
|
recorded in the superproject into account. "untracked" will additionally
|
|
let submodules with modified tracked files in their work tree show up.
|
|
Using "none" (the default when this option is not set) also shows
|
|
submodules that have untracked files in their work tree as changed.
|
|
If this option is also present in the submodules entry in .git/config of
|
|
the superproject, the setting there will override the one found in
|
|
.gitmodules.
|
|
Both settings can be overridden on the command line by using the
|
|
"--ignore-submodule" option. The 'git submodule' commands are not
|
|
affected by this setting.
|
|
|
|
|
|
EXAMPLES
|
|
--------
|
|
|
|
Consider the following .gitmodules file:
|
|
|
|
[submodule "libfoo"]
|
|
path = include/foo
|
|
url = git://foo.com/git/lib.git
|
|
|
|
[submodule "libbar"]
|
|
path = include/bar
|
|
url = git://bar.com/git/lib.git
|
|
|
|
|
|
This defines two submodules, `libfoo` and `libbar`. These are expected to
|
|
be checked out in the paths 'include/foo' and 'include/bar', and for both
|
|
submodules a URL is specified which can be used for cloning the submodules.
|
|
|
|
SEE ALSO
|
|
--------
|
|
linkgit:git-submodule[1] linkgit:git-config[1]
|
|
|
|
GIT
|
|
---
|
|
Part of the linkgit:git[1] suite
|