Merge branch 'ao/submodule-wo-gitmodules-checked-out'
The submodule support has been updated to read from the blob at HEAD:.gitmodules when the .gitmodules file is missing from the working tree. * ao/submodule-wo-gitmodules-checked-out: t/helper: add test-submodule-nested-repo-config submodule: support reading .gitmodules when it's not in the working tree submodule: add a helper to check if it is safe to write to .gitmodules t7506: clean up .gitmodules properly before setting up new scenario submodule: use the 'submodule--helper config' command submodule--helper: add a new 'config' subcommand t7411: be nicer to future tests and really clean things up t7411: merge tests 5 and 6 submodule: factor out a config_set_in_gitmodules_file_gently function submodule: add a print_config_from_gitmodules() helper
This commit is contained in:
28
submodule.c
28
submodule.c
@ -51,6 +51,24 @@ int is_gitmodules_unmerged(const struct index_state *istate)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if the .gitmodules file is safe to write.
|
||||
*
|
||||
* Writing to the .gitmodules file requires that the file exists in the
|
||||
* working tree or, if it doesn't, that a brand new .gitmodules file is going
|
||||
* to be created (i.e. it's neither in the index nor in the current branch).
|
||||
*
|
||||
* It is not safe to write to .gitmodules if it's not in the working tree but
|
||||
* it is in the index or in the current branch, because writing new values
|
||||
* (and staging them) would blindly overwrite ALL the old content.
|
||||
*/
|
||||
int is_writing_gitmodules_ok(void)
|
||||
{
|
||||
struct object_id oid;
|
||||
return file_exists(GITMODULES_FILE) ||
|
||||
(get_oid(GITMODULES_INDEX, &oid) < 0 && get_oid(GITMODULES_HEAD, &oid) < 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if the .gitmodules file has unstaged modifications. This must be
|
||||
* checked before allowing modifications to the .gitmodules file with the
|
||||
@ -89,6 +107,7 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath)
|
||||
{
|
||||
struct strbuf entry = STRBUF_INIT;
|
||||
const struct submodule *submodule;
|
||||
int ret;
|
||||
|
||||
if (!file_exists(GITMODULES_FILE)) /* Do nothing without .gitmodules */
|
||||
return -1;
|
||||
@ -104,14 +123,9 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath)
|
||||
strbuf_addstr(&entry, "submodule.");
|
||||
strbuf_addstr(&entry, submodule->name);
|
||||
strbuf_addstr(&entry, ".path");
|
||||
if (git_config_set_in_file_gently(GITMODULES_FILE, entry.buf, newpath) < 0) {
|
||||
/* Maybe the user already did that, don't error out here */
|
||||
warning(_("Could not update .gitmodules entry %s"), entry.buf);
|
||||
strbuf_release(&entry);
|
||||
return -1;
|
||||
}
|
||||
ret = config_set_in_gitmodules_file_gently(entry.buf, newpath);
|
||||
strbuf_release(&entry);
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user