Re: [PATCH 1/2] submodule add: extend force flag to add existing repos
Hi, On Fri, Oct 07, 2016 at 10:25:04AM -0700, Stefan Beller wrote: > On Fri, Oct 7, 2016 at 5:52 AM, Heiko Voigtwrote: > > On Thu, Oct 06, 2016 at 01:11:20PM -0700, Junio C Hamano wrote: > >> Stefan Beller writes: > >> > >> > 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. > > > > Is it important that the submodule is in the index? > > If it is not in the index, it already works. Ah ok I was not aware of that, sorry. > > How about worktree? > > From the index entry alone we can not deduce the values anyway. > > Right, but as of now this is the only show stopper, i.e. > * you have an existing repo? -> fine, it works with --force > * you even ignored that repo -> --force knows how to do it. > * you already have a gitlink -> Sorry, you're out of luck. > > So that is why I stressed index in this commit message, as it is only about > this > case. Forget what I wrote. As said above I was not aware that there is only an error when it is already in the index. > > [1] > > http://public-inbox.org/git/%3c20160916141143.ga47...@book.hvoigt.net%3E/ > > Current situation: > > > clone the submodule into a directory > > git submodule add --force > > git commit everything > > works fine, but: > > > clone the submodule into a directory > > git add > > git commit -m "Add submodule" > > # me: "Oh crap! I did forget the configuration." > > git submodule add --force > > # Git: "It already exists in the index, I am not going to produce the > > config for you." > > The last step is changed with this patch, as > it will just work fine then. Thanks. Cheers Heiko
Re: [PATCH 1/2] submodule add: extend force flag to add existing repos
On Fri, Oct 7, 2016 at 5:52 AM, Heiko Voigtwrote: > On Thu, Oct 06, 2016 at 01:11:20PM -0700, Junio C Hamano wrote: >> Stefan Beller writes: >> >> > 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. > > Is it important that the submodule is in the index? If it is not in the index, it already works. > How about worktree? > From the index entry alone we can not deduce the values anyway. Right, but as of now this is the only show stopper, i.e. * you have an existing repo? -> fine, it works with --force * you even ignored that repo -> --force knows how to do it. * you already have a gitlink -> Sorry, you're out of luck. So that is why I stressed index in this commit message, as it is only about this case. > > [1] http://public-inbox.org/git/%3c20160916141143.ga47...@book.hvoigt.net%3E/ Current situation: > clone the submodule into a directory > git submodule add --force > git commit everything works fine, but: > clone the submodule into a directory > git add > git commit -m "Add submodule" > # me: "Oh crap! I did forget the configuration." > git submodule add --force > # Git: "It already exists in the index, I am not going to produce the config > for you." The last step is changed with this patch, as it will just work fine then.
Re: [PATCH 1/2] submodule add: extend force flag to add existing repos
On Thu, Oct 06, 2016 at 01:11:20PM -0700, Junio C Hamano wrote: > Stefan Bellerwrites: > > > 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. Is it important that the submodule is in the index? How about worktree? >From the index entry alone we can not deduce the values anyway. So I would say the submodule has to be in the worktree, no matter what is in the index. If its not in the index we can also add it. BTW, that is the way I imagined submodules would work in the first place: just clone and add them, like I described here[1]. > > Signed-off-by: Stefan Beller > > --- > > Yup, the goal makes perfect sense. > > I vaguely recall discussing this exact issue of "git submodule add" > that refuses to add a path that already is a gitlink (via "git add" > that has previously been run) elsewhere on this list some time ago. Yes there was a discussion, see the link. Cheers Heiko [1] http://public-inbox.org/git/%3c20160916141143.ga47...@book.hvoigt.net%3E/
Re: [PATCH 1/2] submodule add: extend force flag to add existing repos
Stefan Bellerwrites: > 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 > --- Yup, the goal makes perfect sense. I vaguely recall discussing this exact issue of "git submodule add" that refuses to add a path that already is a gitlink (via "git add" that has previously been run) elsewhere on this list some time ago.
[PATCH 1/2] submodule add: extend force flag to add existing repos
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--- 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 "^16" > /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