[PATCH v8 3/3] rev-parse: short-circuit superproject worktree when config unset

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In the previous commit, submodules learned a config
'submodule.hasSuperproject' to indicate whether or not we should attempt
to traverse the filesystem to find their superproject. To help test that
this config was added everywhere it should have been, begin using it to
decide whether to exit early from 'git rev-parse
--show-superproject-working-dir'.

Signed-off-by: Emily Shaffer <emilyshaffer@xxxxxxxxxx>

---

Maybe it's actually better to warn instead of error here? Or maybe it's
best not to say anything, but to set 'submodule.hasSuperproject' after
we successfully find the superproject?

Either way - I ran the test suite with this early exit added and
everything still passed. I made this change hoping to get a little
signal on whether the series achieved its goal, and in that regard I'm
satisfied.
---
 submodule.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/submodule.c b/submodule.c
index 741104af8a..463e7f0c48 100644
--- a/submodule.c
+++ b/submodule.c
@@ -2237,6 +2237,7 @@ int get_superproject_working_tree(struct strbuf *buf)
 	struct strbuf sb = STRBUF_INIT;
 	struct strbuf one_up = STRBUF_INIT;
 	const char *cwd = xgetcwd();
+	int has_superproject_cfg = 0;
 	int ret = 0;
 	const char *subpath;
 	int code;
@@ -2250,6 +2251,17 @@ int get_superproject_working_tree(struct strbuf *buf)
 		 */
 		return 0;
 
+	if (git_config_get_bool("submodule.hassuperproject", &has_superproject_cfg)
+	    || !has_superproject_cfg) {
+		/*
+		 * If we don't have a superproject, then we're probably not a
+		 * submodule. If this is failing and shouldn't be, investigate
+		 * why the config was never set.
+		 */
+		error(_("Asked to find a superproject, but submodule.hasSuperproject != true"));
+		return 0;
+	}
+
 	if (!strbuf_realpath(&one_up, "../", 0))
 		return 0;
 
-- 
2.35.1.574.g5d30c73bfb-goog




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux