From: Stefan Beller <sbeller@google.com>
To: gitster@pobox.com
Cc: git@vger.kernel.org, hvoigt@hvoigt.net,
torvalds@linux-foundation.org, peff@peff.net,
Stefan Beller <sbeller@google.com>
Subject: [PATCH 1/2] submodule add: extend force flag to add existing repos
Date: Thu, 6 Oct 2016 12:37:24 -0700 [thread overview]
Message-ID: <20161006193725.31553-2-sbeller@google.com> (raw)
In-Reply-To: <20161006193725.31553-1-sbeller@google.com>
Currently the force flag in `git submodule add` takes care of possibly
ignored files or when a name collision occurs.
However there is another situation where submodule add comes in handy:
When you already have a gitlink recorded, but no configuration was
done (i.e. no .gitmodules file nor any entry in .git/config) and you
want to generate these config entries. For this situation allow
`git submodule add` to proceed if there is already a submodule at the
given path in the index.
Signed-off-by: Stefan Beller <sbeller@google.com>
---
git-submodule.sh | 10 ++++++++--
t/t7400-submodule-basic.sh | 14 ++++++++++++++
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index a024a13..3762616 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -207,8 +207,14 @@ cmd_add()
tstart
s|/*$||
')
- git ls-files --error-unmatch "$sm_path" > /dev/null 2>&1 &&
- die "$(eval_gettext "'\$sm_path' already exists in the index")"
+ if test -z "$force"
+ then
+ git ls-files --error-unmatch "$sm_path" > /dev/null 2>&1 &&
+ die "$(eval_gettext "'\$sm_path' already exists in the index")"
+ else
+ git ls-files -s "$sm_path" | sane_grep -v "^160000" > /dev/null 2>&1 &&
+ die "$(eval_gettext "'\$sm_path' already exists in the index and is not a submodule")"
+ fi
if test -z "$force" && ! git add --dry-run --ignore-missing "$sm_path" > /dev/null 2>&1
then
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index b77cce8..c09ce0d 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -152,6 +152,20 @@ test_expect_success 'submodule add to .gitignored path with --force' '
)
'
+test_expect_success 'submodule add to reconfigure existing submodule with --force' '
+ (
+ cd addtest-ignore &&
+ git submodule add --force bogus-url submod &&
+ git submodule add -b initial "$submodurl" submod-branch &&
+ test "bogus-url" = "$(git config -f .gitmodules submodule.submod.url)" &&
+ test "bogus-url" = "$(git config submodule.submod.url)" &&
+ # Restore the url
+ git submodule add --force "$submodurl" submod
+ test "$submodurl" = "$(git config -f .gitmodules submodule.submod.url)" &&
+ test "$submodurl" = "$(git config submodule.submod.url)"
+ )
+'
+
test_expect_success 'submodule add --branch' '
echo "refs/heads/initial" >expect-head &&
cat <<-\EOF >expect-heads &&
--
2.10.1.353.g1629400
next prev parent reply other threads:[~2016-10-06 19:37 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-06 19:37 [PATCH 0/2] submodule pushes be extra careful Stefan Beller
2016-10-06 19:37 ` Stefan Beller [this message]
2016-10-06 20:11 ` [PATCH 1/2] submodule add: extend force flag to add existing repos Junio C Hamano
2016-10-07 12:52 ` Heiko Voigt
2016-10-07 17:25 ` Stefan Beller
2016-10-11 16:36 ` Heiko Voigt
2016-10-06 19:37 ` [PATCHv4 2/2] push: change submodule default to check when submodules exist Stefan Beller
2016-10-06 20:25 ` Junio C Hamano
2016-10-06 21:29 ` Stefan Beller
2016-10-06 23:41 ` [PATCHv5] " Stefan Beller
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=20161006193725.31553-2-sbeller@google.com \
--to=sbeller@google.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=hvoigt@hvoigt.net \
--cc=peff@peff.net \
--cc=torvalds@linux-foundation.org \
/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).