git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jens Lehmann <Jens.Lehmann@web.de>
To: Jonathan Johnson <me@jondavidjohn.com>
Cc: Git Mailing List <git@vger.kernel.org>,
	Heiko Voigt <hvoigt@hvoigt.net>,
	Junio C Hamano <gitster@pobox.com>
Subject: [PATCH 0/2] Let "git submodule add" fail when .git/modules/<name> already exists
Date: Sun, 30 Sep 2012 01:04:22 +0200	[thread overview]
Message-ID: <50677E76.1050204@web.de> (raw)
In-Reply-To: <50636C00.6080906@web.de>

Am 26.09.2012 22:56, schrieb Jens Lehmann:
> Am 26.09.2012 06:18, schrieb Jonathan Johnson:
>> To reproduce
>>
>> 1) add a git submodule in a specific location (we'll say it's at `./submodule/location`)
>> 2) go through the normal steps of removing a submodule, as listed here - https://git.wiki.kernel.org/index.php/GitSubmoduleTutorial
>> 3) Now the submodule is completely removed and there is no reference to it in .gitmodules or .git/config
>> 4) Re-add a different repository at the same location (`./submodule/location`)
>>
>> Expected - The new submodule repository will be set up at ./submodule/location and have the new repository as its origin
>>
>> What Actually Happens - The new submodule uses the existing `$gitdir` (old repository) as the actual backing repository to the submodule, but the new repository is reflected in .gitmodules and .git/config.
>>
>> So to recap, the result is that `git remote show origin`  in the submodule shows a different origin than is in .gitmodules and .git/config
>>
>> One simple step to remedy this would be to add the deletion of the backing repository from the .git/modules directory, but again, I think an actual command to take care of all of these steps is in order anyways.  Not sure you want to encourage people poking around in the .git directory.
> 
> Unfortunately just throwing away the old repository under .git/modules,
> whether manually or by a git command, is no real solution here: it would
> make it impossible to go back to a commit which records the old submodule
> and check that out again.
> 
> The reason for this issue is that the submodule path is used as its name
> by "git submodule add". While we could check this type of conflict locally,
> we can't really avoid it due to the distributed nature of git (somebody
> else could add a different repo under the same path - and thus the same
> name - in another clone of the repo).
> 
> The only long term solution I can think of is to use some kind of UUID for
> the name, so that the names of newly added submodules won't have a chance
> to clash anymore. For the short term aborting "git submodule add" when a
> submodule of that name already exists in .git/modules of the superproject
> together with the ability to provide a custom name might at least solve
> the local clashes.

This two patch series implements the short term solution described above.

Using some kind of UUID can easily be added in a subsequent patch, we just
have to replace 'sm_name="$sm_path"' with 'sm_name=$(<generate uuid>)' in
line 348 of git-submodule.sh. I think it'll be the best solution to just
use a random UUID for that, as doing anything clever (like using the SHA1
of the url to avoid copies of the same remote repo) might lead to subtle
breakages (e.g. because it assumes the url stays unique forever, which it
sometimes won't). But maybe the short term solution is sufficient as most
of the time people won't produce submodule name conflicts (and names
derived from paths are much more readable that UUIDs). Thoughts?


Jens Lehmann (2):
  Teach "git submodule add" the --name option
  submodule add: Fail when .git/modules/<name> already exists

 Documentation/git-submodule.txt |  7 ++++-
 Documentation/gitmodules.txt    |  4 ++-
 git-submodule.sh                | 35 ++++++++++++++++-------
 t/t7400-submodule-basic.sh      | 63 +++++++++++++++++++++++++++++++++++++++++
 t/t7406-submodule-update.sh     |  2 +-
 5 files changed, 97 insertions(+), 14 deletions(-)

-- 
1.7.12.1.430.g4fd6dc4

  reply	other threads:[~2012-09-29 23:04 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-26  4:18 Bug in Submodule add Jonathan Johnson
2012-09-26 20:56 ` Jens Lehmann
2012-09-29 23:04   ` Jens Lehmann [this message]
2012-09-29 23:05     ` [PATCH 1/2] Teach "git submodule add" the --name option Jens Lehmann
2012-09-29 23:07     ` [PATCH 2/2] submodule add: Fail when .git/modules/<name> already exists Jens Lehmann
2012-09-30  4:47     ` [PATCH 0/2] Let "git submodule add" fail " Junio C Hamano
2012-09-30 19:19       ` Jens Lehmann
2012-09-30 21:01         ` [PATCH v2 2/2] submodule add: Fail when .git/modules/<name> already exists unless forced Jens Lehmann
2012-10-01  0:06           ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50677E76.1050204@web.de \
    --to=jens.lehmann@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=hvoigt@hvoigt.net \
    --cc=me@jondavidjohn.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).