Commit graph

268 commits

Author SHA1 Message Date
Brian M. Carlson 2be945094e submodule: fix confusing variable name
cmd_summary reads the output of git diff, but reads in the submodule path into a
variable called name.  Since this variable does not contain the name of the
submodule, but the path, rename it to be clearer what data it actually holds.

Signed-off-by: Brian M. Carlson <sandals@crustytoothpaste.net>
Acked-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-09-03 12:46:23 -07:00
Junio C Hamano 2bb7aface6 Merge branch 'fg/submodule-clone-depth'
Allow shallow-cloning of submodules with "git submodule update".

* fg/submodule-clone-depth:
  Add --depth to submodule update/add
2013-07-15 10:28:48 -07:00
Fredrik Gustafsson 275cd184d5 Add --depth to submodule update/add
Add the --depth option to the add and update commands of "git submodule",
which is then passed on to the clone command. This is useful when the
submodule(s) are huge and you're not really interested in anything but
the latest commit.

Tests are added and some indention adjustments were made to conform to the
rest of the testfile on "submodule update can handle symbolic links in pwd".

Signed-off-by: Fredrik Gustafsson <iveqy@iveqy.com>
Acked-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-03 10:33:32 -07:00
Chris Packham 6cb5728c43 submodule update: allow custom command to update submodule working tree
Users can set submodule.$name.update to '!command' which will cause
'command' to be run instead of checkout/merge/rebase. This allows
the user finer-grained control over how the update is done.

The primary motivation for this was interoperability with stgit;
however being able to intercept the submodule update process may
prove useful for integrating with or extending other tools.

Signed-off-by: Chris Packham <judge.packham@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-07-03 10:15:15 -07:00
Junio C Hamano d9857bfd4d Merge branch 'jk/submodule-subdirectory-ok'
Allow various subcommands of "git submodule" to be run not from the
top of the working tree of the superproject.

* jk/submodule-subdirectory-ok:
  submodule: drop the top-level requirement
  rev-parse: add --prefix option
  submodule: show full path in error message
  t7403: add missing && chaining
  t7403: modernize style
  t7401: make indentation consistent
2013-06-30 15:39:35 -07:00
Junio C Hamano 4f9ec8dd23 Merge branch 'fg/submodule-non-ascii-path'
Many "git submodule" operations do not work on a submodule at a
path whose name is not in ASCII.

* fg/submodule-non-ascii-path:
  t7400: test of UTF-8 submodule names pass under Mac OS
  handle multibyte characters in name
2013-06-26 15:07:36 -07:00
John Keeping 091a6eb0fe submodule: drop the top-level requirement
Use the new rev-parse --prefix option to process all paths given to the
submodule command, dropping the requirement that it be run from the
top-level of the repository.

Since the interpretation of a relative submodule URL depends on whether
or not "remote.origin.url" is configured, explicitly block relative URLs
in "git submodule add" when not at the top level of the working tree.

Signed-off-by: John Keeping <john@keeping.me.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-06-17 13:30:01 -07:00
John Keeping 1ae2e19a32 submodule: show full path in error message
When --recursive was added to "submodule foreach" in commit 15fc56a (git
submodule foreach: Add --recursive to recurse into nested submodules,
2009-08-19), the error message when the script returns a non-zero status
was not updated to contain $prefix to show the full path.  Fix this.

Signed-off-by: John Keeping <john@keeping.me.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-06-17 13:30:01 -07:00
Fredrik Gustafsson b545cd15af git-submodule.sh: remove duplicate call to set_rev_name
set_rev_name is a possiblly expensive operation. If a submodule has
changes in it, set_rev_name was called twice.

Move call to set_rev_name so it's only called once, no matter which
codepath is taken.

Signed-off-by: Fredrik Gustafsson <iveqy@iveqy.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-06-17 13:26:42 -07:00
Fredrik Gustafsson 74671241fd handle multibyte characters in name
Many "git submodule" operations do not work on a submodule at a path whose
name is not in ASCII.

This is because "git ls-files" is used to find which paths are bound to
submodules to the current working tree, and the output is C-quoted by default
for non ASCII pathnames.

Tell "git ls-files" to not C-quote its output, which is easier than unwrapping
C-quote ourselves.

Signed-off-by: Fredrik Gustafsson <iveqy@iveqy.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-06-14 08:04:32 -07:00
Junio C Hamano 7b72ec5e14 Merge branch 'jl/submodule-deinit'
A finishing touch to the new topic in 1.8.3.

* jl/submodule-deinit:
  submodule deinit: clarify work tree removal message
2013-04-05 14:15:13 -07:00
Junio C Hamano e3b1173fb1 Merge branch 'rs/submodule-summary-limit'
"submodule summary --summary-limit" option did not support
"--option=value" form.

* rs/submodule-summary-limit:
  submodule summary: support --summary-limit=<n>
2013-04-03 09:34:46 -07:00
Jens Lehmann 7b294bf494 submodule deinit: clarify work tree removal message
The output of "git submodule deinit sub" of a populated submodule prints

  rm 'sub'

as the first line unless used with the -f option.

The "rm 'sub'" line is exactly the same output the user gets when using
"git rm sub" (because that command is used with the --dry-run option under
the hood to determine if the submodule is clean), which can easily lead to
the false impression that the submodule would be permanently removed. Also
users might be confused that the "rm 'submodule'" line won't show up when
the -f option is used, as the test is skipped in this case.

Silence the "rm 'submodule'" output by using the --quiet option for "git
rm" and always print

  Cleared directory 'submodule'

instead as the first output line. This line is printed as long as the
directory exists, no matter if empty or not.

Also extend the tests in t7400 to make sure the "Cleared directory" line
is printed correctly.

Reported-by: Phil Hord <phil.hord@gmail.com>
Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-04-01 13:05:54 -07:00
René Scharfe 862ae6cd67 submodule summary: support --summary-limit=<n>
In addition to "--summary-limit <n>" support the form "--summary-limit=<n>",
for consistency with other parameters and commands.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-04-01 07:37:34 -07:00
Junio C Hamano 50734ea0af Merge branch 'we/submodule-update-prefix-output' into maint
"git submodule update", when recursed into sub-submodules, did not
acccumulate the prefix paths.

* we/submodule-update-prefix-output:
  submodule update: when using recursion, show full path
2013-03-26 12:44:27 -07:00
Junio C Hamano b03b41e24c Merge branch 'jl/submodule-deinit'
There was no Porcelain way to say "I no longer am interested in
this submodule", once you express your interest in a submodule with
"submodule init".  "submodule deinit" is the way to do so.

* jl/submodule-deinit:
  submodule: add 'deinit' command
2013-03-25 14:00:29 -07:00
Junio C Hamano 28ed8d7be9 Merge branch 'we/submodule-update-prefix-output'
"git submodule update", when recursed into sub-submodules, did not
acccumulate the prefix paths.

