{"thread":{"id":"60611","subject":"Allow adding files from git submodule to parent git repo if they are in .gitignore in the submodule","startedAt":"2023-12-13T11:07:55Z","lastAt":"2023-12-13T15:38:49Z","messageCount":2,"participants":["Alexey Murz Korepov","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"485611","messageId":"CAL5pyKseyxEfLbgEkDHSqWQVLGkrrcZU=BzRx2zZOaCdQbMaoA@mail.gmail.com","threadId":"60611","inReplyTo":null,"subject":"Allow adding files from git submodule to parent git repo if they are in .gitignore in the submodule","fromName":"Alexey Murz Korepov","fromEmail":"murznn@gmail.com","sentAt":"2023-12-13T11:07:43Z","receivedAt":"2023-12-13T11:07:55Z","isPatch":false,"sender":{"key":"murznn@gmail.com","avatar":null},"body":"Git submodules are pretty often used to \"import\" some external git\nrepository into your git repository, to not manage its files in your\ngit tree, that's good.\n\nBut very often we need to add some file to that submodule and manage\nit in our local git repository, and this file is usually in .gitignore\nin the submodule's git.\n\nSo, the example task is:\n\nCopy a mysubmodule/config.example.yaml to mysubmodule/config.yaml\n(which is in .gitignore in the mysubmodule), make local changes, and\nstore it in the local (parent) root git repo.\n\nBut the problem is that we can't add this mysubmodule/config.yaml file\nto our root git repository, because receiving an error:\n```\n$ git add -f mysubmodule/config.yaml\nfatal: Pathspec 'mysubmodule/config.yaml' is in submodule 'mysubmodule'\n```\nBut I see no problems with doing this, if the file is in .gitignore of\nthe mysubmodule submodule.\n\nSo, let's discuss the approach of how we can allow this in git?\n\nOr will be glad to hear and discuss alternatives and workarounds for this task.\n"},{"id":"485621","messageId":"xmqq34w6nmd8.fsf@gitster.g","threadId":"60611","inReplyTo":"CAL5pyKseyxEfLbgEkDHSqWQVLGkrrcZU=BzRx2zZOaCdQbMaoA@mail.gmail.com","subject":"Re: Allow adding files from git submodule to parent git repo if they are in .gitignore in the submodule","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-12-13T15:38:43Z","receivedAt":"2023-12-13T15:38:49Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alexey Murz Korepov <murznn@gmail.com> writes:\n\n> ```\n> $ git add -f mysubmodule/config.yaml\n> fatal: Pathspec 'mysubmodule/config.yaml' is in submodule 'mysubmodule'\n> ```\n> But I see no problems with doing this, if the file is in .gitignore of\n> the mysubmodule submodule.\n>\n> So, let's discuss the approach of how we can allow this in git?\n\nWhat should happen when mysubmodule/.gitignore changes?  Who\nguarantees that such a file stolen by the superproject will stay in\nthe .gitignore file in the submodule?\n\nI do not think you want to go there, and I do not think I want to\nsee such a behaviour in Git, as we would be the ones who will be\nblamed for the resulting mess.\n\nThe right solution probably is to keep such a file in a directory\nthat is separate from the directory where you bind your submodule.\nTrack the file in the superproject, and have a build procedure to\ncopy it into the submodule directory (as an untracked file, of\ncourse).\n"}]}