Skip to contentSkip to conversation

remote: add camel-cased *.tagOpt key, like clone

PATCH In review Ævar Arnfjörð Bjarmason 3 participants 8 messages Feb 25, 2021 – Mar 18, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 remote: add camel-cased *.tagOpt key, like clone

Change "git remote add" so that it adds a *.tagOpt key, and not the lower-cased *.tagopt on "git remote add --no-tags", just as "git clone --no-tags" would do.

This doesn't matter for anything that reads the config. It's just prettier if we write config keys in their documented camelCase form to user-readable config files.

When I added support for "clone -no-tags" in 0dab2468ee5 (clone: add a --no-tags option to clone without tags, 2017-04-26) I made it use the *.tagOpt form, but the older "git remote add" added in 111fb858654 (remote add: add a --[no-]tags option, 2010-04-20) has been using *.tagopt all this time.

It's easy enough to add a test for this, so let's do that. We can't use "git config -l" there, because it'll normalize the keys to their lower-cased form. Let's add the test for "git clone" too for good measure, not just to the "git remote" codepath we're fixing.

---

I also noticed that we write e.g. init.objectformat instead of init.objectFormat, and core.logallrefupdates etc. If anyone's got an even even worse case of OCD there's an interesting #leftoverbits project there of scouring the code for more cases of this sort of thing...

 builtin/remote.c         | 2 +-
 t/t5505-remote.sh        | 1 +
 t/t5612-clone-refspec.sh | 1 +
 3 files changed, 3 insertions(+), 1 deletion(-)
builtin/remote.c +1 -1
index d11a5589e49..f286ae97538 100644
@@ -221,7 +221,7 @@ static int add(int argc, const char **argv)
 
 	if (fetch_tags != TAGS_DEFAULT) {
 		strbuf_reset(&buf);
-		strbuf_addf(&buf, "remote.%s.tagopt", name);
+		strbuf_addf(&buf, "remote.%s.tagOpt", name);
 		git_config_set(buf.buf,
 			       fetch_tags == TAGS_SET ? "--tags" : "--no-tags");
 	}
t/t5505-remote.sh +1 -0
index 045398b94e6..2a7b5cd00a0 100755
@@ -594,6 +594,7 @@ test_expect_success 'add --no-tags' '
 		cd add-no-tags &&
 		git init &&
 		git remote add -f --no-tags origin ../one &&
+		grep tagOpt .git/config &&
 		git tag -l some-tag >../test/output &&
 		git tag -l foobar-tag >../test/output &&
 		git config remote.origin.tagopt >>../test/output
t/t5612-clone-refspec.sh +1 -0
index 6a6af7449ca..3126cfd7e9d 100755
@@ -97,6 +97,7 @@ test_expect_success 'by default no tags will be kept updated' '
 test_expect_success 'clone with --no-tags' '
 	(
 		cd dir_all_no_tags &&
+		grep tagOpt .git/config &&
 		git fetch &&
 		git for-each-ref refs/tags >../actual
 	) &&
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7
#1 lore raw

PATCH 2/2 remote: write camel-cased *.pushRemote on rename

When a remote is renamed don't change the canonical "*.pushRemote" form to "*.pushremote". Fixes and tests for a minor bug in 923d4a5ca4f (remote rename/remove: handle branch.<name>.pushRemote config values, 2020-01-27). See the preceding commit for why this does & doesn't matter.

While we're at it let's also test that we handle the "*.pushDefault" key correctly. The code to handle that was added in b3fd6cbf294 (remote rename/remove: gently handle remote.pushDefault config, 2020-02-01) and does the right thing, but nothing tested that we wrote out the canonical camel-cased form.

---
 builtin/remote.c  | 2 +-
 t/t5505-remote.sh | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)
