{"thread":{"id":"24270","subject":"[PATCH/RFC] git submodule: add submodules with git add -f <path>","startedAt":"2010-07-02T19:22:01Z","lastAt":"2010-07-17T16:26:15Z","messageCount":10,"participants":["Ævar Arnfjörð Bjarmason","Junio C Hamano","Jens Lehmann"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"144709","messageId":"1278098521-5321-1-git-send-email-avarab@gmail.com","threadId":"24270","inReplyTo":null,"subject":"[PATCH/RFC] git submodule: add submodules with git add -f <path>","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2010-07-02T19:22:01Z","receivedAt":"2010-07-02T19:22:01Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Change `git submodule add' to add the new submodule <path> with `git\nadd --force'.\n\nI keep my /etc in .git with a .gitignore that contains just\n\"*\". I.e. `git status' will ignore everything that isn't in the tree\nalready. When I do:\n\n    git submodule add <url> hlagh\n\ngit-submodule will get as far as checking out the remote repository\ninto hlagh, but it'll die right afterwards when it fails to add the\nnew path:\n\n    The following paths are ignored by one of your .gitignore files:\n    hlagh\n    Use -f if you really want to add them.\n    fatal: no files added\n    Failed to add submodule 'hlagh'\n\nCurrently there's no way to add a submodule in this situation other\nthan to remove the ignored path from the .gitignore while I'm at it.\n\nThat's silly, when you run `git submodule add' you're explicitly\nsaying that you want to add something *new* to the repository. Instead\nit should just add the path with `git add --force'.\n\nInitially I implemented this by adding new -f and --force options to\n`git submodule add'. But if the --force option isn't supplied it'll\nget as far as cloning `hlagh', but won't add it.\n\nSo the first thing the user has to do is to remove `hlagh' and then\ntry again with the --force option.\n\nThat sucks, it should just add the path to begin with. I can't think\nof any usecase where you've gone through the trouble of typing out\n`git submodule add ..', but wish to be overriden by a `gitignore'. The\nsubmodule semantics should be more like `git init', not `git add'.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n Documentation/git-submodule.txt |    4 ++++\n git-submodule.sh                |    4 ++--\n t/t7400-submodule-basic.sh      |   24 +++++++++++++++++++++++-\n 3 files changed, 29 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt\nindex cdabfd2..76a832a 100644\n--- a/Documentation/git-submodule.txt\n+++ b/Documentation/git-submodule.txt\n@@ -95,6 +95,10 @@ is the superproject and submodule repositories will be kept\n together in the same relative location, and only the\n superproject's URL needs to be provided: git-submodule will correctly\n locate the submodule using the relative URL in .gitmodules.\n++\n+The submodule will be added with \"git add --force <path>\". I.e. git\n+doesn't care if the new path is in a `gitignore`. Your invocation of\n+\"git submodule add\" is considered enough to override it.\n \n status::\n \tShow the status of the submodules. This will print the SHA-1 of the\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex d9950c2..ad2417d 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -234,12 +234,12 @@ cmd_add()\n \t\t) || die \"Unable to checkout submodule '$path'\"\n \tfi\n \n-\tgit add \"$path\" ||\n+\tgit add --force \"$path\" ||\n \tdie \"Failed to add submodule '$path'\"\n \n \tgit config -f .gitmodules submodule.\"$path\".path \"$path\" &&\n \tgit config -f .gitmodules submodule.\"$path\".url \"$repo\" &&\n-\tgit add .gitmodules ||\n+\tgit add --force .gitmodules ||\n \tdie \"Failed to register submodule '$path'\"\n }\n \ndiff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh\nindex 97ff074..d9f2785 100755\n--- a/t/t7400-submodule-basic.sh\n+++ b/t/t7400-submodule-basic.sh\n@@ -42,7 +42,8 @@ test_expect_success 'setup - hide init subdirectory' '\n '\n \n test_expect_success 'setup - repository to add submodules to' '\n-\tgit init addtest\n+\tgit init addtest &&\n+\tgit init addtest-ignore\n '\n \n # The 'submodule add' tests need some repository to add as a submodule.\n@@ -85,6 +86,27 @@ test_expect_success 'submodule add' '\n \ttest_cmp empty untracked\n '\n \n+test_expect_success 'submodule add to .gitignored path' '\n+\techo \"refs/heads/master\" >expect &&\n+\t>empty &&\n+\n+\t(\n+\t\tcd addtest-ignore &&\n+\t\t# Does not use test_commit due to the ignore\n+\t\techo \"*\" > .gitignore &&\n+\t\tgit add --force .gitignore &&\n+\t\tgit commit -m\"Ignore everything\" &&\n+\t\tgit submodule add \"$submodurl\" submod &&\n+\t\tgit submodule init\n+\t) &&\n+\n+\trm -f heads head untracked &&\n+\tinspect addtest/submod ../.. &&\n+\ttest_cmp expect heads &&\n+\ttest_cmp expect head &&\n+\ttest_cmp empty untracked\n+'\n+\n test_expect_success 'submodule add --branch' '\n \techo \"refs/heads/initial\" >expect-head &&\n \tcat <<-\\EOF >expect-heads &&\n-- \n1.7.2.rc1.192.g262ff.dirty\n"},{"id":"144832","messageId":"1278351183-18734-1-git-send-email-avarab@gmail.com","threadId":"24270","inReplyTo":"1278098521-5321-1-git-send-email-avarab@gmail.com","subject":"[PATCH] git submodule: add submodules with git add -f <path>","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2010-07-05T17:33:03Z","receivedAt":"2010-07-05T17:33:03Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Change `git submodule add' to add the new submodule <path> with `git\nadd --force'.\n\nI keep my /etc in .git with a .gitignore that contains just\n\"*\". I.e. `git status' will ignore everything that isn't in the tree\nalready. When I do:\n\n    git submodule add <url> hlagh\n\ngit-submodule will get as far as checking out the remote repository\ninto hlagh, but it'll die right afterwards when it fails to add the\nnew path:\n\n    The following paths are ignored by one of your .gitignore files:\n    hlagh\n    Use -f if you really want to add them.\n    fatal: no files added\n    Failed to add submodule 'hlagh'\n\nCurrently there's no way to add a submodule in this situation other\nthan to remove the ignored path from the .gitignore while I'm at it.\n\nThat's silly, when you run `git submodule add' you're explicitly\nsaying that you want to add something *new* to the repository. Instead\nit should just add the path with `git add --force'.\n\nInitially I implemented this by adding new -f and --force options to\n`git submodule add'. But if the --force option isn't supplied it'll\nget as far as cloning `hlagh', but won't add it.\n\nSo the first thing the user has to do is to remove `hlagh' and then\ntry again with the --force option.\n\nThat sucks, it should just add the path to begin with. I can't think\nof any usecase where you've gone through the trouble of typing out\n`git submodule add ..', but wish to be overriden by a `gitignore'. The\nsubmodule semantics should be more like `git init', not `git add'.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n\nResubmitting this as a non-RFC. I think it's sane and ready for\ninclusion.\n\n Documentation/git-submodule.txt |    4 ++++\n git-submodule.sh                |    4 ++--\n t/t7400-submodule-basic.sh      |   24 +++++++++++++++++++++++-\n 3 files changed, 29 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt\nindex cdabfd2..76a832a 100644\n--- a/Documentation/git-submodule.txt\n+++ b/Documentation/git-submodule.txt\n@@ -95,6 +95,10 @@ is the superproject and submodule repositories will be kept\n together in the same relative location, and only the\n superproject's URL needs to be provided: git-submodule will correctly\n locate the submodule using the relative URL in .gitmodules.\n++\n+The submodule will be added with \"git add --force <path>\". I.e. git\n+doesn't care if the new path is in a `gitignore`. Your invocation of\n+\"git submodule add\" is considered enough to override it.\n \n status::\n \tShow the status of the submodules. This will print the SHA-1 of the\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex d9950c2..ad2417d 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -234,12 +234,12 @@ cmd_add()\n \t\t) || die \"Unable to checkout submodule '$path'\"\n \tfi\n \n-\tgit add \"$path\" ||\n+\tgit add --force \"$path\" ||\n \tdie \"Failed to add submodule '$path'\"\n \n \tgit config -f .gitmodules submodule.\"$path\".path \"$path\" &&\n \tgit config -f .gitmodules submodule.\"$path\".url \"$repo\" &&\n-\tgit add .gitmodules ||\n+\tgit add --force .gitmodules ||\n \tdie \"Failed to register submodule '$path'\"\n }\n \ndiff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh\nindex 97ff074..d9f2785 100755\n--- a/t/t7400-submodule-basic.sh\n+++ b/t/t7400-submodule-basic.sh\n@@ -42,7 +42,8 @@ test_expect_success 'setup - hide init subdirectory' '\n '\n \n test_expect_success 'setup - repository to add submodules to' '\n-\tgit init addtest\n+\tgit init addtest &&\n+\tgit init addtest-ignore\n '\n \n # The 'submodule add' tests need some repository to add as a submodule.\n@@ -85,6 +86,27 @@ test_expect_success 'submodule add' '\n \ttest_cmp empty untracked\n '\n \n+test_expect_success 'submodule add to .gitignored path' '\n+\techo \"refs/heads/master\" >expect &&\n+\t>empty &&\n+\n+\t(\n+\t\tcd addtest-ignore &&\n+\t\t# Does not use test_commit due to the ignore\n+\t\techo \"*\" > .gitignore &&\n+\t\tgit add --force .gitignore &&\n+\t\tgit commit -m\"Ignore everything\" &&\n+\t\tgit submodule add \"$submodurl\" submod &&\n+\t\tgit submodule init\n+\t) &&\n+\n+\trm -f heads head untracked &&\n+\tinspect addtest/submod ../.. &&\n+\ttest_cmp expect heads &&\n+\ttest_cmp expect head &&\n+\ttest_cmp empty untracked\n+'\n+\n test_expect_success 'submodule add --branch' '\n \techo \"refs/heads/initial\" >expect-head &&\n \tcat <<-\\EOF >expect-heads &&\n-- \n1.7.2.rc1.192.g262ff.dirty\n"},{"id":"144863","messageId":"7vmxu572w5.fsf@alter.siamese.dyndns.org","threadId":"24270","inReplyTo":"1278351183-18734-1-git-send-email-avarab@gmail.com","subject":"Re: [PATCH] git submodule: add submodules with git add -f <path>","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-07-06T02:36:10Z","receivedAt":"2010-07-06T02:36:10Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:\n\n> Resubmitting this as a non-RFC.\n\nI don't recall any negative nor supporting discussion on this one.  Will\nqueue in 'pu' to see if people who do care about submodules complain.\n\nThanks.\n"},{"id":"144964","messageId":"4C33A552.5060008@web.de","threadId":"24270","inReplyTo":"7vmxu572w5.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] git submodule: add submodules with git add -f <path>","fromName":"Jens Lehmann","fromEmail":"jens.lehmann@web.de","sentAt":"2010-07-06T21:51:14Z","receivedAt":"2010-07-06T21:51:14Z","isPatch":true,"sender":{"key":"jens.lehmann@web.de","avatar":"https://avatars.githubusercontent.com/u/135220?v=4"},"body":"Am 06.07.2010 04:36, schrieb Junio C Hamano:\n> Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:\n> \n>> Resubmitting this as a non-RFC.\n> \n> I don't recall any negative nor supporting discussion on this one.  Will\n> queue in 'pu' to see if people who do care about submodules complain.\n\nFirst: I think this patch fixes a bug. Without it \"git submodule add\"\nleaves the work tree in an inconsistent state when either .gitmodules\nor the submodule path are ignored: the submodule is checked out and\npopulated but the path and/or a new .gitmodules file is not added to\nthe index. And even worse: The advice of the failed \"git add\" called\nfrom the script that using \"-f\" might help is misleading here, as\n\"git submodule add\" doesn't know this option.\n\nBut while I think adding the --force option to the \"git add .gitmodules\"\nmakes perfect sense (as the submodule can't be successfully added until\nit is recorded in this file and there is really no point in ignoring\n.gitmodules when you decide to use submodules), I'm not so sure about\nwhat to do when the submodule path itself is ignored.\n\nI see two possible behaviors here:\n\na) We just ignore .gitignore and add the submodule anyways (which is\n   what this patch does)\n\nb) We do the same a \"git add <ignored file>\" does: Print an error\n   message, maybe even tell the user to use a - still to be added -\n   \"--force\" (or \"-f\") option and exit. But without checking out the\n   submodule first nor adding or changing .gitmodules.\n\nIMHO b) is more consistent with the current behavior of \"git add\". And\nwhen you later decide that the submodules files should live in the\nsuperproject and you drop the submodule, the then probably still\npresent entry in .gitignore might really shoot you in the foot when\nyou add new files there and they won't show up because they are still\nignored.\n\nWhat do others think?\n"},{"id":"144966","messageId":"AANLkTinn_Vz6I619Do4AOCVMUgfpyy84L1wh3lkuCP7R@mail.gmail.com","threadId":"24270","inReplyTo":"4C33A552.5060008@web.de","subject":"Re: [PATCH] git submodule: add submodules with git add -f <path>","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2010-07-06T22:33:34Z","receivedAt":"2010-07-06T22:33:34Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"On Tue, Jul 6, 2010 at 21:51, Jens Lehmann <Jens.Lehmann@web.de> wrote:\n> [...]\n> But while I think adding the --force option to the \"git add .gitmodules\"\n> makes perfect sense (as the submodule can't be successfully added until\n> it is recorded in this file and there is really no point in ignoring\n> .gitmodules when you decide to use submodules), I'm not so sure about\n> what to do when the submodule path itself is ignored.\n>\n> I see two possible behaviors here:\n>\n> a) We just ignore .gitignore and add the submodule anyways (which is\n>   what this patch does)\n>\n> b) We do the same a \"git add <ignored file>\" does: Print an error\n>   message, maybe even tell the user to use a - still to be added -\n>   \"--force\" (or \"-f\") option and exit. But without checking out the\n>   submodule first nor adding or changing .gitmodules.\n>\n> IMHO b) is more consistent with the current behavior of \"git add\". And\n> when you later decide that the submodules files should live in the\n> superproject and you drop the submodule, the then probably still\n> present entry in .gitignore might really shoot you in the foot when\n> you add new files there and they won't show up because they are still\n> ignored.\n>\n> What do others think?\n\nOption C would be treating it like git init as the current patch\ndoes. But init isn't strictly comparable to git add or git submodule\nadd since it's not adding something to *another* repository.\n\nI really don't care, B or C works for me, although C is of course\neasier since I don't have to write another patch :)\n\nOption b) is more consistent with git-add, but I can't find a way to\nask any git tool whether a non-existing path is ignored without\nactually adding something. git add --dry-run will die on \"pathspec\n'foo' did not match any files\" unless the file exists already.\n"},{"id":"145243","messageId":"4C37A03E.7030801@web.de","threadId":"24270","inReplyTo":"AANLkTinn_Vz6I619Do4AOCVMUgfpyy84L1wh3lkuCP7R@mail.gmail.com","subject":"[PATCH] git add: Add the \"--ignore-missing\" option for the dry run","fromName":"Jens Lehmann","fromEmail":"jens.lehmann@web.de","sentAt":"2010-07-09T22:18:38Z","receivedAt":"2010-07-09T22:18:38Z","isPatch":true,"sender":{"key":"jens.lehmann@web.de","avatar":"https://avatars.githubusercontent.com/u/135220?v=4"},"body":"Sometimes it is useful to know if a file or directory will be ignored\nbefore it is added to the work tree. An example is \"git submodule add\",\nwhere it would be really nice to be able to fail with an appropriate\nerror message before the submodule is cloned and checked out.\n\nSigned-off-by: Jens Lehmann <Jens.Lehmann@web.de>\n---\n\nAm 07.07.2010 00:33, schrieb Ævar Arnfjörð Bjarmason:\n> Option b) is more consistent with git-add, but I can't find a way to\n> ask any git tool whether a non-existing path is ignored without\n> actually adding something. git add --dry-run will die on \"pathspec\n> 'foo' did not match any files\" unless the file exists already.\n\nRight, and as IMHO creating a directory with the same name of the\nsubmodule and then deleting it again after the \"git add --dry-run\"\nis way too hackish, what about adding a \"--ignore-missing\" option to\n\"git add\", which ignores any missing files when used with the option\n\"--dry-run\"?\n\n(And to add some bikeshedding-fodder: I also thought about naming\nthat option \"--dry-run=ignore-missing\" or \"--only-ignored\". I really\ndon't have any strong feelings about the particular naming, so if\nanyone has a better idea, please speak up!)\n\nWith this patch it should be easy to have \"git submodule add\" return\nan error /before/ adding a submodule path and its contents when it\nis found in .gitignore.\n\nOpinions?\n\n\n Documentation/git-add.txt |    9 ++++++++-\n builtin/add.c             |   16 ++++++++++++----\n dir.c                     |    2 +-\n dir.h                     |    1 +\n t/t3700-add.sh            |   25 +++++++++++++++++++++++++\n 5 files changed, 47 insertions(+), 6 deletions(-)\n\ndiff --git a/Documentation/git-add.txt b/Documentation/git-add.txt\nindex 74741a4..bfea2c2 100644\n--- a/Documentation/git-add.txt\n+++ b/Documentation/git-add.txt\n@@ -57,7 +57,8 @@ OPTIONS\n\n -n::\n --dry-run::\n-        Don't actually add the file(s), just show if they exist.\n+\tDon't actually add the file(s), just show if they exist and/or will\n+\tbe ignored.\n\n -v::\n --verbose::\n@@ -131,6 +132,12 @@ subdirectories.\n \tthem, do not abort the operation, but continue adding the\n \tothers. The command shall still exit with non-zero status.\n\n+--ignore-missing::\n+\tThis option can only be used together with --dry-run. By using\n+\tthis option the user can check if any of the given files would\n+\tbe ignored, no matter if they are already present in the work\n+\ttree or not.\n+\n \\--::\n \tThis option can be used to separate command-line options from\n \tthe list of files, (useful when filenames might be mistaken\ndiff --git a/builtin/add.c b/builtin/add.c\nindex 17149cf..56a4e0a 100644\n--- a/builtin/add.c\n+++ b/builtin/add.c\n@@ -310,7 +310,7 @@ static const char ignore_error[] =\n \"The following paths are ignored by one of your .gitignore files:\\n\";\n\n static int verbose = 0, show_only = 0, ignored_too = 0, refresh_only = 0;\n-static int ignore_add_errors, addremove, intent_to_add;\n+static int ignore_add_errors, addremove, intent_to_add, ignore_missing = 0;\n\n static struct option builtin_add_options[] = {\n \tOPT__DRY_RUN(&show_only),\n@@ -325,6 +325,7 @@ static struct option builtin_add_options[] = {\n \tOPT_BOOLEAN('A', \"all\", &addremove, \"add all, noticing removal of tracked files\"),\n \tOPT_BOOLEAN( 0 , \"refresh\", &refresh_only, \"don't add, only refresh the index\"),\n \tOPT_BOOLEAN( 0 , \"ignore-errors\", &ignore_add_errors, \"just skip files which cannot be added because of errors\"),\n+\tOPT_BOOLEAN( 0 , \"ignore-missing\", &ignore_missing, \"check if - even missing - files are ignored in dry run\"),\n \tOPT_END(),\n };\n\n@@ -385,6 +386,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)\n\n \tif (addremove && take_worktree_changes)\n \t\tdie(\"-A and -u are mutually incompatible\");\n+\tif (!show_only && ignore_missing)\n+\t\tdie(\"Option --ignore-missing can only be used together with --dry-run\");\n \tif ((addremove || take_worktree_changes) && !argc) {\n \t\tstatic const char *here[2] = { \".\", NULL };\n \t\targc = 1;\n@@ -441,9 +444,14 @@ int cmd_add(int argc, const char **argv, const char *prefix)\n \t\t\tseen = find_used_pathspec(pathspec);\n \t\tfor (i = 0; pathspec[i]; i++) {\n \t\t\tif (!seen[i] && pathspec[i][0]\n-\t\t\t    && !file_exists(pathspec[i]))\n-\t\t\t\tdie(\"pathspec '%s' did not match any files\",\n-\t\t\t\t    pathspec[i]);\n+\t\t\t    && !file_exists(pathspec[i])) {\n+\t\t\t\tif (ignore_missing) {\n+\t\t\t\t\tif (excluded(&dir, pathspec[i], DT_UNKNOWN))\n+\t\t\t\t\t\tdir_add_ignored(&dir, pathspec[i], strlen(pathspec[i]));\n+\t\t\t\t} else\n+\t\t\t\t\tdie(\"pathspec '%s' did not match any files\",\n+\t\t\t\t\t    pathspec[i]);\n+\t\t\t}\n \t\t}\n \t\tfree(seen);\n \t}\ndiff --git a/dir.c b/dir.c\nindex 151ea67..133f472 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -453,7 +453,7 @@ static struct dir_entry *dir_add_name(struct dir_struct *dir, const char *pathna\n \treturn dir->entries[dir->nr++] = dir_entry_new(pathname, len);\n }\n\n-static struct dir_entry *dir_add_ignored(struct dir_struct *dir, const char *pathname, int len)\n+struct dir_entry *dir_add_ignored(struct dir_struct *dir, const char *pathname, int len)\n {\n \tif (!cache_name_is_other(pathname, len))\n \t\treturn NULL;\ndiff --git a/dir.h b/dir.h\nindex 3bead5f..278d84c 100644\n--- a/dir.h\n+++ b/dir.h\n@@ -72,6 +72,7 @@ extern int read_directory(struct dir_struct *, const char *path, int len, const\n extern int excluded_from_list(const char *pathname, int pathlen, const char *basename,\n \t\t\t      int *dtype, struct exclude_list *el);\n extern int excluded(struct dir_struct *, const char *, int *);\n+struct dir_entry *dir_add_ignored(struct dir_struct *dir, const char *pathname, int len);\n extern int add_excludes_from_file_to_list(const char *fname, const char *base, int baselen,\n \t\t\t\t\t  char **buf_p, struct exclude_list *which, int check_index);\n extern void add_excludes_from_file(struct dir_struct *, const char *fname);\ndiff --git a/t/t3700-add.sh b/t/t3700-add.sh\nindex 6f031af..47fbf53 100755\n--- a/t/t3700-add.sh\n+++ b/t/t3700-add.sh\n@@ -260,4 +260,29 @@ test_expect_success '\"add non-existent\" should fail' '\n \t! (git ls-files | grep \"non-existent\")\n '\n\n+test_expect_success 'git add --dry-run of existing changed file' \"\n+\techo new >>track-this &&\n+\tgit add --dry-run track-this >actual 2>&1 &&\n+\techo \\\"add 'track-this'\\\" | test_cmp - actual\n+\"\n+\n+test_expect_success 'git add --dry-run of non-existing file' \"\n+\techo ignored-file >>.gitignore &&\n+\t! (git add --dry-run track-this ignored-file >actual 2>&1) &&\n+\techo \\\"fatal: pathspec 'ignored-file' did not match any files\\\" | test_cmp - actual\n+\"\n+\n+cat >expect <<EOF\n+The following paths are ignored by one of your .gitignore files:\n+ignored-file\n+Use -f if you really want to add them.\n+fatal: no files added\n+add 'track-this'\n+EOF\n+\n+test_expect_success 'git add --dry-run --ignore-missing of non-existing file' '\n+\t!(git add --dry-run --ignore-missing track-this ignored-file >actual 2>&1) &&\n+\ttest_cmp expect actual\n+'\n+\n test_done\n-- \n1.7.2.rc1.218.gca56a.dirty\n"},{"id":"145400","messageId":"7viq4k8i0e.fsf@alter.siamese.dyndns.org","threadId":"24270","inReplyTo":"4C37A03E.7030801@web.de","subject":"Re: [PATCH] git add: Add the \"--ignore-missing\" option for the dry run","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-07-12T22:14:41Z","receivedAt":"2010-07-12T22:14:41Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jens Lehmann <Jens.Lehmann@web.de> writes:\n\n> With this patch it should be easy to have \"git submodule add\" return\n> an error /before/ adding a submodule path and its contents when it\n> is found in .gitignore.\n>\n> Opinions?\n\nSounds like a right thing to do.\n"},{"id":"145723","messageId":"4C41C82F.8030200@web.de","threadId":"24270","inReplyTo":"7viq4k8i0e.fsf@alter.siamese.dyndns.org","subject":"[PATCH] git submodule add: Require the new --force option to add ignored paths","fromName":"Jens Lehmann","fromEmail":"jens.lehmann@web.de","sentAt":"2010-07-17T15:11:43Z","receivedAt":"2010-07-17T15:11:43Z","isPatch":true,"sender":{"key":"jens.lehmann@web.de","avatar":"https://avatars.githubusercontent.com/u/135220?v=4"},"body":"To make the behavior of \"git submodule add\" more consistent with \"git add\"\nignored submodule paths should not be silently added when they match an\nentry in a .gitignore file. To be able to override that default behavior\nin the same way as we can do that for \"git add\", the new option \"--force\"\nis introduced.\n\nSigned-off-by: Jens Lehmann <Jens.Lehmann@web.de>\n---\n\nAm 13.07.2010 00:14, schrieb Junio C Hamano:\n> Jens Lehmann <Jens.Lehmann@web.de> writes:\n> \n>> With this patch it should be easy to have \"git submodule add\" return\n>> an error /before/ adding a submodule path and its contents when it\n>> is found in .gitignore.\n>>\n>> Opinions?\n> \n> Sounds like a right thing to do.\n\nSo here we go. This patch applies to pu as it needs the\n'git add: Add the \"--ignore-missing\" option for the dry run'\npatch to work.\n\n\n Documentation/git-submodule.txt |    7 ++++++-\n git-submodule.sh                |   16 ++++++++++++++--\n t/t7400-submodule-basic.sh      |   27 +++++++++++++++------------\n 3 files changed, 35 insertions(+), 15 deletions(-)\n\ndiff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt\nindex 76a832a..617069f 100644\n--- a/Documentation/git-submodule.txt\n+++ b/Documentation/git-submodule.txt\n@@ -9,7 +9,7 @@ git-submodule - Initialize, update or inspect submodules\n SYNOPSIS\n --------\n [verse]\n-'git submodule' [--quiet] add [-b branch]\n+'git submodule' [--quiet] add [-b branch] [-f|--force]\n \t      [--reference <repository>] [--] <repository> [<path>]\n 'git submodule' [--quiet] status [--cached] [--recursive] [--] [<path>...]\n 'git submodule' [--quiet] init [--] [<path>...]\n@@ -187,6 +187,11 @@ OPTIONS\n --branch::\n \tBranch of repository to add as submodule.\n\n+-f::\n+--force::\n+\tThis option is only valid for the add command.\n+\tAllow adding an otherwise ignored submodule path.\n+\n --cached::\n \tThis option is only valid for status and summary commands.  These\n \tcommands typically use the commit found in the submodule HEAD, but\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex ad2417d..170186f 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -5,7 +5,7 @@\n # Copyright (c) 2007 Lars Hjemli\n\n dashless=$(basename \"$0\" | sed -e 's/-/ /')\n-USAGE=\"[--quiet] add [-b branch] [--reference <repository>] [--] <repository> [<path>]\n+USAGE=\"[--quiet] add [-b branch] [-f|--force] [--reference <repository>] [--] <repository> [<path>]\n    or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]\n    or: $dashless [--quiet] init [--] [<path>...]\n    or: $dashless [--quiet] update [--init] [-N|--no-fetch] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]\n@@ -19,6 +19,7 @@ require_work_tree\n\n command=\n branch=\n+force=\n reference=\n cached=\n recursive=\n@@ -133,6 +134,9 @@ cmd_add()\n \t\t\tbranch=$2\n \t\t\tshift\n \t\t\t;;\n+\t\t-f | --force)\n+\t\t\tforce=$1\n+\t\t\t;;\n \t\t-q|--quiet)\n \t\t\tGIT_QUIET=1\n \t\t\t;;\n@@ -201,6 +205,14 @@ cmd_add()\n \tgit ls-files --error-unmatch \"$path\" > /dev/null 2>&1 &&\n \tdie \"'$path' already exists in the index\"\n\n+\tif test -z \"$force\" && ! git add --dry-run --ignore-missing \"$path\" > /dev/null 2>&1\n+\tthen\n+\t\techo >&2 \"The following path is ignored by one of your .gitignore files:\" &&\n+\t\techo >&2 $path &&\n+\t\techo >&2 \"Use -f if you really want to add it.\"\n+\t\texit 1\n+\tfi\n+\n \t# perhaps the path exists and is already a git repo, else clone it\n \tif test -e \"$path\"\n \tthen\n@@ -234,7 +246,7 @@ cmd_add()\n \t\t) || die \"Unable to checkout submodule '$path'\"\n \tfi\n\n-\tgit add --force \"$path\" ||\n+\tgit add $force \"$path\" ||\n \tdie \"Failed to add submodule '$path'\"\n\n \tgit config -f .gitmodules submodule.\"$path\".path \"$path\" &&\ndiff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh\nindex d9f2785..9bda970 100755\n--- a/t/t7400-submodule-basic.sh\n+++ b/t/t7400-submodule-basic.sh\n@@ -86,25 +86,28 @@ test_expect_success 'submodule add' '\n \ttest_cmp empty untracked\n '\n\n-test_expect_success 'submodule add to .gitignored path' '\n-\techo \"refs/heads/master\" >expect &&\n-\t>empty &&\n-\n+test_expect_success 'submodule add to .gitignored path fails' '\n \t(\n \t\tcd addtest-ignore &&\n+\t\tcat <<-\\EOF >expect &&\n+\t\tThe following path is ignored by one of your .gitignore files:\n+\t\tsubmod\n+\t\tUse -f if you really want to add it.\n+\t\tEOF\n \t\t# Does not use test_commit due to the ignore\n \t\techo \"*\" > .gitignore &&\n \t\tgit add --force .gitignore &&\n \t\tgit commit -m\"Ignore everything\" &&\n-\t\tgit submodule add \"$submodurl\" submod &&\n-\t\tgit submodule init\n-\t) &&\n+\t\t! git submodule add \"$submodurl\" submod >actual 2>&1 &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n\n-\trm -f heads head untracked &&\n-\tinspect addtest/submod ../.. &&\n-\ttest_cmp expect heads &&\n-\ttest_cmp expect head &&\n-\ttest_cmp empty untracked\n+test_expect_success 'submodule add to .gitignored path with --force' '\n+\t(\n+\t\tcd addtest-ignore &&\n+\t\tgit submodule add --force \"$submodurl\" submod\n+\t)\n '\n\n test_expect_success 'submodule add --branch' '\n-- \n1.7.2.rc3.262.gcf61\n"},{"id":"145728","messageId":"1279382025-24814-1-git-send-email-avarab@gmail.com","threadId":"24270","inReplyTo":"4C41C82F.8030200@web.de","subject":"[PATCH] git submodule add: Remove old docs about implicit -f","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2010-07-17T15:53:45Z","receivedAt":"2010-07-17T15:53:45Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"git submodule add no longer implicitly adds with --force. Remove\nreferences to the old functionality in the documentation.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n\n> To make the behavior of \"git submodule add\" more consistent with \"git add\"\n> ignored submodule paths should not be silently added when they match an\n> entry in a .gitignore file. To be able to override that default behavior\n> in the same way as we can do that for \"git add\", the new option \"--force\"\n> is introduced.\n>\n> Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>\n\nYou beat me to it. I like this better than the original functionality\nthat I implemented, and it's now possible with --ignore-missing.\n\nSo,:\n\n    Acked-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n\nThis amended patch removes some obsolete documentation that you\nmissed.\n\n> +               echo >&2 \"The following path is ignored by one of your .gitignore files:\" &&\n> +               echo >&2 $path &&\n> +               echo >&2 \"Use -f if you really want to add it.\"\n\nIs the \"it\" intentional? We currently say \"them\" in git add regardless\nof how many things are being added, so perhaps we should say \"it\"\nthere too for singulars.\n\nI'll jot this down as something to look at for plural support once\ngettext gets merged.\n\n Documentation/git-submodule.txt |    4 ----\n 1 files changed, 0 insertions(+), 4 deletions(-)\n\ndiff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt\nindex 617069f..1ed331c 100644\n--- a/Documentation/git-submodule.txt\n+++ b/Documentation/git-submodule.txt\n@@ -95,10 +95,6 @@ is the superproject and submodule repositories will be kept\n together in the same relative location, and only the\n superproject's URL needs to be provided: git-submodule will correctly\n locate the submodule using the relative URL in .gitmodules.\n-+\n-The submodule will be added with \"git add --force <path>\". I.e. git\n-doesn't care if the new path is in a `gitignore`. Your invocation of\n-\"git submodule add\" is considered enough to override it.\n \n status::\n \tShow the status of the submodules. This will print the SHA-1 of the\n-- \n1.7.2.rc3.125.g94e09.dirty\n"},{"id":"145732","messageId":"4C41D9A7.7000508@web.de","threadId":"24270","inReplyTo":"1279382025-24814-1-git-send-email-avarab@gmail.com","subject":"Re: [PATCH] git submodule add: Remove old docs about implicit -f","fromName":"Jens Lehmann","fromEmail":"jens.lehmann@web.de","sentAt":"2010-07-17T16:26:15Z","receivedAt":"2010-07-17T16:26:15Z","isPatch":true,"sender":{"key":"jens.lehmann@web.de","avatar":"https://avatars.githubusercontent.com/u/135220?v=4"},"body":"Am 17.07.2010 17:53, schrieb Ævar Arnfjörð Bjarmason:\n> git submodule add no longer implicitly adds with --force. Remove\n> references to the old functionality in the documentation.\n> \n> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n> ---\n\n> This amended patch removes some obsolete documentation that you\n> missed.\n\nYeah, thanks!\n\n    Acked-by: Jens Lehmann <Jens.Lehmann@web.de>\n\n\n>> +               echo >&2 \"The following path is ignored by one of your .gitignore files:\" &&\n>> +               echo >&2 $path &&\n>> +               echo >&2 \"Use -f if you really want to add it.\"\n> \n> Is the \"it\" intentional? We currently say \"them\" in git add regardless\n> of how many things are being added, so perhaps we should say \"it\"\n> there too for singulars.\n\nYes, the \"it\" is intentional. While \"git add\" may be called with one\nor more files, \"git submodule add\" can only be called with one path.\nThat's why I chose the singular form here.\n"}]}