* we/submodule-update-prefix-output:
  submodule update: when using recursion, show full path
2013-03-21 14:03:10 -07:00
Jens Lehmann cf41982806 submodule: add 'deinit' command
With "git submodule init" the user is able to tell git he cares about one
or more submodules and wants to have it populated on the next call to "git
submodule update". But currently there is no easy way he could tell git he
does not care about a submodule anymore and wants to get rid of his local
work tree (except he knows a lot about submodule internals and removes the
"submodule.$name.url" setting from .git/config together with the work tree
himself).

Help those users by providing a 'deinit' command. This removes the
whole submodule.<name> section from .git/config (either for the given
submodule(s) or for all those which have been initialized if '.' is used)
together with their work tree. Fail if the current work tree contains
modifications (unless forced), but don't complain when either the work
tree is already removed or no settings are found in .git/config.

Add tests and link the man pages of "git submodule deinit" and "git rm"
to assist the user in deciding whether removing or unregistering the
submodule is the right thing to do for him. Also add the deinit subcommand
to the completion list.

Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-03-04 14:48:02 -08:00
William Entriken 75bf5e60e8 submodule update: when using recursion, show full path
Previously when using update with recursion, only the path for the
inner-most module was printed. Now the path is printed relative to
the directory the command was started from. This now matches the
behavior of submodule foreach.

Signed-off-by: William Entriken <github.com@phor.net>
Acked-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-03-03 19:46:54 -08:00
Junio C Hamano eff80a9fd9 Allow custom "comment char"
Some users do want to write a line that begin with a pound sign, #,
in their commit log message.  Many tracking system recognise
a token of #<bugid> form, for example.

The support we offer these use cases is not very friendly to the end
users.  They have a choice between

 - Don't do it.  Avoid such a line by rewrapping or indenting; and

 - Use --cleanup=whitespace but remove all the hint lines we add.

Give them a way to set a custom comment char, e.g.

    $ git -c core.commentchar="%" commit

so that they do not have to do either of the two workarounds.

[jc: although I started the topic, all the tests and documentation
updates, many of the call sites of the new strbuf_add_commented_*()
functions, and the change to git-submodule.sh scripted Porcelain are
from Ralf.]

Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-01-16 12:48:22 -08:00
W. Trevor King b928922727 submodule add: If --branch is given, record it in .gitmodules
This allows you to easily record a submodule.<name>.branch option in
.gitmodules when you add a new submodule.  With this patch,

  $ git submodule add -b <branch> <repository> [<path>]
  $ git config -f .gitmodules submodule.<path>.branch <branch>

reduces to

  $ git submodule add -b <branch> <repository> [<path>]

This means that future calls to

  $ git submodule update --remote ...

will get updates from the same branch that you used to initialize the
submodule, which is usually what you want.

Signed-off-by: W. Trevor King <wking@tremily.us>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-12-19 09:40:51 -08:00
W. Trevor King 06b1abb5bd submodule update: add --remote for submodule's upstream changes
The current `update` command incorporates the superproject's gitlinked
SHA-1 ($sha1) into the submodule HEAD ($subsha1).  Depending on the
options you use, it may checkout $sha1, rebase the $subsha1 onto
$sha1, or merge $sha1 into $subsha1.  This helps you keep up with
changes in the upstream superproject.

However, it's also useful to stay up to date with changes in the
upstream subproject.  Previous workflows for incorporating such
changes include the ungainly:

  $ git submodule foreach 'git checkout $(git config --file $toplevel/.gitmodules submodule.$name.branch) && git pull'

With this patch, all of the useful functionality for incorporating
superproject changes can be reused to incorporate upstream subproject
updates.  When you specify --remote, the target $sha1 is replaced with
a $sha1 of the submodule's origin/master tracking branch.  If you want
to merge a different tracking branch, you can configure the
`submodule.<name>.branch` option in `.gitmodules`.  You can override
the `.gitmodules` configuration setting for a particular superproject
by configuring the option in that superproject's default configuration
(using the usual configuration hierarchy, e.g. `.git/config`,
`~/.gitconfig`, etc.).

Previous use of submodule.<name>.branch
=======================================

Because we're adding a new configuration option, it's a good idea to
check if anyone else is already using the option.  The foreach-pull
example above was described by Ævar in

  commit f030c96d86
  Author: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
  Date:   Fri May 21 16:10:10 2010 +0000

    git-submodule foreach: Add $toplevel variable

Gerrit uses the same interpretation for the setting, but because
Gerrit has direct access to the subproject repositories, it updates
the superproject repositories automatically when a subproject changes.
Gerrit also accepts the special value '.', which it expands into the
superproject's branch name.

Although the --remote functionality is using `submodule.<name>.branch`
slightly differently, the effect is the same.  The foreach-pull
example uses the option to record the name of the local branch to
checkout before pulls.  The tracking branch to be pulled is recorded
in `.git/modules/<name>/config`, which was initialized by the module
clone during `submodule add` or `submodule init`.  Because the branch
name stored in `submodule.<name>.branch` was likely the same as the
branch name used during the initial `submodule add`, the same branch
will be pulled in each workflow.

Implementation details
======================

In order to ensure a current tracking branch state, `update --remote`
fetches the submodule's remote repository before calculating the
SHA-1.  However, I didn't change the logic guarding the existing fetch:

  if test -z "$nofetch"
  then
    # Run fetch only if $sha1 isn't present or it
    # is not reachable from a ref.
    (clear_local_git_env; cd "$path" &&
      ( (rev=$(git rev-list -n 1 $sha1 --not --all 2>/dev/null) &&
       test -z "$rev") || git-fetch)) ||
    die "$(eval_gettext "Unable to fetch in submodule path '\$path'")"
  fi

There will not be a double-fetch, because the new $sha1 determined
after the `--remote` triggered fetch should always exist in the
repository.  If it doesn't, it's because some racy process removed it
from the submodule's repository and we *should* be re-fetching.

Signed-off-by: W. Trevor King <wking@tremily.us>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-12-19 09:40:01 -08:00
W. Trevor King 88ce00c378 submodule: add get_submodule_config helper funtion
Several submodule configuration variables
(e.g. fetchRecurseSubmodules) are read from .gitmodules with local
overrides from the usual git config files.  This shell function mimics
that logic to help initialize configuration variables in
git-submodule.sh.

Signed-off-by: W. Trevor King <wking@tremily.us>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-12-11 21:46:49 -08:00
Junio C Hamano 681b036fa0 Merge branch 'wtk/submodule-doc-fixup'
* wtk/submodule-doc-fixup:
  git-submodule: wrap branch option with "<>" in usage strings.
2012-11-21 13:25:42 -08:00
Junio C Hamano a1b3293936 Merge branch 'ph/submodule-sync-recursive'
Adds "--recursive" option to submodule sync.