builtin/remote.c +1 -1
index f286ae97538..717b662d455 100644
@@ -746,7 +746,7 @@ static int mv(int argc, const char **argv)
 		}
 		if (info->push_remote_name && !strcmp(info->push_remote_name, rename.old_name)) {
 			strbuf_reset(&buf);
-			strbuf_addf(&buf, "branch.%s.pushremote", item->string);
+			strbuf_addf(&buf, "branch.%s.pushRemote", item->string);
 			git_config_set(buf.buf, rename.new_name);
 		}
 	}
t/t5505-remote.sh +2 -0
index 2a7b5cd00a0..34fc3fa421f 100755
@@ -757,6 +757,7 @@ test_expect_success 'rename a remote' '
 		cd four &&
 		git config branch.main.pushRemote origin &&
 		git remote rename origin upstream &&
+		grep "pushRemote" .git/config &&
 		test -z "$(git for-each-ref refs/remotes/origin)" &&
 		test "$(git symbolic-ref refs/remotes/upstream/HEAD)" = "refs/remotes/upstream/main" &&
 		test "$(git rev-parse upstream/main)" = "$(git rev-parse main)" &&
@@ -773,6 +774,7 @@ test_expect_success 'rename a remote renames repo remote.pushDefault' '
 		cd four.1 &&
 		git config remote.pushDefault origin &&
 		git remote rename origin upstream &&
+		grep pushDefault .git/config &&
 		test "$(git config --local remote.pushDefault)" = "upstream"
 	)
 '
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7
#4 lore raw
In reply to Ævar Arnfjörð Bjarmason
Quoted 38 lines · Ævar Arnfjörð Bjarmason

Change "git remote add" so that it adds a *.tagOpt key, and not the lower-cased *.tagopt on "git remote add --no-tags", just as "git clone --no-tags" would do.

This doesn't matter for anything that reads the config. It's just prettier if we write config keys in their documented camelCase form to user-readable config files.

When I added support for "clone -no-tags" in 0dab2468ee5 (clone: add a --no-tags option to clone without tags, 2017-04-26) I made it use the *.tagOpt form, but the older "git remote add" added in 111fb858654 (remote add: add a --[no-]tags option, 2010-04-20) has been using *.tagopt all this time.

It's easy enough to add a test for this, so let's do that. We can't use "git config -l" there, because it'll normalize the keys to their lower-cased form. Let's add the test for "git clone" too for good measure, not just to the "git remote" codepath we're fixing.

---

I also noticed that we write e.g. init.objectformat instead of init.objectFormat, and core.logallrefupdates etc. If anyone's got an even even worse case of OCD there's an interesting #leftoverbits project there of scouring the code for more cases of this sort of thing...

 builtin/remote.c         | 2 +-
 t/t5505-remote.sh        | 1 +
 t/t5612-clone-refspec.sh | 1 +
 3 files changed, 3 insertions(+), 1 deletion(-)
builtin/remote.c +0 -0
index d11a5589e49..f286ae97538 100644

builtin/remote.c static int add(int argc, const char **argv) · line 224

