git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Stefan Beller <sbeller@google.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: "git@vger.kernel.org" <git@vger.kernel.org>,
	Jens Lehmann <Jens.Lehmann@web.de>,
	Stefan Beller <sbeller@google.com>
Subject: Re: [PATCH] submodule init: fail gracefully with a missing .gitmodules file
Date: Thu, 28 Apr 2016 12:12:56 -0700	[thread overview]
Message-ID: <CAGZ79kairv4jXsaRfqj_TA9ejqOyinOVwrj+-ATMTraaiQsvBA@mail.gmail.com> (raw)
In-Reply-To: <1461868119-9146-1-git-send-email-sbeller@google.com>

On Thu, Apr 28, 2016 at 11:28 AM, Stefan Beller <sbeller@google.com> wrote:
> When there is no .gitmodules file availabe to initialize a submodule
> from, `submodule_from_path` just returns NULL. We need to check for
> that and abort gracefully. When `submodule init` was implemented in shell,
> a missing .gitmodules file would result in an error message
>
>     No url found for submodule path '%s' in .gitmodules
>
> While that is technically true, I think we can broaden the error message
> and just say there is no section for the submodule in the .gitmodules file.

Actually I am not so sure any more about this part. In a resend I will use
the old error message again.

This fix is also required for `submodule--helper update-clone`.

>
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
>
>  This goes on top of sb/submodule-init (I added the base-commit
>  below, just in case anyone uses that feature already. Though I did
>  that manually :)
>
>  Thanks,
>  Stefan
>
>  builtin/submodule--helper.c | 10 +++++++---
>  t/t7400-submodule-basic.sh  |  8 ++++++++
>  2 files changed, 15 insertions(+), 3 deletions(-)
>
> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> index b6d4f27..af5406e 100644
> --- a/builtin/submodule--helper.c
> +++ b/builtin/submodule--helper.c
> @@ -314,13 +314,17 @@ static void init_submodule(const char *path, const char *prefix, int quiet)
>         /* Only loads from .gitmodules, no overlay with .git/config */
>         gitmodules_config();
>
> -       sub = submodule_from_path(null_sha1, path);
> -
>         if (prefix) {
>                 strbuf_addf(&sb, "%s%s", prefix, path);
>                 displaypath = strbuf_detach(&sb, NULL);
>         } else
> -               displaypath = xstrdup(sub->path);
> +               displaypath = xstrdup(path);
> +
> +       sub = submodule_from_path(null_sha1, path);
> +
> +       if (!sub)
> +               die(_("No section found for submodule path '%s' in .gitmodules"),
> +                       displaypath);
>
>         /*
>          * Copy url setting when it is not set yet.
> diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
> index f99f674..f2b3519 100755
> --- a/t/t7400-submodule-basic.sh
> +++ b/t/t7400-submodule-basic.sh
> @@ -18,6 +18,14 @@ test_expect_success 'setup - initial commit' '
>         git branch initial
>  '
>
> +test_expect_success 'sane abort on missing .gitmodules file' '
> +       test_when_finished "git update-index --remove sub" &&
> +       git update-index --add --cacheinfo 160000,$(git rev-parse HEAD),sub &&
> +       # missing the .gitmodules file here
> +       test_must_fail git submodule init 2>actual &&
> +       test_i18ngrep "No section found for submodule path" actual
> +'
> +
>  test_expect_success 'configuration parsing' '
>         test_when_finished "rm -f .gitmodules" &&
>         cat >.gitmodules <<-\EOF &&
> --
> 2.8.0.26.g3604242.dirty
>
> base-commit: 3604242f080a813d6f20a7394def422d1e55b30e

      reply	other threads:[~2016-04-28 19:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-28 18:28 [PATCH] submodule init: fail gracefully with a missing .gitmodules file Stefan Beller
2016-04-28 19:12 ` Stefan Beller [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

  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=CAGZ79kairv4jXsaRfqj_TA9ejqOyinOVwrj+-ATMTraaiQsvBA@mail.gmail.com \
    --to=sbeller@google.com \
    --cc=Jens.Lehmann@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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).