summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8fbe9b3)
raw | patch | inline | side by side (parent: 8fbe9b3)
author | Jens Lehmann <Jens.Lehmann@web.de> | |
Sat, 17 Jul 2010 15:11:43 +0000 (17:11 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 19 Jul 2010 18:10:43 +0000 (11:10 -0700) |
To make the behavior of "git submodule add" more consistent with "git add"
ignored submodule paths should not be silently added when they match an
entry in a .gitignore file. To be able to override that default behavior
in the same way as we can do that for "git add", the new option "--force"
is introduced.
Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
Acked-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
ignored submodule paths should not be silently added when they match an
entry in a .gitignore file. To be able to override that default behavior
in the same way as we can do that for "git add", the new option "--force"
is introduced.
Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
Acked-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-submodule.txt | patch | blob | history | |
git-submodule.sh | patch | blob | history | |
t/t7400-submodule-basic.sh | patch | blob | history |
index 76a832a3ac893111b2d17333e6bc99b7903b47a8..617069fb04bd87431792b8f95ab7f4b5a6d76ab3 100644 (file)
SYNOPSIS
--------
[verse]
-'git submodule' [--quiet] add [-b branch]
+'git submodule' [--quiet] add [-b branch] [-f|--force]
[--reference <repository>] [--] <repository> [<path>]
'git submodule' [--quiet] status [--cached] [--recursive] [--] [<path>...]
'git submodule' [--quiet] init [--] [<path>...]
--branch::
Branch of repository to add as submodule.
+-f::
+--force::
+ This option is only valid for the add command.
+ Allow adding an otherwise ignored submodule path.
+
--cached::
This option is only valid for status and summary commands. These
commands typically use the commit found in the submodule HEAD, but
diff --git a/git-submodule.sh b/git-submodule.sh
index ad2417d1b0827b80ec884009447adada0ddb8173..170186f4946859e04d6a0b4ce248dd17bc877b31 100755 (executable)
--- a/git-submodule.sh
+++ b/git-submodule.sh
# Copyright (c) 2007 Lars Hjemli
dashless=$(basename "$0" | sed -e 's/-/ /')
-USAGE="[--quiet] add [-b branch] [--reference <repository>] [--] <repository> [<path>]
+USAGE="[--quiet] add [-b branch] [-f|--force] [--reference <repository>] [--] <repository> [<path>]
or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]
or: $dashless [--quiet] init [--] [<path>...]
or: $dashless [--quiet] update [--init] [-N|--no-fetch] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]
command=
branch=
+force=
reference=
cached=
recursive=
branch=$2
shift
;;
+ -f | --force)
+ force=$1
+ ;;
-q|--quiet)
GIT_QUIET=1
;;
git ls-files --error-unmatch "$path" > /dev/null 2>&1 &&
die "'$path' already exists in the index"
+ if test -z "$force" && ! git add --dry-run --ignore-missing "$path" > /dev/null 2>&1
+ then
+ echo >&2 "The following path is ignored by one of your .gitignore files:" &&
+ echo >&2 $path &&
+ echo >&2 "Use -f if you really want to add it."
+ exit 1
+ fi
+
# perhaps the path exists and is already a git repo, else clone it
if test -e "$path"
then
) || die "Unable to checkout submodule '$path'"
fi
- git add --force "$path" ||
+ git add $force "$path" ||
die "Failed to add submodule '$path'"
git config -f .gitmodules submodule."$path".path "$path" &&
index d9f27859932c33e126fa64c5c1fb80963dabb97a..9bda97058499ecab88dc6de7551d7909e1ad5a2e 100755 (executable)
test_cmp empty untracked
'
-test_expect_success 'submodule add to .gitignored path' '
- echo "refs/heads/master" >expect &&
- >empty &&
-
+test_expect_success 'submodule add to .gitignored path fails' '
(
cd addtest-ignore &&
+ cat <<-\EOF >expect &&
+ The following path is ignored by one of your .gitignore files:
+ submod
+ Use -f if you really want to add it.
+ EOF
# Does not use test_commit due to the ignore
echo "*" > .gitignore &&
git add --force .gitignore &&
git commit -m"Ignore everything" &&
- git submodule add "$submodurl" submod &&
- git submodule init
- ) &&
+ ! git submodule add "$submodurl" submod >actual 2>&1 &&
+ test_cmp expect actual
+ )
+'
- rm -f heads head untracked &&
- inspect addtest/submod ../.. &&
- test_cmp expect heads &&
- test_cmp expect head &&
- test_cmp empty untracked
+test_expect_success 'submodule add to .gitignored path with --force' '
+ (
+ cd addtest-ignore &&
+ git submodule add --force "$submodurl" submod
+ )
'
test_expect_success 'submodule add --branch' '