Quoted 5 lines
builtin/remote.c +1 -1
@@ -221,7 +221,7 @@ static int add(int argc, const char **argv)
 
 	if (fetch_tags != TAGS_DEFAULT) {
 		strbuf_reset(&buf);
-		strbuf_addf(&buf, "remote.%s.tagopt", name);
+		strbuf_addf(&buf, "remote.%s.tagOpt", name);

Good find.

A general rule for a name used to refer to a configuration variable the C code ought to be

- if it is used to match what the system gave us, make sure we use all lowercase for the first and the last component and match with strcmp(), not with strcasecmp().

- if it is used to update, make sure we use the canonical spelling, if only for the documentation value.

Quoted 24 lines
t/t5505-remote.sh +1 -0
index 045398b94e6..2a7b5cd00a0 100755
@@ -594,6 +594,7 @@ test_expect_success 'add --no-tags' '
 		cd add-no-tags &&
 		git init &&
 		git remote add -f --no-tags origin ../one &&
+		grep tagOpt .git/config &&
 		git tag -l some-tag >../test/output &&
 		git tag -l foobar-tag >../test/output &&
 		git config remote.origin.tagopt >>../test/output
t/t5612-clone-refspec.sh +1 -0
index 6a6af7449ca..3126cfd7e9d 100755
@@ -97,6 +97,7 @@ test_expect_success 'by default no tags will be kept updated' '
 test_expect_success 'clone with --no-tags' '
 	(
 		cd dir_all_no_tags &&
+		grep tagOpt .git/config &&
 		git fetch &&
 		git for-each-ref refs/tags >../actual
 	) &&
#5 lore raw
In reply to Ævar Arnfjörð Bjarmason
Quoted 3 lines · Ævar Arnfjörð Bjarmason

It's easy enough to add a test for this, so let's do that. We can't use "git config -l" there, because it'll normalize the keys to their lower-cased form.

I wondered if we want "git config -l --preserve-case" or something like that, but an extra grep for "tagOpt" would be sufficient in a simple test like these that are unlikely to have unrelated tagOpt defined in the file. More importantly, I am starting to doubt if this should even be tested.

If there were existing "section.varname" variable definition and we ask

	git_config_set("section.varName", "newvalue");

we may end up with "[section] varname = newvalue", and that is perfectly OK, I would think, because the first and the last component of the configuration variable names are defined to be case insensitive, and here may be "[Section] varname = oldvalue" in the configuration file before we try to set it, and the implementation is free to replace "oldvalue" with "newvalue", instead of first removing "[Section] varname = oldvalue" and then adding a new "[section] varName = newvalue" (after all, there may be variables other than "varname" in the section, and the existing "[Section]" header may need to be kept for the remaining variables while we futz with the varname or varName).

Which means that while we do want to spell the names in our source code correctly (i.e. "tagOpt", not "tagopt") when we tell which variable we want to get modified to the git_config_set() function, we should not care how exactly git_config_set() chooses to spell the variable in the resulting configuration file, no?

So, ...

t/t5612-clone-refspec.sh test_expect_success 'by default no tags will be kept updated' ' · line 102

Quoted 11 lines
t/t5612-clone-refspec.sh +1 -0
index 6a6af7449ca..3126cfd7e9d 100755
@@ -97,6 +97,7 @@ test_expect_success 'by default no tags will be kept updated' '
 test_expect_success 'clone with --no-tags' '
 	(
 		cd dir_all_no_tags &&
+		grep tagOpt .git/config &&
 		git fetch &&
 		git for-each-ref refs/tags >../actual

...as long as "git config remote.origin.tagopt" yields what we expect, we should be OK, I would think. Insisting that the variable name is kept by git_config_set() API may be expecting too much.

Quoted 1 line
t/t5612-clone-refspec.sh +0 -0
 	) &&
#2 lore raw

Re: [PATCH 2/2] remote: write camel-cased *.pushRemote on rename

In reply to Ævar Arnfjörð Bjarmason
Quoted 44 lines · Ævar Arnfjörð Bjarmason

When a remote is renamed don't change the canonical "*.pushRemote" form to "*.pushremote". Fixes and tests for a minor bug in 923d4a5ca4f (remote rename/remove: handle branch.<name>.pushRemote config values, 2020-01-27). See the preceding commit for why this does & doesn't matter.

While we're at it let's also test that we handle the "*.pushDefault" key correctly. The code to handle that was added in b3fd6cbf294 (remote rename/remove: gently handle remote.pushDefault config, 2020-02-01) and does the right thing, but nothing tested that we wrote out the canonical camel-cased form.

---
 builtin/remote.c  | 2 +-
 t/t5505-remote.sh | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)
builtin/remote.c +1 -1
index f286ae97538..717b662d455 100644
@@ -746,7 +746,7 @@ static int mv(int argc, const char **argv)
 		}
 		if (info->push_remote_name && !strcmp(info->push_remote_name, rename.old_name)) {
 			strbuf_reset(&buf);
-			strbuf_addf(&buf, "branch.%s.pushremote", item->string);
+			strbuf_addf(&buf, "branch.%s.pushRemote", item->string);
 			git_config_set(buf.buf, rename.new_name);
 		}
 	}
t/t5505-remote.sh +1 -0
index 2a7b5cd00a0..34fc3fa421f 100755
@@ -757,6 +757,7 @@ test_expect_success 'rename a remote' '
 		cd four &&
 		git config branch.main.pushRemote origin &&
 		git remote rename origin upstream &&
+		grep "pushRemote" .git/config &&
 		test -z "$(git for-each-ref refs/remotes/origin)" &&
 		test "$(git symbolic-ref refs/remotes/upstream/HEAD)" = "refs/remotes/upstream/main" &&
 		test "$(git rev-parse upstream/main)" = "$(git rev-parse main)" &&

t/t5505-remote.sh test_expect_success 'rename a remote renames repo remote.pushDefault' ' · line 780

Quoted 7 lines
t/t5505-remote.sh +1 -0
@@ -773,6 +774,7 @@ test_expect_success 'rename a remote renames repo remote.pushDefault' '
 		cd four.1 &&
 		git config remote.pushDefault origin &&
 		git remote rename origin upstream &&
+		grep pushDefault .git/config &&
 		test "$(git config --local remote.pushDefault)" = "upstream"
 	)
 '

Again, good find, but I am not sure if we want the test to be so strict. Besides, quoting one and not quoting the other in the same patch looks the test is also being inconsistent ;-).

Thanks.

#6 lore raw
In reply to Junio C Hamano
Quoted 29 lines · Junio C Hamano
Quoted 3 lines · Ævar Arnfjörð Bjarmason

It's easy enough to add a test for this, so let's do that. We can't use "git config -l" there, because it'll normalize the keys to their lower-cased form.

I wondered if we want "git config -l --preserve-case" or something like that, but an extra grep for "tagOpt" would be sufficient in a simple test like these that are unlikely to have unrelated tagOpt defined in the file. More importantly, I am starting to doubt if this should even be tested.

If there were existing "section.varname" variable definition and we ask

	git_config_set("section.varName", "newvalue");

we may end up with "[section] varname = newvalue", and that is perfectly OK, I would think, because the first and the last component of the configuration variable names are defined to be case insensitive, and here may be "[Section] varname = oldvalue" in the configuration file before we try to set it, and the implementation is free to replace "oldvalue" with "newvalue", instead of first removing "[Section] varname = oldvalue" and then adding a new "[section] varName = newvalue" (after all, there may be variables other than "varname" in the section, and the existing "[Section]" header may need to be kept for the remaining variables while we futz with the varname or varName).

Quoted 7 lines

Which means that while we do want to spell the names in our source code correctly (i.e. "tagOpt", not "tagopt") when we tell which variable we want to get modified to the git_config_set() function, we should not care how exactly git_config_set() chooses to spell the variable in the resulting configuration file, no?

So, ...

Yes, in general, but...

Quoted 7 lines
Quoted 7 lines
t/t5612-clone-refspec.sh +0 -0
index 6a6af7449ca..3126cfd7e9d 100755
@@ -97,6 +97,7 @@ test_expect_success 'by default no tags will be kept updated' '
 test_expect_success 'clone with --no-tags' '
 	(
Quoted 10 lines

t/t5612-clone-refspec.sh test_expect_success 'by default no tags will be kept updated' ' · line 102

Quoted 4 lines
t/t5612-clone-refspec.sh +1 -0
 		cd dir_all_no_tags &&
+		grep tagOpt .git/config &&
 		git fetch &&
 		git for-each-ref refs/tags >../actual

...as long as "git config remote.origin.tagopt" yields what we expect, we should be OK, I would think. Insisting that the variable name is kept by git_config_set() API may be expecting too much.

Quoted 1 line
t/t5612-clone-refspec.sh +0 -0
 	) &&

...the cases fixed in this series are not ones where we're possibly changing an existing variable name, but where we're guaranteed to be writing new values.

We are renaming a remote or otherwise moving variables around, if there were existing values to contend with we'd have died earlier.