* ph/submodule-sync-recursive:
  Add tests for submodule sync --recursive
  Teach --recursive to submodule sync
2012-11-15 10:24:01 -08:00
Jeff King b0b00a3ee4 Merge branch 'ph/maint-submodule-status-fix'
Cleans up some leftover bits from an earlier submodule change.

* ph/maint-submodule-status-fix:
  submodule status: remove unused orig_* variables
  t7407: Fix recursive submodule test
2012-11-09 12:51:15 -05:00
Jeff King 1777144781 Merge branch 'sz/maint-submodule-reference-arg'
* sz/maint-submodule-reference-arg:
  submodule add: fix handling of --reference=<repo> option
2012-11-04 08:00:16 -05:00
Jeff King fdb4d27158 Merge branch 'jl/submodule-add-by-name'
If you remove a submodule, in order to keep the repository so that
"git checkout" to an older commit in the superproject history can
resurrect the submodule, the real repository will stay in $GIT_DIR
of the superproject.  A later "git submodule add $path" to add a
different submodule at the same path will fail.  Diagnose this case
a bit better, and if the user really wants to add an unrelated
submodule at the same path, give the "--name" option to give it a
place in $GIT_DIR of the superproject that does not conflict with
the original submodule.

* jl/submodule-add-by-name:
  submodule add: Fail when .git/modules/<name> already exists unless forced
  Teach "git submodule add" the --name option
2012-10-29 04:12:12 -04:00
Phil Hord 82f49f294c Teach --recursive to submodule sync
The submodule sync command was somehow left out when
--recursive was added to the other submodule commands.

Teach sync to handle the --recursive switch by recursing
when we're in a submodule we are sync'ing.

Change the report during sync to show submodule-path
instead of submodule-name to be consistent with the other
submodule commands and to help recursed paths make sense.

Signed-off-by: Phil Hord <hordp@cisco.com>
Acked-By: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Jeff King <peff@peff.net>
2012-10-29 03:29:43 -04:00
Jens Lehmann e15bec0ec3 submodule status: remove unused orig_* variables
When renaming orig_args to orig_flags in 98dbe63d (submodule: only
preserve flags across recursive status/update invocations) the call site
of the recursive cmd_status was forgotten. At that place orig_args is
still passed into the recursion, which is always empty since then. This
did not break anything because the orig_flags logic is not needed at all
when a function from the submodule script is called with eval, as that
inherits all the variables set by the option parsing done in the first
level of the recursion.

Now that we know that orig_flags and orig_args aren't needed at all,
let's just remove them from cmd_status().

Thanks-to: Phil Hord <hordp@cisco.com>
Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Jeff King <peff@peff.net>
2012-10-29 03:25:50 -04:00
Stefan Zager 835460bba9 submodule add: fix handling of --reference=<repo> option
Doing a shift here is wrong because there is no extra
argument to consume when "--reference=<repo>" is used (note
the '=' instead of a space).

Signed-off-by: Stefan Zager <szager@google.com>
Signed-off-by: Jeff King <peff@peff.net>
2012-10-26 10:32:31 -04:00
W. Trevor King 38ae92e4d0 git-submodule: wrap branch option with "<>" in usage strings.
Use "-b <branch>" instead of "-b branch".  This brings the usage
strings in line with other options, e.g. "--reference <repository>".

Signed-off-by: W. Trevor King <wking@tremily.us>
Signed-off-by: Jeff King <peff@peff.net>
2012-10-25 04:46:13 -04:00
Junio C Hamano e2c7a5b646 Merge branch 'rr/maint-submodule-unknown-cmd' into maint
"git submodule frotz" was not diagnosed as "frotz" being an unknown
subcommand to "git submodule"; the user instead got a complaint that
"git submodule status" was run with an unknown path "frotz".

* rr/maint-submodule-unknown-cmd:
  submodule: if $command was not matched, don't parse other args
2012-10-02 13:42:32 -07:00
Jens Lehmann 4b7c286ec7 submodule add: Fail when .git/modules/<name> already exists unless forced
When adding a new submodule it can happen that .git/modules/<name> already
contains a submodule repo, e.g. when a submodule is removed from the work
tree and another submodule is added at the same path. But then the work
tree of the submodule will be populated using the existing repository and
not the one the user provided, which results in an incorrect work tree. On
the other hand the user might reactivate a submodule removed earlier, then
reusing that .git directory is the Right Thing to do.

As git can't decide what is the case, error out and tell the user she
should use either use a different name for the submodule with the "--name"
option or can reuse the .git directory for the newly added submodule by
providing the --force option (which only makes sense when the upstream
matches, so the error message lists all remotes of .git/modules/<name>).

In one test in t7406 the --force option had to be added to "git submodule
add", as that test re-adds a formerly removed submodule.

Reported-by: Jonathan Johnson <me@jondavidjohn.com>
Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-09-30 16:53:57 -07:00
Junio C Hamano da5a2bd525 Merge branch 'rr/maint-submodule-unknown-cmd'
* rr/maint-submodule-unknown-cmd:
  submodule: if $command was not matched, don't parse other args
2012-09-29 22:28:33 -07:00
Jens Lehmann 73b0898d0d Teach "git submodule add" the --name option
"git submodule add" initializes the name of a submodule to its path. This
was ok as long as the .git directory lived inside the submodule's work
tree, but since 1.7.8 it is stored in the .git/modules/<name> directory of
the superproject, making the submodule name survive the removal of the
submodule's work tree. This leads to problems when the user tries to add a
different submodule at the same path - and thus the same name - later, as
that will happily try to restore the submodule from the old repository
instead of the one the user specified and will lead to a checkout of the
wrong repository.

Add the new "--name" option to let the user provide a name for the
submodule. This enables the user to solve this conflict without having to
remove .git/modules/<name> by hand (which is no viable solution as it
makes it impossible to checkout a commit that records the old submodule
and populate it, as that will still check out the new submodule for the
same reason).

To achieve that the submodule's name is added to the parameter list of
the module_clone() helper function. This makes it possible to remove the
call of module_name() there because both callers of module_clone() already
know the name and can provide it as argument number two.

Reported-by: Jonathan Johnson <me@jondavidjohn.com>
Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-09-29 21:49:11 -07:00
Ramkumar Ramachandra af9c9f9713 submodule: if $command was not matched, don't parse other args
"git submodule" command DWIMs the command line and assumes a
unspecified action word for 'status' action.  This is a UI mistake
that leads to a confusing behaviour.  A mistyped command name is
instead treated as a request for 'status' of the submodule with that
name, e.g.

    $ git submodule show
    error: pathspec 'show' did not match any file(s) known to git.
    Did you forget to 'git add'?

Stop DWIMming an unknown or mistyped subcommand name as pathspec
given to unspelled "status" subcommand.  "git submodule" without any
argument is still interpreted as "git submodule status", but its
value is questionable.

