git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] setup: tweak upgrade policy to grandfather worktreeconfig

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 13, 2020, 20:18 UTC
Message-ID
<xmqqpn8zmao1.fsf_-_@gitster.c.googlers.com>
In-Reply-To
<xmqqy2nnmbh8.fsf@gitster.c.googlers.com>

The "fail and warn" approach introduced in the previous step may be with smaller impact to the codebase, but

 - it requires the end-user to read, understand and execute the
   manual upgrade
 - it encourages to follow the same procedure blindly, making the
   protection even less useful

Let's instead keep failing hard without teaching how to bypass the repository protection, but allow upgrading even when only the worktreeconfig extension exists in an old repository, which is likely to be set by a broke version of Git that did not update the repository version when setting the extension.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * This time with a log message to explain and justify the change,
   with a matching tweak to the test script, designed to be applied
   on top, but feel free to squash it in if you agree with me that
   we do not need two separate commits for this.
   Thanks.
 cache.h                            |  2 +-
 setup.c                            | 17 ++++++++---------
 t/t1091-sparse-checkout-builtin.sh |  9 ---------
 3 files changed, 9 insertions(+), 19 deletions(-)
diff --git a/cache.h b/cache.h
index e5885cc9ea..8ff46857f6 100644
--- a/cache.h
+++ b/cache.h
@@ -1042,8 +1042,8 @@ struct repository_format {
 	int worktree_config;
 	int is_bare;
 	int hash_algo;
-	int has_extensions;
 	char *work_tree;
+	int has_unallowed_extensions;
 	struct string_list unknown_extensions;
 };
 
diff --git a/setup.c b/setup.c
index 6ff6c54d39..65270440a9 100644
--- a/setup.c
+++ b/setup.c
@@ -455,12 +455,13 @@ static int check_repo_format(const char *var, const char *value, void *vdata)
 	if (strcmp(var, "core.repositoryformatversion") == 0)
 		data->version = git_config_int(var, value);
 	else if (skip_prefix(var, "extensions.", &ext)) {
-		data->has_extensions = 1;
 		/*
 		 * record any known extensions here; otherwise,
 		 * we fall through to recording it as unknown, and
 		 * check_repository_format will complain
 		 */
+		int is_unallowed_extension = 1;
+
 		if (!strcmp(ext, "noop"))
 			;
 		else if (!strcmp(ext, "preciousobjects"))
@@ -469,10 +470,13 @@ static int check_repo_format(const char *var, const char *value, void *vdata)
 			if (!value)
 				return config_error_nonbool(var);
 			data->partial_clone = xstrdup(value);
-		} else if (!strcmp(ext, "worktreeconfig"))
+		} else if (!strcmp(ext, "worktreeconfig")) {
 			data->worktree_config = git_config_bool(var, value);
-		else
+			is_unallowed_extension = 0;
+		} else
 			string_list_append(&data->unknown_extensions, ext);
+
+		data->has_unallowed_extensions |= is_unallowed_extension;
 	}
 
 	return read_worktree_config(var, value, vdata);
@@ -542,11 +546,6 @@ static int check_repository_format_gently(const char *gitdir, struct repository_
 		}
 	}
 
-	if (candidate->version == 0 && candidate->has_extensions) {
-		warning(_("some extensions are enabled, but core.repositoryFormatVersion=0"));
-		warning(_("if you intended to use extensions, run 'git config core.repositoryFormatVersion 1'"));
-	}
-
 	return 0;
 }
 
@@ -565,7 +564,7 @@ int upgrade_repository_format(int target_version)
 		return 0;
 
 	if (verify_repository_format(&repo_fmt, &err) < 0 ||
-	    (!repo_fmt.version && repo_fmt.has_extensions)) {
+	    (!repo_fmt.version && repo_fmt.has_unallowed_extensions)) {
 		warning("unable to upgrade repository format from %d to %d: %s",
 			repo_fmt.version, target_version, err.buf);
 		strbuf_release(&err);
diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh
index d249428f44..88cdde255c 100755
--- a/t/t1091-sparse-checkout-builtin.sh
+++ b/t/t1091-sparse-checkout-builtin.sh
@@ -68,15 +68,6 @@ test_expect_success 'git sparse-checkout init' '
 	check_files repo a
 '
 
-test_expect_success 'warning about core.repositoryFormatVersion' '
-	test_when_finished git -C repo config core.repositoryFormatVersion 1 &&
-	git -C repo status 2>err &&
-	test_must_be_empty err &&
-	git -C repo config --local core.repositoryFormatVersion 0 &&
-	git -C repo status 2>err &&
-	test_i18ngrep "some extensions are enabled, but core.repositoryFormatVersion=0" err
-'
-
 test_expect_success 'git sparse-checkout list after init' '
 	git -C repo sparse-checkout list >actual &&
 	cat >expect <<-\EOF &&
-- 
2.28.0-rc0
Previous: Junio C HamanoNext: Derrick Stolee
Message 6 of 15 in “setup: warn if extensions exist on old format”
  1. setup: warn if extensions exist on old formatDerrick Stolee via GitGitGadget, Jul 13, 2020
  2. Taylor BlauJul 13, 2020
  3. Derrick StoleeJul 13, 2020
  4. Junio C HamanoJul 13, 2020
  5. Junio C HamanoJul 13, 2020
  6. setup: tweak upgrade policy to grandfather worktreeconfigJunio C Hamano, Jul 13, 2020
  7. Derrick StoleeJul 13, 2020
  8. Junio C HamanoJul 13, 2020
  9. Jonathan NiederJul 14, 2020
  10. Junio C HamanoJul 14, 2020
  11. 0/2 setup: warn if extensions exist on old formatDerrick Stolee via GitGitGadget, Jul 14, 2020
  12. 1/2 setup: tweak upgrade policy to grandfather worktreeconfigDerrick Stolee via GitGitGadget, Jul 14, 2020
  13. Johannes SchindelinJul 14, 2020
  14. 2/2 config: provide extra detail about worktree configDerrick Stolee via GitGitGadget, Jul 14, 2020
  15. Johannes SchindelinJul 14, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.