I'm not quite sure what to make of this feedback in general. That you'd like the bugfix but we shouldn't bother with a regression test, or that we shouldn't bother with the fix at all?

I admit this is getting to diminishing returns in testing, we're unlikely to break this, and if we do it's not such a big deal.

But I don't agree that we should feel free to munge user config files within the bound of valid config syntax when we edit these files for users.

We already go out of our way to add values to existing sections, not add new empty headings etc. (I believe the last major effort on that front was from Johannes S. a while back).

likewise here, even though cmd.averylongvariablename is perfectly valid, it's much more user friendly if we write/edit it as cmd.AVeryLongVariableName.

#7 lore raw
Quoted 3 lines · Ævar Arnfjörð Bjarmason

I'm not quite sure what to make of this feedback in general. That you'd like the bugfix but we shouldn't bother with a regression test, or that we shouldn't bother with the fix at all?

I like the style update to make the callers use the canonical case (even though they do not have to), but the test that inspects the cases in the resulting configuration file may be too strict.

Quoted 3 lines

But I don't agree that we should feel free to munge user config files within the bound of valid config syntax when we edit these files for users.

I agree with your sentiment in principle. I just wanted to make sure that future test writers agree with the principle, and also that they understand there are cases where end-user input may not match the output (e.g. when running "git config Vari.Able value" to an existing configuration file that has "[vari] ous = true", it may be less desirable to add "[Vari] Able = value" than to add to the existing "[Vari] section a new line "Able = value").

#3 lore raw

Re: [PATCH 2/2] remote: write camel-cased *.pushRemote on rename

In reply to Ævar Arnfjörð Bjarmason
Quoted 7 lines · Ævar Arnfjörð Bjarmason

When a remote is renamed don't change the canonical "*.pushRemote" form to "*.pushremote". Fixes and tests for a minor bug in 923d4a5ca4f (remote rename/remove: handle branch.<name>.pushRemote config values, 2020-01-27). See the preceding commit for why this does & doesn't matter.

Quoted 6 lines

While we're at it let's also test that we handle the "*.pushDefault" key correctly. The code to handle that was added in b3fd6cbf294 (remote rename/remove: gently handle remote.pushDefault config, 2020-02-01) and does the right thing, but nothing tested that we wrote out the canonical camel-cased form.

Fine with me.

Thanks.

Quoted 42 lines
---
 builtin/remote.c  | 2 +-
 t/t5505-remote.sh | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)
builtin/remote.c +1 -1
index f286ae97538..717b662d455 100644
@@ -746,7 +746,7 @@ static int mv(int argc, const char **argv)
                }
                if (info->push_remote_name && !strcmp(info->push_remote_name, rename.old_name)) {
                        strbuf_reset(&buf);
-                       strbuf_addf(&buf, "branch.%s.pushremote", item->string);
+                       strbuf_addf(&buf, "branch.%s.pushRemote", item->string);
                        git_config_set(buf.buf, rename.new_name);
                }
        }
t/t5505-remote.sh +2 -1
index 2a7b5cd00a0..34fc3fa421f 100755
@@ -757,6 +757,7 @@ test_expect_success 'rename a remote' '
                cd four &&
                git config branch.main.pushRemote origin &&
                git remote rename origin upstream &&
+               grep "pushRemote" .git/config &&
                test -z "$(git for-each-ref refs/remotes/origin)" &&
                test "$(git symbolic-ref refs/remotes/upstream/HEAD)" = "refs/remotes/upstream/main" &&
                test "$(git rev-parse upstream/main)" = "$(git rev-parse main)" &&
@@ -773,6 +774,7 @@ test_expect_success 'rename a remote renames repo remote.pushDefault' '
                cd four.1 &&
                git config remote.pushDefault origin &&
                git remote rename origin upstream &&
+               grep pushDefault .git/config &&
                test "$(git config --local remote.pushDefault)" = "upstream"
        )
 '
--

2.30.0.284.gd98b1dd5eaa7