Adjust t7400 to match, and stop advertising the default subcommand
being 'status' which does not help much in practice, other than
promoting laziness and confusion.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-09-25 11:31:48 -07:00
Junio C Hamano 1c88a6d174 Sync with 1.7.11.6
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-09-11 11:23:54 -07:00
Junio C Hamano ee7a83f631 Merge branch 'sz/submodule-force-update' into maint-1.7.11
* sz/submodule-force-update:
  Make 'git submodule update --force' always check out submodules.
2012-09-11 11:10:17 -07:00
Junio C Hamano 81dbbf7240 Merge branch 'sz/submodule-force-update'
"git submodule update --force" used to leave the working tree of the
submodule intact when there were local changes.  It is more intiutive
to make "--force" a sign to run "checkout -f" to overwrite them.

* sz/submodule-force-update:
  Make 'git submodule update --force' always check out submodules.
2012-09-03 15:54:18 -07:00
Junio C Hamano 1c0fa76be7 Merge branch 'hv/submodule-path-unmatch'
* hv/submodule-path-unmatch:
  Let submodule command exit with error status if path does not exist
2012-08-29 14:50:15 -07:00
Stefan Zager 01d4721565 Make 'git submodule update --force' always check out submodules.
Currently, it will only do a checkout if the sha1 registered in the containing
repository doesn't match the HEAD of the submodule, regardless of whether the
submodule is dirty.  As discussed on the mailing list, the '--force' flag is a
strong indicator that the state of the submodule is suspect, and should be reset
to HEAD.

Signed-off-by: Stefan Zager <szager@google.com>
Acked-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-08-24 09:00:43 -07:00
Heiko Voigt be9d0a3a4c Let submodule command exit with error status if path does not exist
Various subcommands of the "git submodule" command exited with 0
status even though the path given by the user did not exist.

The reason behind that was that they all pipe the output of
module_list into the while loop which then does the action on the
paths specified by the commandline. Since the exit code of the
command on the upstream side of the pipe is ignored by the shell,
the status code of "ls-files --error-unmatch" nor "module_list" was
not propagated.

In case ls-files returns with an error code, we write a special
string that is not possible in non error situations, and no other
output, so that the downstream can detect the error and die with an
error code.

The error message that there is an unmatched pathspec comes through
stderr directly from ls-files. So the user still gets a hint whats going
on.

Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-08-14 14:00:17 -07:00
Junio C Hamano 5fe1484a9b Merge branch 'jx/i18n-1.7.11'
Add i18n support for scripted Porcelains, and mark strings in
merge(-recursive), am, and rebase for i18n.

* jx/i18n-1.7.11:
  i18n: merge-recursive: mark strings for translation
  Remove dead code which contains bad gettext block
  i18n: am: mark more strings for translation
  rebase: remove obsolete and unused LONG_USAGE which breaks xgettext
  i18n: Rewrite gettext messages start with dash
  i18n: rebase: mark messages for translation
  i18n: New keywords for xgettext extraction from sh
2012-07-31 09:41:52 -07:00
Junio C Hamano 8ba105dda8 Merge branch 'jl/maint-1.7.10-recurse-submodules-with-symlink' into maint
When "git submodule add" clones a submodule repository, it can get
confused where to store the resulting submodule repository in the
superproject's .git/ directory when there is a symbolic link in the
path to the current directory.

* jl/maint-1.7.10-recurse-submodules-with-symlink:
  submodules: don't stumble over symbolic links when cloning recursively
2012-07-30 13:04:18 -07:00
Jiang Xin 465d6a00e9 i18n: Rewrite gettext messages start with dash
Gettext message in a shell script should not start with '-', one
workaround is adding '--' between gettext and the message, like:

    gettext -- "--exec option ..."

But due to a bug in the xgettext extraction, xgettext can not
extract the actual message for this case. Rewriting the message
is a simpler and better solution.

Reported-by: Vincent van Ravesteijn <vfr@lyx.org>
Signed-off-by: Jiang Xin <worldhello.net@gmail.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Reviewed-by: Stefano Lattarini <stefano.lattarini@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-07-26 22:33:37 -07:00
Daniel Graña be8779f7ac git-submodule: work with GIT_DIR/GIT_WORK_TREE
The combination of GIT_DIR and GIT_WORK_TREE can be used to manage
files in one directory hierarchy while keeping the repository that
keeps track of them outside the directory hierarchy.  For example:

    git init --bare /path/to/there
    alias dotfiles="GIT_DIR=/path/to/there GIT_WORK_TREE=/path/to/here git"

    cd /path/to/here
    dotfiles add file
    dotfiles commit -a -m "add /path/to/here/file"
    ...

lets you manage files under /path/to/here/ in the repository located
at /path/to/there.

git-submodule however fails to add submodules, as it is confused by
GIT_DIR and GIT_WORK_TREE environment variables when it tries to
work in the submodule, like so:

    dotfiles submodule add http://path.to/submodule
    fatal: working tree '/path/to/here' already exists.

Simply unsetting the environment where the command works on the
submodule is sufficient to fix this, as it has set things up so
that GIT_DIR and GIT_WORK_TREE do not even have to point at the
repository and the working tree of the submodule.

Signed-off-by: Daniel Graña <dangra@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-07-25 11:33:24 -07:00
Junio C Hamano 15b3c82cbb Merge branch 'jl/maint-1.7.10-recurse-submodules-with-symlink'
When "git submodule add" clones a submodule repository, it can get
confused where to store the resulting submodule repository in the
superproject's .git/ directory when there is a symbolic link in the
path to the current directory.

* jl/maint-1.7.10-recurse-submodules-with-symlink:
  submodules: don't stumble over symbolic links when cloning recursively
2012-07-22 12:55:48 -07:00
Jens Lehmann 6eafa6d096 submodules: don't stumble over symbolic links when cloning recursively
Since 69c3051 (submodules: refactor computation of relative gitdir path)
cloning a submodule recursively fails for nested submodules when a
symbolic link is part of the path to the work tree of the superproject.

This happens when module_clone() tries to find the relative paths between
the work tree and the git dir. When a symbolic link in current $PWD points
to a directory that is at a different level, then determining the number
of "../" needed to traverse to the superproject's work tree leads to a
wrong result.

As there is no portable way to say "pwd -P", use cd_to_toplevel to remove
the link from $PWD, which fixes this problem.

A test for this issue has been added to t7406.

Reported-by: Bob Halley <halley@play-bow.org>
Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-07-12 11:14:40 -07:00
Junio C Hamano a3fbb2350d Merge branch 'js/submodule-relative'
Teach "git submodule" deal with nested submodule structure where a
module is contained within a module whose origin is specified as a
relative URL to its superproject's origin.
2012-06-28 15:20:55 -07:00
Michał Górny 4c8a9db6f7 git-submodule.sh: fix filename in comment.
Signed-off-by: Michał Górny <mgorny@gentoo.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-06-25 11:09:35 -07:00
Jon Seymour 758615e251 submodule: fix handling of superproject origin URLs like foo, ./foo and ./foo/bar
Currently git submodule init and git submodule sync fail with an error
if the superproject origin URL is of the form foo but succeed if the
superproject origin URL is of the form ./foo or ./foo/bar or foo/bar.

