On Wed, Mar 15, 2017 at 2:28 PM, Prathamesh <pc44800@xxxxxxxxx> wrote: >> What do you mean by catch here? > > By catching commands, I meant that we identify that the user has entered > the command in an unpopulated or uninitialized submodule and respond > to the user accordingly. Well in that sense, we do not do that, yet. I see what you mean. >> However to detect if there is a submodule, we can to check two >> things: if there is a .gitmodules entry and if there is a gitlink entry >> recorded in the tree. Depending on the command we'd want to >> do one before the other. e.g. git-add most likely doesn't need to >> load .gitmodules, but may have the objects already loaded. >> So checking if a given path is a submodule is cheap compared >> to loading the .gitmodules file, so we'd probably want to do the >> cheap thing first. > > Adding to this, we may use here this functions is_submodule_populated() > and is_submodule_initialized() from submodule.c Not quite, IMO. is_submodule_initialized checks for the existence of submodule.<name>.URL in .git/config; but it sounds as if we want to check for the existence of submodule.<any name>.path in .gitmodules instead. So we'd end up using only module = submodule_from_path(null_sha1, path); only from that function. is_submodule_populated checks if there is a .git file/directory at the given path, which at this point we would know is not the case, already? We'd roughly need to module_list_compute(... prefix = "", pathspec = prefix, ...), i.e. struct cache_entry *ce = lookup_cache_entry_for(prefix); if (ce && S_ISGITLINK(ce->ce_mode)) /* this is an uninitialized submodule */ else /* this is just a normal prefix */ >> I think even when the .gitmodules file is missing, we want to have >> some sort of warning here, as it is a confusing state to run git >> from an uninitialized gitlink'd repository. The user may assume they >> run the command in the gitlink'd repo, so it may be better to bail out. > > Can you please give an example of such situation ? I would like to > reproduce it and think further. I think you can create such a situation via git init tmp cd tmp git init gitlink git -C gitlink commit --allow-empty -m "initial commit" -> git add gitlink git commit -m "add 'gitlink' as a gitlink" rm -rf gitlink mkdir gitlink git -C gitlink status Note that we used "git add" instead of "git submodule add". git-add doesn't care about submodule, i.e. doesn't create a .gitmodules entry for you (unlike "git submodule add"). Also note that the "rm -rf && mkdir" is just a placeholder to produce this state. An alternative ending after the commit could have been cd .. git clone tmp tmp2 cd tmp2 git -C gitlink status > (As even in the case where the superproject is initialized using gitlink, > .gitmodules is in the same folder as that of the .git file containing > GIT_DIR path) I do not understand this? > Also if it possible, I would like to > work on a smaller task related to my project first, as it will help me > understand about the project more, and which also will help me write > my proposal for the project. Heh, that is the beauty of open source, you don't have to ask permission. ;) But I guess this is meant as a question, on what this smaller project could be? Well as this proposal is heavy on path computation, I'd look for pathspec related leftovers at https://git-blame.blogspot.com/p/leftover-bits.html Thanks, Stefan