summaryrefslogtreecommitdiff
path: root/submodule.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2018-11-13 13:37:22 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-11-13 13:37:22 (GMT)
commitabb4824d13a44f68d1bbaf6726945983230771f9 (patch)
tree316449048983aa8a4503af46cd450199a69b1078 /submodule.c
parent504bdc59948831ebccafb1be9f90bb58c02303eb (diff)
parent2b1257e463fe97b3f657bbf30fafdea0c4847cd7 (diff)
downloadgit-abb4824d13a44f68d1bbaf6726945983230771f9.zip
git-abb4824d13a44f68d1bbaf6726945983230771f9.tar.gz
git-abb4824d13a44f68d1bbaf6726945983230771f9.tar.bz2
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
Diffstat (limited to 'submodule.c')
-rw-r--r--submodule.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/submodule.c b/submodule.c
index a2701ed..6415cc5 100644
--- a/submodule.c
+++ b/submodule.c
@@ -52,6 +52,24 @@ int is_gitmodules_unmerged(const struct index_state *istate)
}
/*
+ * 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
* intention to stage them later, because when continuing we would stage 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;
}
/*