This change makes handling of the foo case behave like the handling
of the ./foo case and also ensures that superfluous leading and
embedded ./'s are removed from the resulting derived URLs.

Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-06-06 11:43:55 -07:00
Jon Seymour 967b2c6673 submodule: fix sync handling of some relative superproject origin URLs
When the origin URL of the superproject is itself relative, git submodule sync
configures the remote.origin.url configuration property of the submodule
with a path that is relative to the work tree of the superproject
rather than the work tree of the submodule.

To fix this an 'up_path' that navigates from the work tree of the submodule
to the work tree of the superproject needs to be prepended to the URL
otherwise calculated.

Correct handling of superproject origin URLs like foo, ./foo and ./foo/bar is
left to a subsequent patch since an additional change is required to handle
these cases.

The documentation of resolve_relative_url() is expanded to give a more thorough
description of the function's objective.

Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-06-06 11:40:59 -07:00
Jens Lehmann c1c259e225 submodules: print "registered for path" message only once
Since 2cd9de3e (submodule add: always initialize .git/config entry) the
message "Submodule '\$name' (\$url) registered for path '\$sm_path'" is
printed every time cmd_init() is called, e.g. each time "git submodule
update" is used with the --init option.

This was not intended and leads to bogus output which can confuse users
and build systems. Apart from that the $url variable was not set after the
first run which did the actual initialization and only "()" was printed
in subsequent runs where "($url)" was meant to inform the user about the
upstream repo.

Fix that by moving the say command in question into the if block where the
url is initialized, restoring the behavior that was in place before the
2cd9de3e commit. While at it also remove the comment which still describes
the logic used before 2cd9de3e and add a comment about how things work now.

Reported-by: Nicolas Viennot and Sid Nair <nicolas@viennot.com>
Reported-by: Heiko Voigt <hvoigt@hvoigt.net>
Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-05-29 13:52:23 -07:00
Junio C Hamano 8ea07808c1 Merge branch 'rj/submodule-mswin-path'
By Ramsay Jones
* rj/submodule-mswin-path:
  git-submodule.sh: Don't use $path variable in eval_gettext string
2012-04-23 13:01:49 -07:00
Ramsay Jones 64394e3ae9 git-submodule.sh: Don't use $path variable in eval_gettext string
The eval_gettext (and eval_gettextln) i18n shell functions call
git-sh-i18n--envsubst to process the variable references in the
string parameter. Unfortunately, environment variables are case
insensitive on windows, which leads to failure on cygwin when
eval_gettext exports $path.

Commit df599e9 (Windows: teach getenv to do a case-sensitive search,
06-06-2011) attempts to solve this problem on MinGW by overriding
the system getenv() function to allow git-sh-i18n--envsubst to read
$path rather than $PATH from the environment. However, this commit
does not address cygwin at all and, furthermore, does not fix all
problems on MinGW.

In particular, when executing test #38 in t7400-submodule-basic.sh,
an 'git-sh-i18n-envsubst.exe - Unable To Locate Component' dialog
pops up saying that the application "failed to start because
libiconv2.dll was not found." After studying the voluminous trace
output from the process monitor, it is clear that the system is
attempting to use $path, rather than $PATH, to search for the DLL
file. (Note that, after dismissing the dialog, the test passes
anyway!)

As an alternative, we finesse the problem by renaming the $path
variable to $sm_path (submodule path). This fixes the problem on
MinGW along with all test failures on cygwin (t7400.{7,32,34},
t7406.3 and t7407.{2,6}). We note that the foreach subcommand
provides $path to user scripts (ie it is part of the API), so we
can't simply rename it to $sm_path.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Acked-by: Jens Lehmann <Jens.Lehmann@web.de>
Tested-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-04-18 13:05:33 -07:00
Ben Walton c5bc42b9b7 Avoid bug in Solaris xpg4/sed as used in submodule
The sed provided by Solaris in /usr/xpg4/bin has a bug whereby an
unanchored regex using * for zero or more repetitions sees two
separate matches fed to the substitution engine in some cases.

This is evidenced by:

$ for sed in /usr/xpg4/bin/sed /usr/bin/sed /opt/csw/gnu/sed; do \
echo 'ab' | $sed -e 's|[a]*|X|g'; \
done
XXbX
XbX
XbX

This bug was triggered during a git submodule clone operation as
exercised in the setup stage of t5526-fetch-submodules when using the
default SANE_TOOL_PATH for Solaris.  It led to paths such as
..../.. being used in the submodule .git gitdir reference.

Using the expression 's|\([^/]*\(/*\)\)|..\2|g' provides the desired
result with all three three tested sed implementations but is harder
to read.  As we do not need to handle fully qualified paths though,
the expression could actually be [^/]+ which isn't properly handled
either.  Instead, use [^/][^/]*, as suggested by Andreas Schwab, which
works on all three tested sed implementations.

The new expression is semantically different than the original one.
It will not place a leading '..' on a fully qualified path as the
original expression did.  All of the paths being passed through this
regex are relative and did not rely on this behaviour so it's a safe
change.

Signed-off-by: Ben Walton <bwalton@artsci.utoronto.ca>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-04-09 14:49:32 -07:00
Johannes Sixt 4dce7d9b40 submodules: fix ambiguous absolute paths under Windows
Under Windows the "git rev-parse --git-dir" and "pwd" commands may return
either drive-letter-colon or POSIX style paths. This makes module_clone()
behave badly because it expects absolute paths to always start with a '/'.

Fix that by always converting the "c:/" notation into "/c/" when computing
the relative paths from gitdir to the submodule work tree and back.

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-03-04 21:22:46 -08:00
Jens Lehmann 69c3051780 submodules: refactor computation of relative gitdir path
In module_clone() the rel_gitdir variable was computed differently when
"git rev-parse --git-dir" returned a relative path than when it returned
an absolute path. This is not optimal, as different code paths are used
depending on the return value of that command.

Fix that by reusing the differing path components computed for setting the
core.worktree config setting, which leaves a single code path for setting
both instead of having three and makes the code much shorter.

This also fixes the bug that in the computation of how many directories
have to be traversed up to hit the root directory of the submodule the
name of the submodule was used where the path should have been used. This
lead to problems after renaming submodules into another directory level.

Even though the "(cd $somewhere && pwd)" approach breaks the flexibility
of symlinks, that is no issue here as we have to have one relative path
pointing from the work tree to the gitdir and another pointing back, which
will never work anyway when a symlink along one of those paths is changed
because the directory it points to was moved.

