From: "Lars Hjemli" <hjemli@gmail.com>
To: "Junio C Hamano" <gitster@pobox.com>
Cc: "Petr Baudis" <pasky@suse.cz>,
git@vger.kernel.org, "Mark Levedahl" <mlevedahl@gmail.com>
Subject: Re: [PATCH 6/6] git submodule add: Fix naming clash handling
Date: Sat, 13 Sep 2008 13:32:38 +0200 [thread overview]
Message-ID: <8c5c35580809130432r11e986e5u4c7300d62ca2896f@mail.gmail.com> (raw)
In-Reply-To: <7v63p0n5pv.fsf@gitster.siamese.dyndns.org>
On Sat, Sep 13, 2008 at 4:24 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Petr Baudis <pasky@suse.cz> writes:
>
>> This patch fixes git submodule add behaviour when we add submodule
>> living at a same path as logical name of existing submodule. This
>> can happen e.g. in case the user git mv's the previous submodule away
>> and then git submodule add's another under the same name.
>
> In short, name "example" was used to name the submodule bound at path
> "init" in earlier tests, and the new one adds another submodule whose name
> and path are both "example" and makes sure they do not get mixed up (and
> the original code did mix them up).
>
>> git-submodule.sh | 15 ++++++++++++---
>> t/t7400-submodule-basic.sh | 11 +++++++++++
>> 2 files changed, 23 insertions(+), 3 deletions(-)
>>
>> diff --git a/git-submodule.sh b/git-submodule.sh
>> index 1c39b59..3e4d839 100755
>> --- a/git-submodule.sh
>> +++ b/git-submodule.sh
>> @@ -201,10 +201,19 @@ cmd_add()
>> git add "$path" ||
>> die "Failed to add submodule '$path'"
>>
>> - git config -f .gitmodules submodule."$path".path "$path" &&
>> - git config -f .gitmodules submodule."$path".url "$repo" &&
>> + name="$path"
>> + if git config -f .gitmodules submodule."$name".path; then
>> + name="$path~"; i=1;
>> + while git config -f .gitmodules submodule."$name".path; do
>> + name="$path~$i"
>> + i=$((i+1))
>> + done
>> + fi
>> +
>> + git config -f .gitmodules submodule."$name".path "$path" &&
>> + git config -f .gitmodules submodule."$name".url "$repo" &&
>> git add .gitmodules ||
>> - die "Failed to register submodule '$path'"
>> + die "Failed to register submodule '$path' (name '$name')"
>> }
>
> The logic of the fix seems to be correct, but shouldn't the test be like
> this instead?
>
> if git config -f .gitmodules "submodule.$name.path" >/dev/null
> then
>
> The same thing for "git config" used in the "while" loop.
Yeah, redirecting to /dev/null seems like a good idea.
> Also I am not sure if name="$path~" is a good idea for two reasons:
>
> - name suffixed with tilde and number looks too much like revision
> expression.
>
> - A, A~, A~1, A~2... looks ugly; A, A-0, A-1, A-2,... (or start counting
> from 1 or 2) I would understand.
I'd just exit with an informative error if submodule.$name already
exists in .git/config.
> By the way, I noticed that cmd_add does not seem to cd_to_toplevel, and
> accesses .gitmodules in the current working directory. Isn't this a bug?
Not really, since `git submodule` must be executed from the toplevel
($SUBDIRECTORY_OK is undefined, so the cd_to_toplevel in cmd_sync and
cmd_summary seems to be noops).
--
larsh
prev parent reply other threads:[~2008-09-13 11:33 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-12 21:08 [PATCH 0/6] Submodule support for git mv and git rm Petr Baudis
2008-09-12 21:08 ` [PATCH 1/6] submodule.*: Introduce simple C interface for submodule lookup by path Petr Baudis
2008-09-12 21:23 ` Junio C Hamano
2008-09-12 21:35 ` Jakub Narebski
2008-09-12 21:58 ` Petr Baudis
2008-09-12 21:09 ` [PATCH 2/6] git rm: Support for removing submodules Petr Baudis
2008-09-12 21:49 ` Junio C Hamano
2008-09-12 21:59 ` Junio C Hamano
2008-09-12 22:24 ` Petr Baudis
2008-09-12 22:42 ` Junio C Hamano
2008-09-12 21:09 ` [PATCH 3/6] git mv: Support moving submodules Petr Baudis
2008-09-12 21:42 ` [PATCH] " Petr Baudis
2008-09-12 22:19 ` Junio C Hamano
2008-09-12 21:09 ` [PATCH 4/6] t7403: Submodule git mv, git rm testsuite Petr Baudis
2008-09-12 21:09 ` [PATCH 5/6] t7400: Add short "git submodule add" testsuite Petr Baudis
2008-09-12 21:09 ` [PATCH 6/6] git submodule add: Fix naming clash handling Petr Baudis
2008-09-13 2:24 ` Junio C Hamano
2008-09-13 11:32 ` Lars Hjemli [this message]
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8c5c35580809130432r11e986e5u4c7300d62ca2896f@mail.gmail.com \
--to=hjemli@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=mlevedahl@gmail.com \
--cc=pasky@suse.cz \
/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.
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 NNTP newsgroup(s).