Also add a test moving a submodule into a deeper directory to catch any
future breakage here and to document what has to be done when a submodule
needs to be moved until git mv learns to do that. Simply moving it to the
new location doesn't work, as the core.worktree and possibly the gitfile
setting too will be wrong. So it has to be removed from filesystem and
index, then the new location has to be added into the index and the
.gitmodules file has to be updated. After that a git submodule update will
check out the submodule at the new location.

Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-03-04 21:22:35 -08:00
Jens Lehmann d75219b4a8 submodules: always use a relative path from gitdir to work tree
Since recently a submodule with name <name> has its git directory in the
.git/modules/<name> directory of the superproject while the work tree
contains a gitfile pointing there. To make that work the git directory has
the core.worktree configuration set in its config file to point back to
the work tree.

That core.worktree is an absolute path set by the initial clone of the
submodule. A relative path is preferable here because it allows the
superproject to be moved around without invalidating that setting, so
compute and set that relative path after cloning or reactivating the
submodule.

This also fixes a bug when moving a submodule around inside the
superproject, as the current code forgot to update the setting to the new
submodule work tree location.

Enhance t7400 to ensure that future versions won't re-add absolute paths
by accident and that moving a superproject won't break submodules.

Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-03-04 21:20:27 -08:00
Jens Lehmann ea115a0d43 submodules: always use a relative path to gitdir
Since recently a submodule with name <name> has its git directory in the
.git/modules/<name> directory of the superproject while the work tree
contains a gitfile pointing there. When the submodule git directory needs
to be cloned because it is not found in .git/modules/<name> the clone
command will write an absolute path into the gitfile. When no clone is
necessary the git directory will be reactivated by the git-submodule.sh
script by writing a relative path into the gitfile.

This is inconsistent, as the behavior depends on the submodule having been
cloned before into the .git/modules of the superproject. A relative path
is preferable here because it allows the superproject to be moved around
without invalidating the gitfile. We do that by always writing the
relative path into the gitfile, which overwrites the absolute path the
clone command may have written there.

This is only the first step to make superprojects movable again like they
were before the separate-git-dir approach was introduced. The second step
is to use a relative path in core.worktree too.

Enhance t7400 to ensure that future versions won't re-add absolute paths
by accident.

While at it also replace an if/else construct evaluating the presence
of the 'reference' option with a single line of bash code.

Reported-by: Antony Male <antony.male@gmail.com>
Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-03-04 21:19:41 -08:00
Jens Lehmann 1017c1abcb submodule add: fix breakage when re-adding a deep submodule
Since recently a submodule with name <name> has its git directory in the
.git/modules/<name> directory of the superproject while the work tree
contains a gitfile pointing there.

When the same submodule is added on a branch where it wasn't present so
far (it is not found in the .gitmodules file), the name is not initialized
from the path as it should. This leads to a wrong path entered in the
gitfile when the .git/modules/<name> directory is found, as this happily
uses the - now empty - name. It then always points only a single directory
up, even if we have a path deeper in the directory hierarchy.

Fix that by initializing the name of the submodule early in module_clone()
if module_name() returned an empty name and add a test to catch that bug.

Reported-by: Jehan Bing <jehan@orb.com>
Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-01-24 14:18:18 -08:00
Junio C Hamano 0b26d1e8b2 Merge branch 'tc/submodule-clone-name-detection'
* tc/submodule-clone-name-detection:
  submodule::module_clone(): silence die() message from module_name()
  submodule: whitespace fix
2011-10-26 16:16:32 -07:00
Tay Ray Chuan 9e76d4a834 submodule::module_clone(): silence die() message from module_name()
The die() message that may occur in module_name() is not really relevant
to the user when called from module_clone(); the latter handles the
"failure" (no submodule mapping) anyway.

Analysis of other callsites is left to future work.

Acked-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-10-21 10:02:02 -07:00
Tay Ray Chuan 1e42258acd submodule: whitespace fix
Replace SPs with TAB.

Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-10-21 10:01:50 -07:00
Junio C Hamano efc5fb6a77 Merge branch 'fg/submodule-git-file-git-dir'
* fg/submodule-git-file-git-dir:
  Move git-dir for submodules
  rev-parse: add option --resolve-git-dir <path>

Conflicts:
	cache.h
	git-submodule.sh
2011-10-10 15:56:17 -07:00
Junio C Hamano 957450054c Merge branch 'js/i18n-scripts'
* js/i18n-scripts:
  submodule: take advantage of gettextln and eval_gettextln.
  stash: take advantage of eval_gettextln
  pull: take advantage of eval_gettextln
  git-am: take advantage of gettextln and eval_gettextln.
  gettext: add gettextln, eval_gettextln to encode common idiom
2011-08-25 16:00:16 -07:00
Fredrik Gustafsson 501770e1bb Move git-dir for submodules
Move git-dir for submodules into $GIT_DIR/modules/[name_of_submodule] of
the superproject. This is a step towards being able to delete submodule
directories without loosing the information from their .git directory
as that is now stored outside the submodules work tree.

This is done relying on the already existent .git-file functionality.
When adding or updating a submodule whose git directory is found under
$GIT_DIR/modules/[name_of_submodule], don't clone it again but simply
point the .git-file to it and remove the now stale index file from it.
The index will be recreated by the following checkout.

This patch will not affect already cloned submodules at all.

Tests that rely on .git being a directory have been fixed.

Signed-off-by: Fredrik Gustafsson <iveqy@iveqy.com>
Mentored-by: Jens Lehmann <Jens.Lehmann@web.de>
Mentored-by: Heiko Voigt <hvoigt@hvoigt.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-08-22 21:03:38 -07:00
Junio C Hamano 86c9cd8d25 Merge branch 'jl/submodule-update-quiet'
* jl/submodule-update-quiet:
  submodule: update and add must honor --quiet flag
2011-08-08 12:33:34 -07:00
Jon Seymour 6ff875c52a submodule: take advantage of gettextln and eval_gettextln.
Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-08-08 12:05:27 -07:00
Jens Lehmann 7e60407f7a submodule: update and add must honor --quiet flag
When using the --quiet flag "git submodule update" and "git submodule add"
didn't behave as the documentation stated. They printed progress output
from the clone, even though they should only print error messages.

Fix that by passing the -q flag to git clone in module_clone() when the
GIT_QUIET variable is set. Two tests in t7400 have been modified to test
that behavior.

Reported-by: Daniel Holtmann-Rice <flyingtabmow@gmail.com>
Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-07-28 12:48:26 -07:00
Junio C Hamano c56dce3b81 Merge branch 'jl/submodule-add-relurl-wo-upstream'
* jl/submodule-add-relurl-wo-upstream:
  submodule add: clean up duplicated code
  submodule add: allow relative repository path even when no url is set
  submodule add: test failure when url is not configured in superproject

Conflicts:
	git-submodule.sh
2011-07-22 14:24:35 -07:00
Junio C Hamano 0591c0a5be Merge branch 'jc/submodule-sync-no-auto-vivify'
* jc/submodule-sync-no-auto-vivify:
  submodule add: always initialize .git/config entry
  submodule sync: do not auto-vivify uninteresting submodule

Conflicts:
	git-submodule.sh
2011-07-19 09:45:37 -07:00
Junio C Hamano 13ac90a478 Merge branch 'bc/submodule-foreach-stdin-fix-1.7.4'
* bc/submodule-foreach-stdin-fix-1.7.4:
  git-submodule.sh: preserve stdin for the command spawned by foreach
  t/t7407: demonstrate that the command called by 'submodule foreach' loses stdin

Conflicts:
	git-submodule.sh
2011-07-13 14:31:37 -07:00
Junio C Hamano ff968f03e6 Merge branch 'fg/submodule-keep-updating'
* fg/submodule-keep-updating:
  git-submodule.sh: clarify the "should we die now" logic
  submodule update: continue when a checkout fails
  git-sh-setup: add die_with_status

Conflicts:
	git-submodule.sh
2011-07-13 14:31:35 -07:00
Brandon Casey 4dca1aa650 git-submodule.sh: preserve stdin for the command spawned by foreach
The user-supplied command spawned by 'submodule foreach' loses its
connection to the original standard input.  Instead, it is connected to the
output of a pipe within the git-submodule script.  The user-supplied
command supplied to 'submodule foreach' is spawned within a while loop
which is being piped into.  Due to the way shells implement piping output
to a while loop, a subshell is created with its standard input attached to
the output of the pipe.  This results in all of the commands executed
within the while loop to have their stdins modified in the same way,
including the user-supplied command.

This can cause a problem if the command requires reading from stdin or if
it changes its behavior based on whether stdin is a tty or not.  For
example, this problem was noticed when trying to execute the following:

   git submodule foreach git shortlog --since=two.weeks.ago

which printed a message about entering the first submodule and produced no
further output and exited with a status of zero.  In this case, shortlog
detected that it was not connected to a tty, and since no revision was
supplied as an argument, it attempted to read the list of revisions from
standard input.  Instead, it slurped up the list of submodules that was
being piped to the enclosing while loop and caused that loop to end early
without processing the remaining submodules.

Work around this behavior by saving the original standard input file
descriptor before the while loop, and restoring it when spawning the
user-supplied command.

This fixes the tests in t7407.

Signed-off-by: Brandon Casey <drafnel@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-06-29 18:25:49 -07:00
Junio C Hamano 61f44720a9 Merge branch 'ab/i18n-scripts' into next
* ab/i18n-scripts: (48 commits)
  i18n: git-bisect bisect_next_check "You need to" message
  i18n: git-bisect [Y/n] messages
  i18n: git-bisect bisect_replay + $1 messages
  i18n: git-bisect bisect_reset + $1 messages
  i18n: git-bisect bisect_run + $@ messages
  i18n: git-bisect die + eval_gettext messages
  i18n: git-bisect die + gettext messages
  i18n: git-bisect echo + eval_gettext message
  i18n: git-bisect echo + gettext messages
  i18n: git-bisect gettext + echo message
  i18n: git-bisect add git-sh-i18n
  i18n: git-stash drop_stash say/die messages
  i18n: git-stash "unknown option" message
  i18n: git-stash die + eval_gettext $1 messages
  i18n: git-stash die + eval_gettext $* messages
  i18n: git-stash die + eval_gettext messages
  i18n: git-stash die + gettext messages
  i18n: git-stash say + gettext messages
  i18n: git-stash echo + gettext message
  i18n: git-stash add git-sh-i18n
  ...
2011-06-29 17:09:27 -07:00
Jens Lehmann 2cd9de3e18 submodule add: always initialize .git/config entry
When "git submodule add $path" is run to add a subdirectory $path to the
superproject, and $path is already the top of the working tree of the
submodule repository, the command created submodule.$path.url entry in the
configuration file in the superproject. However, when adding a repository
$URL that is outside the respository of the superproject to $path that
does not exist (yet) with "git submodule add $URL $path", the command
forgot to set it up.

The user is expressing the interest in the submodule and wants to keep a
checkout, the "submodule add" command should consistently set up the
submodule.$path.url entry in either case.

As a result "git submodule init" can't simply skip the initialization of
those submodules for which it finds an url entry in the git./config
anymore. That lead to problems when adding a submodule (which now sets the
url), add the "update" setting to .gitmodules and expect init to copy that
into .git/config like it is done in t7406. So change init to only then
copy the "url" and "update" entries when they don't exist yet in the
.git/config and do nothing otherwise.

Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-06-26 13:15:21 -07:00
Junio C Hamano ccee60862b submodule sync: do not auto-vivify uninteresting submodule
Earlier 33f072f (submodule sync: Update "submodule.<name>.url" for empty
directories, 2010-10-08) attempted to fix a bug where "git submodule sync"
command does not update the URL if the current superproject does not have
a checkout of the submodule.

However, it did so by unconditionally registering submodule.$name.url to
every submodule in the project, even the ones that the user has never
showed interest in at all by running 'git submodule init' command. This
caused subsequent 'git submodule update' to start cloning/updating submodules
that are not interesting to the user at all.

Update the code so that the URL is updated from the .gitmodules file only
for submodules that already have submodule.$name.url entries, i.e. the
ones the user has showed interested in having a checkout.

Acked-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-06-26 13:06:08 -07:00
Junio C Hamano 877449c136 git-submodule.sh: clarify the "should we die now" logic
Earlier the decision to stop or continue was made on the $action variable
that was set by inspecting $update_module variable. The former is a
redundant variable and will be removed in another topic.

Decide upon inspecting $update_module if a failure should cascade up to
cause us immediately stop, and use a variable that means just that, to
clarify the logic.

Incidentally this also makes the merge with the other topic slightly
easier and cleaner to understand.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-06-13 12:18:29 -07:00
Fredrik Gustafsson 15ffb7cde4 submodule update: continue when a checkout fails
"git submodule update" stops at the first error and gives control
back to the user. Only after the user fixes the problematic
submodule and runs "git submodule update" again, the second error
is found. And the user needs to repeat until all the problems are
found and fixed one by one. This is tedious.

Instead, the command can remember which submodules it had trouble with,
continue updating the ones it can, and report which ones had errors at
the end. The user can run "git submodule update", find all the ones that
need minor fixing (e.g. working tree was dirty) to fix them in a single
pass. Then another "git submodule update" can be run to update all.

Note that the problematic submodules are skipped only when they are to
be integrated with a safer value of submodule.<name>.update option,
namely "checkout". Fixing a failure in a submodule that uses "rebase" or
"merge" may need an involved conflict resolution by the user, and
leaving too many submodules in states that need resolution would not
reduce the mental burden on the user.

Signed-off-by: Fredrik Gustafsson <iveqy@iveqy.com>
Mentored-by: Jens Lehmann <Jens.Lehmann@web.de>
Mentored-by: Heiko Voigt <hvoigt@hvoigt.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-06-13 11:24:48 -07:00
Jens Lehmann f22a17e8da submodule add: clean up duplicated code
In cmd_add() the switch statement used to resolve a relative url was
present twice. Remove the second one and use the realrepo variable set
by the first one (lines 194 ff.) instead.

Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-06-06 13:46:36 -07:00
Jens Lehmann 4d68932004 submodule add: allow relative repository path even when no url is set
Adding a submodule with a relative repository path did only succeed when
the superproject's default remote was set. But when that is unset, the
superproject is its own authoritative upstream, so lets use its working
directory as upstream instead.

This allows users to set up a new superpoject where the submodules urls
are configured relative to the superproject's upstream while its default
remote can be configured later.

Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-06-06 13:46:36 -07:00
Junio C Hamano fb674d7671 Merge branch 'maint'
* maint:
  git-submodule.sh: separate parens by a space to avoid confusing some shells
  Documentation/technical/api-diff.txt: correct name of diff_unmerge()
  read_gitfile_gently: use ssize_t to hold read result
  remove tests of always-false condition
  rerere.c: diagnose a corrupt MERGE_RR when hitting EOF between TAB and '\0'
2011-05-30 00:09:55 -07:00
Brandon Casey f5799e05c0 git-submodule.sh: separate parens by a space to avoid confusing some shells
Some shells interpret '(( ))' according to the rules for arithmetic
expansion.  This may not follow POSIX, but is prevalent in commonly used
shells.  Bash does not have a problem with this particular instance of
'((', likely because it is not followed by a '))', but the public domain
ksh does, and so does ksh on IRIX 6.5.

So, add a space between the parenthesis to avoid confusing these shells.

Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-05-26 15:04:05 -07:00
Ævar Arnfjörð Bjarmason b3e7344964 i18n: git-submodule "blob" and "submodule" messages
Gettextize the words "blob" and "submodule", which will be
interpolated in a message emitted by git-submodule. This is
explicitly tested for so we need to skip a portion of a test with
test_i18ncmp.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-05-21 11:57:16 -07:00
Ævar Arnfjörð Bjarmason 1c2ef66f63 i18n: git-submodule "path not initialized" message
Gettextize the "Submodule path '$path' not initialized" message. This
is explicitly tested for so we need to skip a portion of a test with
test_i18grep.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-05-21 11:57:16 -07:00
Ævar Arnfjörð Bjarmason 3a4c3ed7e8 i18n: git-submodule "[...] path is ignored" message
Gettextize the "The following path is ignored" message. This is
explicitly tested for so we need to skip a portion of a test with
test_i18ncmp.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-05-21 11:57:16 -07:00
Ævar Arnfjörð Bjarmason 490b6d5749 i18n: git-submodule "Entering [...]" message
Gettextize the "Entering [...]" message. This is explicitly tested for
so we need to skip a portion of a test with test_i18ncmp.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-05-21 11:57:16 -07:00
Ævar Arnfjörð Bjarmason f62f8212e1 i18n: git-submodule $errmsg messages
Gettextize warning messages stored in the $errmsg variable using
eval_gettext interpolation. This is explicitly tested for so we
need to skip a portion of a test with test_i18ncmp.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-05-21 11:57:16 -07:00
Ævar Arnfjörð Bjarmason 165119e9e6 i18n: git-submodule "Submodule change[...]" messages
Gettextize the "Submodules changed but not updated" and "Submodule
changes to be committed" messages. This is explicitly tested for so we
need to skip a portion of a test with test_i18ncmp.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-05-21 11:57:16 -07:00
Ævar Arnfjörð Bjarmason b9b9c22f6d i18n: git-submodule "cached cannot be used" message
Gettextize the "--cached cannot be used with --files" message. Since
this message starts with "--" we have to pass "--" as the first
argument. This works with both GNU gettext 0.18.1 (as expected), and
the gettext(1) on Solaris 10.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-05-21 11:57:16 -07:00
Ævar Arnfjörð Bjarmason ee653c89ff i18n: git-submodule $update_module say + die messages
Gettextize $update_module say and die messages. These messages needed
to be split up to make them translatable.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-05-21 11:57:16 -07:00
Ævar Arnfjörð Bjarmason 497ee87245 i18n: git-submodule die + eval_gettext messages
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-05-21 11:57:15 -07:00
Ævar Arnfjörð Bjarmason 8f3f2c44c5 i18n: git-submodule say + eval_gettext messages
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-05-21 11:57:15 -07:00
Ævar Arnfjörð Bjarmason dc2204fe32 i18n: git-submodule echo + eval_gettext messages
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-05-21 11:57:15 -07:00
Ævar Arnfjörð Bjarmason d0ad825110 i18n: git-submodule add git-sh-i18n
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-05-21 11:57:15 -07:00
Junio C Hamano 0d405d72f5 Merge branch 'nm/submodule-update-force'
* nm/submodule-update-force:
  submodule: Add --force option for git submodule update

Conflicts:
	t/t7406-submodule-update.sh
2011-05-02 15:58:36 -07:00
Junio C Hamano 2071fb015b Merge branch 'jl/submodule-fetch-on-demand'
* jl/submodule-fetch-on-demand:
  fetch/pull: Describe --recurse-submodule restrictions in the BUGS section
  submodule update: Don't fetch when the submodule commit is already present
  fetch/pull: Don't recurse into a submodule when commits are already present
  Submodules: Add 'on-demand' value for the 'fetchRecurseSubmodule' option
  config: teach the fetch.recurseSubmodules option the 'on-demand' value
  fetch/pull: Add the 'on-demand' value to the --recurse-submodules option
  fetch/pull: recurse into submodules when necessary

Conflicts:
	builtin/fetch.c
	submodule.c
2011-04-04 15:02:01 -07:00
Nicolas Morey-Chaisemartin 9db31bdf5c submodule: Add --force option for git submodule update
By default git submodule update runs a simple checkout on submodules that
are not up-to-date. If the submodules contains modified or untracked
files, the command may exit sanely with an error:

  $ git submodule update
  error: Your local changes to the following files would be overwritten by
  checkout:
	  file
  Please, commit your changes or stash them before you can switch branches.
  Aborting
  Unable to checkout '1b69c6e55606b48d3284a3a9efe4b58bfb7e8c9e' in
  submodule path 'test1'

In order to reset a whole git submodule tree, a user has to run first 'git
submodule foreach --recursive git checkout -f' and then run 'git submodule
update'.

This patch adds a --force option for the update command (only used for
submodules without --rebase or --merge options). It passes the --force
option to git checkout which will throw away the local changes.

Signed-off-by: Nicolas Morey-Chaisemartin <nmorey@kalray.eu>
Acked-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-04-04 10:50:50 -07:00