From: Johannes Schindelin Date: Thu, 24 Nov 2005 10:36:01 +0000 (+0100) Subject: Rename git-config-set to git-repo-config X-Git-Tag: v0.99.9k^2~9 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/ee72aeaf009417156a3599b0eb69da3f7023ca07?hp=a50b870aa18738ec10ed31fd4a32a284ee1cfe50 Rename git-config-set to git-repo-config ... and adjust all references. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- diff --git a/.gitignore b/.gitignore index d17a8b5845..8a6bd02d4f 100644 --- a/.gitignore +++ b/.gitignore @@ -17,7 +17,6 @@ git-clone git-clone-pack git-commit git-commit-tree -git-config-set git-convert-objects git-count-objects git-cvsexportcommit @@ -76,6 +75,7 @@ git-rebase git-receive-pack git-relink git-repack +git-repo-config git-request-pull git-reset git-resolve diff --git a/Documentation/git-config-set.txt b/Documentation/git-config-set.txt deleted file mode 100644 index bfbd42147a..0000000000 --- a/Documentation/git-config-set.txt +++ /dev/null @@ -1,170 +0,0 @@ -git-config-set(1) -=============== - -NAME ----- -git-config-set - Set options in .git/config. - - -SYNOPSIS --------- -'git-config-set' name [value [value_regex]] -'git-config-set' --replace-all name [value [value_regex]] -'git-config-set' --get name [value_regex] -'git-config-set' --get-all name [value_regex] -'git-config-set' --unset name [value_regex] -'git-config-set' --unset-all name [value_regex] - -DESCRIPTION ------------ -You can query/set/replace/unset options with this command. The name is -actually the section and the key separated by a dot, and the value will be -escaped. - -If you want to set/unset an option which can occor on multiple lines, you -should provide a POSIX regex for the value. If you want to handle the lines -*not* matching the regex, just prepend a single exlamation mark in front -(see EXAMPLES). - -This command will fail if - -. .git/config is invalid, -. .git/config can not be written to, -. no section was provided, -. the section or key is invalid, -. you try to unset an option which does not exist, or -. you try to unset/set an option for which multiple lines match. - - -OPTIONS -------- - ---replace-all:: - Default behaviour is to replace at most one line. This replaces - all lines matching the key (and optionally the value_regex) - ---get:: - Get the value for a given key (optionally filtered by a regex - matching the value). - ---get-all:: - Like get, but does not fail if the number of values for the key - is not exactly one. - ---unset:: - Remove the line matching the key from .git/config. - ---unset-all:: - Remove all matching lines from .git/config. - - -EXAMPLE -------- - -Given a .git/config like this: - - # - # This is the config file, and - # a '#' or ';' character indicates - # a comment - # - - ; core variables - [core] - ; Don't trust file modes - filemode = false - - ; Our diff algorithm - [diff] - external = "/usr/local/bin/gnu-diff -u" - renames = true - - ; Proxy settings - [proxy] - command="ssh" for "ssh://kernel.org/" - command="proxy-command" for kernel.org - command="myprotocol-command" for "my://" - command=default-proxy ; for all the rest - -you can set the filemode to true with - ------------- -% git config-set core.filemode true ------------- - -The hypothetic proxy command entries actually have a postfix to discern -to what URL they apply. Here is how to change the entry for kernel.org -to "ssh". - ------------- -% git config-set proxy.command '"ssh" for kernel.org' 'for kernel.org$' ------------- - -This makes sure that only the key/value pair for kernel.org is replaced. - -To delete the entry for renames, do - ------------- -% git config-set --unset diff.renames ------------- - -If you want to delete an entry for a multivar (like proxy.command above), -you have to provide a regex matching the value of exactly one line. - -To query the value for a given key, do - ------------- -% git config-set --get core.filemode ------------- - -or - ------------- -% git config-set core.filemode ------------- - -or, to query a multivar: - ------------- -% git config-set --get proxy.command "for kernel.org$" ------------- - -If you want to know all the values for a multivar, do: - ------------- -% git config-set --get-all proxy.command ------------- - -If you like to live dangerous, you can replace *all* proxy.commands by a -new one with - ------------- -% git config-set --replace-all proxy.command ssh ------------- - -However, if you really only want to replace the line for the default proxy, -i.e. the one without a "for ..." postfix, do something like this: - ------------- -% git config-set proxy.command ssh '! for ' ------------- - -To actually match only values with an exclamation mark, you have to - ------------- -% git config-set section.key value '[!]' ------------- - - -Author ------- -Written by Johannes Schindelin - -Documentation --------------- -Documentation by Johannes Schindelin. - -GIT ---- -Part of the gitlink:git[7] suite - diff --git a/Documentation/git-repo-config.txt b/Documentation/git-repo-config.txt new file mode 100644 index 0000000000..5eefe02437 --- /dev/null +++ b/Documentation/git-repo-config.txt @@ -0,0 +1,170 @@ +git-repo-config(1) +================== + +NAME +---- +git-repo-config - Get and set options in .git/config. + + +SYNOPSIS +-------- +'git-repo-config' name [value [value_regex]] +'git-repo-config' --replace-all name [value [value_regex]] +'git-repo-config' --get name [value_regex] +'git-repo-config' --get-all name [value_regex] +'git-repo-config' --unset name [value_regex] +'git-repo-config' --unset-all name [value_regex] + +DESCRIPTION +----------- +You can query/set/replace/unset options with this command. The name is +actually the section and the key separated by a dot, and the value will be +escaped. + +If you want to set/unset an option which can occor on multiple lines, you +should provide a POSIX regex for the value. If you want to handle the lines +*not* matching the regex, just prepend a single exlamation mark in front +(see EXAMPLES). + +This command will fail if + +. .git/config is invalid, +. .git/config can not be written to, +. no section was provided, +. the section or key is invalid, +. you try to unset an option which does not exist, or +. you try to unset/set an option for which multiple lines match. + + +OPTIONS +------- + +--replace-all:: + Default behaviour is to replace at most one line. This replaces + all lines matching the key (and optionally the value_regex) + +--get:: + Get the value for a given key (optionally filtered by a regex + matching the value). + +--get-all:: + Like get, but does not fail if the number of values for the key + is not exactly one. + +--unset:: + Remove the line matching the key from .git/config. + +--unset-all:: + Remove all matching lines from .git/config. + + +EXAMPLE +------- + +Given a .git/config like this: + + # + # This is the config file, and + # a '#' or ';' character indicates + # a comment + # + + ; core variables + [core] + ; Don't trust file modes + filemode = false + + ; Our diff algorithm + [diff] + external = "/usr/local/bin/gnu-diff -u" + renames = true + + ; Proxy settings + [proxy] + command="ssh" for "ssh://kernel.org/" + command="proxy-command" for kernel.org + command="myprotocol-command" for "my://" + command=default-proxy ; for all the rest + +you can set the filemode to true with + +------------ +% git repo-config core.filemode true +------------ + +The hypothetic proxy command entries actually have a postfix to discern +to what URL they apply. Here is how to change the entry for kernel.org +to "ssh". + +------------ +% git repo-config proxy.command '"ssh" for kernel.org' 'for kernel.org$' +------------ + +This makes sure that only the key/value pair for kernel.org is replaced. + +To delete the entry for renames, do + +------------ +% git repo-config --unset diff.renames +------------ + +If you want to delete an entry for a multivar (like proxy.command above), +you have to provide a regex matching the value of exactly one line. + +To query the value for a given key, do + +------------ +% git repo-config --get core.filemode +------------ + +or + +------------ +% git repo-config core.filemode +------------ + +or, to query a multivar: + +------------ +% git repo-config --get proxy.command "for kernel.org$" +------------ + +If you want to know all the values for a multivar, do: + +------------ +% git repo-config --get-all proxy.command +------------ + +If you like to live dangerous, you can replace *all* proxy.commands by a +new one with + +------------ +% git repo-config --replace-all proxy.command ssh +------------ + +However, if you really only want to replace the line for the default proxy, +i.e. the one without a "for ..." postfix, do something like this: + +------------ +% git repo-config proxy.command ssh '! for ' +------------ + +To actually match only values with an exclamation mark, you have to + +------------ +% git repo-config section.key value '[!]' +------------ + + +Author +------ +Written by Johannes Schindelin + +Documentation +-------------- +Documentation by Johannes Schindelin. + +GIT +--- +Part of the gitlink:git[7] suite + diff --git a/Documentation/git.txt b/Documentation/git.txt index 694fee8f2a..a518249863 100644 --- a/Documentation/git.txt +++ b/Documentation/git.txt @@ -84,9 +84,6 @@ gitlink:git-checkout-index[1]:: gitlink:git-commit-tree[1]:: Creates a new commit object -gitlink:git-config-set[1]:: - Set options in .git/config. - gitlink:git-hash-object[1]:: Computes the object ID from a file. @@ -111,6 +108,9 @@ gitlink:git-prune-packed[1]:: gitlink:git-read-tree[1]:: Reads tree information into the directory index +gitlink:git-repo-config[1]:: + Get and set options in .git/config. + gitlink:git-unpack-objects[1]:: Unpacks objects out of a packed archive. diff --git a/Makefile b/Makefile index a97a5d9595..984d167def 100644 --- a/Makefile +++ b/Makefile @@ -130,7 +130,7 @@ PROGRAMS = \ git-unpack-objects$X git-update-index$X git-update-server-info$X \ git-upload-pack$X git-verify-pack$X git-write-tree$X \ git-update-ref$X git-symbolic-ref$X git-check-ref-format$X \ - git-name-rev$X git-pack-redundant$X git-config-set$X git-var$X + git-name-rev$X git-pack-redundant$X git-repo-config$X git-var$X # what 'all' will build and 'install' will install. ALL_PROGRAMS = $(PROGRAMS) $(SIMPLE_PROGRAMS) $(SCRIPTS) git$X diff --git a/config-set.c b/config-set.c deleted file mode 100644 index d938f96768..0000000000 --- a/config-set.c +++ /dev/null @@ -1,116 +0,0 @@ -#include "cache.h" -#include - -static const char git_config_set_usage[] = -"git-config-set [--get | --get-all | --replace-all | --unset | --unset-all] name [value [value_regex]]"; - -static char* key = NULL; -static char* value = NULL; -static regex_t* regex = NULL; -static int do_all = 0; -static int do_not_match = 0; -static int seen = 0; - -static int show_config(const char* key_, const char* value_) -{ - if (!strcmp(key_, key) && - (regex == NULL || - (do_not_match ^ - !regexec(regex, value_, 0, NULL, 0)))) { - if (do_all) { - printf("%s\n", value_); - return 0; - } - if (seen > 0) { - fprintf(stderr, "More than one value: %s\n", value); - free(value); - } - value = strdup(value_); - seen++; - } - return 0; -} - -static int get_value(const char* key_, const char* regex_) -{ - int i; - - key = malloc(strlen(key_)+1); - for (i = 0; key_[i]; i++) - key[i] = tolower(key_[i]); - key[i] = 0; - - if (regex_) { - if (regex_[0] == '!') { - do_not_match = 1; - regex_++; - } - - regex = (regex_t*)malloc(sizeof(regex_t)); - if (regcomp(regex, regex_, REG_EXTENDED)) { - fprintf(stderr, "Invalid pattern: %s\n", regex_); - return -1; - } - } - - i = git_config(show_config); - if (value) { - printf("%s\n", value); - free(value); - } - free(key); - if (regex) { - regfree(regex); - free(regex); - } - - if (do_all) - return 0; - - return seen == 1 ? 0 : 1; -} - -int main(int argc, const char **argv) -{ - setup_git_directory(); - switch (argc) { - case 2: - return get_value(argv[1], NULL); - case 3: - if (!strcmp(argv[1], "--unset")) - return git_config_set(argv[2], NULL); - else if (!strcmp(argv[1], "--unset-all")) - return git_config_set_multivar(argv[2], NULL, NULL, 1); - else if (!strcmp(argv[1], "--get")) - return get_value(argv[2], NULL); - else if (!strcmp(argv[1], "--get-all")) { - do_all = 1; - return get_value(argv[2], NULL); - } else - - return git_config_set(argv[1], argv[2]); - case 4: - if (!strcmp(argv[1], "--unset")) - return git_config_set_multivar(argv[2], NULL, argv[3], 0); - else if (!strcmp(argv[1], "--unset-all")) - return git_config_set_multivar(argv[2], NULL, argv[3], 1); - else if (!strcmp(argv[1], "--get")) - return get_value(argv[2], argv[3]); - else if (!strcmp(argv[1], "--get-all")) { - do_all = 1; - return get_value(argv[2], argv[3]); - } else if (!strcmp(argv[1], "--replace-all")) - - return git_config_set_multivar(argv[2], argv[3], NULL, 1); - else - - return git_config_set_multivar(argv[1], argv[2], argv[3], 0); - case 5: - if (!strcmp(argv[1], "--replace-all")) - return git_config_set_multivar(argv[2], argv[3], argv[4], 1); - case 1: - default: - usage(git_config_set_usage); - } - return 0; -} diff --git a/repo-config.c b/repo-config.c new file mode 100644 index 0000000000..b2569b7901 --- /dev/null +++ b/repo-config.c @@ -0,0 +1,116 @@ +#include "cache.h" +#include + +static const char git_config_set_usage[] = +"git-repo-config [--get | --get-all | --replace-all | --unset | --unset-all] name [value [value_regex]]"; + +static char* key = NULL; +static char* value = NULL; +static regex_t* regex = NULL; +static int do_all = 0; +static int do_not_match = 0; +static int seen = 0; + +static int show_config(const char* key_, const char* value_) +{ + if (!strcmp(key_, key) && + (regex == NULL || + (do_not_match ^ + !regexec(regex, value_, 0, NULL, 0)))) { + if (do_all) { + printf("%s\n", value_); + return 0; + } + if (seen > 0) { + fprintf(stderr, "More than one value: %s\n", value); + free(value); + } + value = strdup(value_); + seen++; + } + return 0; +} + +static int get_value(const char* key_, const char* regex_) +{ + int i; + + key = malloc(strlen(key_)+1); + for (i = 0; key_[i]; i++) + key[i] = tolower(key_[i]); + key[i] = 0; + + if (regex_) { + if (regex_[0] == '!') { + do_not_match = 1; + regex_++; + } + + regex = (regex_t*)malloc(sizeof(regex_t)); + if (regcomp(regex, regex_, REG_EXTENDED)) { + fprintf(stderr, "Invalid pattern: %s\n", regex_); + return -1; + } + } + + i = git_config(show_config); + if (value) { + printf("%s\n", value); + free(value); + } + free(key); + if (regex) { + regfree(regex); + free(regex); + } + + if (do_all) + return 0; + + return seen == 1 ? 0 : 1; +} + +int main(int argc, const char **argv) +{ + setup_git_directory(); + switch (argc) { + case 2: + return get_value(argv[1], NULL); + case 3: + if (!strcmp(argv[1], "--unset")) + return git_config_set(argv[2], NULL); + else if (!strcmp(argv[1], "--unset-all")) + return git_config_set_multivar(argv[2], NULL, NULL, 1); + else if (!strcmp(argv[1], "--get")) + return get_value(argv[2], NULL); + else if (!strcmp(argv[1], "--get-all")) { + do_all = 1; + return get_value(argv[2], NULL); + } else + + return git_config_set(argv[1], argv[2]); + case 4: + if (!strcmp(argv[1], "--unset")) + return git_config_set_multivar(argv[2], NULL, argv[3], 0); + else if (!strcmp(argv[1], "--unset-all")) + return git_config_set_multivar(argv[2], NULL, argv[3], 1); + else if (!strcmp(argv[1], "--get")) + return get_value(argv[2], argv[3]); + else if (!strcmp(argv[1], "--get-all")) { + do_all = 1; + return get_value(argv[2], argv[3]); + } else if (!strcmp(argv[1], "--replace-all")) + + return git_config_set_multivar(argv[2], argv[3], NULL, 1); + else + + return git_config_set_multivar(argv[1], argv[2], argv[3], 0); + case 5: + if (!strcmp(argv[1], "--replace-all")) + return git_config_set_multivar(argv[2], argv[3], argv[4], 1); + case 1: + default: + usage(git_config_set_usage); + } + return 0; +} diff --git a/t/t1300-config-set.sh b/t/t1300-config-set.sh deleted file mode 100644 index 7a5849ae66..0000000000 --- a/t/t1300-config-set.sh +++ /dev/null @@ -1,271 +0,0 @@ -#!/bin/sh -# -# Copyright (c) 2005 Johannes Schindelin -# - -test_description='Test git-config-set in different settings' - -. ./test-lib.sh - -test -f .git/config && rm .git/config - -git-config-set core.penguin "little blue" - -cat > expect << EOF -# -# This is the config file -# - -[core] - penguin = little blue -EOF - -test_expect_success 'initial' 'cmp .git/config expect' - -git-config-set Core.Movie BadPhysics - -cat > expect << EOF -# -# This is the config file -# - -[core] - penguin = little blue - Movie = BadPhysics -EOF - -test_expect_success 'mixed case' 'cmp .git/config expect' - -git-config-set Cores.WhatEver Second - -cat > expect << EOF -# -# This is the config file -# - -[core] - penguin = little blue - Movie = BadPhysics -[Cores] - WhatEver = Second -EOF - -test_expect_success 'similar section' 'cmp .git/config expect' - -git-config-set CORE.UPPERCASE true - -cat > expect << EOF -# -# This is the config file -# - -[core] - penguin = little blue - Movie = BadPhysics - UPPERCASE = true -[Cores] - WhatEver = Second -EOF - -test_expect_success 'similar section' 'cmp .git/config expect' - -test_expect_success 'replace with non-match' \ - 'git-config-set core.penguin kingpin !blue' - -test_expect_success 'replace with non-match (actually matching)' \ - 'git-config-set core.penguin "very blue" !kingpin' - -cat > expect << EOF -# -# This is the config file -# - -[core] - penguin = very blue - Movie = BadPhysics - UPPERCASE = true - penguin = kingpin -[Cores] - WhatEver = Second -EOF - -test_expect_success 'non-match result' 'cmp .git/config expect' - -cat > .git/config << EOF -[beta] ; silly comment # another comment -noIndent= sillyValue ; 'nother silly comment - -# empty line - ; comment - haha ="beta" # last silly comment -haha = hello - haha = bello -[nextSection] noNewline = ouch -EOF - -cp .git/config .git/config2 - -test_expect_success 'multiple unset' \ - 'git-config-set --unset-all beta.haha' - -cat > expect << EOF -[beta] ; silly comment # another comment -noIndent= sillyValue ; 'nother silly comment - -# empty line - ; comment -[nextSection] noNewline = ouch -EOF - -test_expect_success 'multiple unset is correct' 'cmp .git/config expect' - -mv .git/config2 .git/config - -test_expect_success '--replace-all' \ - 'git-config-set --replace-all beta.haha gamma' - -cat > expect << EOF -[beta] ; silly comment # another comment -noIndent= sillyValue ; 'nother silly comment - -# empty line - ; comment - haha = gamma -[nextSection] noNewline = ouch -EOF - -test_expect_success 'all replaced' 'cmp .git/config expect' - -git-config-set beta.haha alpha - -cat > expect << EOF -[beta] ; silly comment # another comment -noIndent= sillyValue ; 'nother silly comment - -# empty line - ; comment - haha = alpha -[nextSection] noNewline = ouch -EOF - -test_expect_success 'really mean test' 'cmp .git/config expect' - -git-config-set nextsection.nonewline wow - -cat > expect << EOF -[beta] ; silly comment # another comment -noIndent= sillyValue ; 'nother silly comment - -# empty line - ; comment - haha = alpha -[nextSection] - nonewline = wow -EOF - -test_expect_success 'really really mean test' 'cmp .git/config expect' - -test_expect_success 'get value' 'test alpha = $(git-config-set beta.haha)' -git-config-set --unset beta.haha - -cat > expect << EOF -[beta] ; silly comment # another comment -noIndent= sillyValue ; 'nother silly comment - -# empty line - ; comment -[nextSection] - nonewline = wow -EOF - -test_expect_success 'unset' 'cmp .git/config expect' - -git-config-set nextsection.NoNewLine "wow2 for me" "for me$" - -cat > expect << EOF -[beta] ; silly comment # another comment -noIndent= sillyValue ; 'nother silly comment - -# empty line - ; comment -[nextSection] - nonewline = wow - NoNewLine = wow2 for me -EOF - -test_expect_success 'multivar' 'cmp .git/config expect' - -test_expect_success 'non-match' \ - 'git-config-set --get nextsection.nonewline !for' - -test_expect_success 'non-match value' \ - 'test wow = $(git-config-set --get nextsection.nonewline !for)' - -test_expect_failure 'ambiguous get' \ - 'git-config-set --get nextsection.nonewline' - -test_expect_success 'get multivar' \ - 'git-config-set --get-all nextsection.nonewline' - -git-config-set nextsection.nonewline "wow3" "wow$" - -cat > expect << EOF -[beta] ; silly comment # another comment -noIndent= sillyValue ; 'nother silly comment - -# empty line - ; comment -[nextSection] - nonewline = wow3 - NoNewLine = wow2 for me -EOF - -test_expect_success 'multivar replace' 'cmp .git/config expect' - -test_expect_failure 'ambiguous value' 'git-config-set nextsection.nonewline' - -test_expect_failure 'ambiguous unset' \ - 'git-config-set --unset nextsection.nonewline' - -test_expect_failure 'invalid unset' \ - 'git-config-set --unset somesection.nonewline' - -git-config-set --unset nextsection.nonewline "wow3$" - -cat > expect << EOF -[beta] ; silly comment # another comment -noIndent= sillyValue ; 'nother silly comment - -# empty line - ; comment -[nextSection] - NoNewLine = wow2 for me -EOF - -test_expect_success 'multivar unset' 'cmp .git/config expect' - -test_expect_failure 'invalid key' 'git-config-set inval.2key blabla' - -test_expect_success 'correct key' 'git-config-set 123456.a123 987' - -test_expect_success 'hierarchical section' \ - 'git-config-set 1.2.3.alpha beta' - -cat > expect << EOF -[beta] ; silly comment # another comment -noIndent= sillyValue ; 'nother silly comment - -# empty line - ; comment -[nextSection] - NoNewLine = wow2 for me -[123456] - a123 = 987 -[1.2.3] - alpha = beta -EOF - -test_expect_success 'hierarchical section value' 'cmp .git/config expect' - -test_done - diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh new file mode 100644 index 0000000000..5e994ff009 --- /dev/null +++ b/t/t1300-repo-config.sh @@ -0,0 +1,271 @@ +#!/bin/sh +# +# Copyright (c) 2005 Johannes Schindelin +# + +test_description='Test git-repo-config in different settings' + +. ./test-lib.sh + +test -f .git/config && rm .git/config + +git-repo-config core.penguin "little blue" + +cat > expect << EOF +# +# This is the config file +# + +[core] + penguin = little blue +EOF + +test_expect_success 'initial' 'cmp .git/config expect' + +git-repo-config Core.Movie BadPhysics + +cat > expect << EOF +# +# This is the config file +# + +[core] + penguin = little blue + Movie = BadPhysics +EOF + +test_expect_success 'mixed case' 'cmp .git/config expect' + +git-repo-config Cores.WhatEver Second + +cat > expect << EOF +# +# This is the config file +# + +[core] + penguin = little blue + Movie = BadPhysics +[Cores] + WhatEver = Second +EOF + +test_expect_success 'similar section' 'cmp .git/config expect' + +git-repo-config CORE.UPPERCASE true + +cat > expect << EOF +# +# This is the config file +# + +[core] + penguin = little blue + Movie = BadPhysics + UPPERCASE = true +[Cores] + WhatEver = Second +EOF + +test_expect_success 'similar section' 'cmp .git/config expect' + +test_expect_success 'replace with non-match' \ + 'git-repo-config core.penguin kingpin !blue' + +test_expect_success 'replace with non-match (actually matching)' \ + 'git-repo-config core.penguin "very blue" !kingpin' + +cat > expect << EOF +# +# This is the config file +# + +[core] + penguin = very blue + Movie = BadPhysics + UPPERCASE = true + penguin = kingpin +[Cores] + WhatEver = Second +EOF + +test_expect_success 'non-match result' 'cmp .git/config expect' + +cat > .git/config << EOF +[beta] ; silly comment # another comment +noIndent= sillyValue ; 'nother silly comment + +# empty line + ; comment + haha ="beta" # last silly comment +haha = hello + haha = bello +[nextSection] noNewline = ouch +EOF + +cp .git/config .git/config2 + +test_expect_success 'multiple unset' \ + 'git-repo-config --unset-all beta.haha' + +cat > expect << EOF +[beta] ; silly comment # another comment +noIndent= sillyValue ; 'nother silly comment + +# empty line + ; comment +[nextSection] noNewline = ouch +EOF + +test_expect_success 'multiple unset is correct' 'cmp .git/config expect' + +mv .git/config2 .git/config + +test_expect_success '--replace-all' \ + 'git-repo-config --replace-all beta.haha gamma' + +cat > expect << EOF +[beta] ; silly comment # another comment +noIndent= sillyValue ; 'nother silly comment + +# empty line + ; comment + haha = gamma +[nextSection] noNewline = ouch +EOF + +test_expect_success 'all replaced' 'cmp .git/config expect' + +git-repo-config beta.haha alpha + +cat > expect << EOF +[beta] ; silly comment # another comment +noIndent= sillyValue ; 'nother silly comment + +# empty line + ; comment + haha = alpha +[nextSection] noNewline = ouch +EOF + +test_expect_success 'really mean test' 'cmp .git/config expect' + +git-repo-config nextsection.nonewline wow + +cat > expect << EOF +[beta] ; silly comment # another comment +noIndent= sillyValue ; 'nother silly comment + +# empty line + ; comment + haha = alpha +[nextSection] + nonewline = wow +EOF + +test_expect_success 'really really mean test' 'cmp .git/config expect' + +test_expect_success 'get value' 'test alpha = $(git-repo-config beta.haha)' +git-repo-config --unset beta.haha + +cat > expect << EOF +[beta] ; silly comment # another comment +noIndent= sillyValue ; 'nother silly comment + +# empty line + ; comment +[nextSection] + nonewline = wow +EOF + +test_expect_success 'unset' 'cmp .git/config expect' + +git-repo-config nextsection.NoNewLine "wow2 for me" "for me$" + +cat > expect << EOF +[beta] ; silly comment # another comment +noIndent= sillyValue ; 'nother silly comment + +# empty line + ; comment +[nextSection] + nonewline = wow + NoNewLine = wow2 for me +EOF + +test_expect_success 'multivar' 'cmp .git/config expect' + +test_expect_success 'non-match' \ + 'git-repo-config --get nextsection.nonewline !for' + +test_expect_success 'non-match value' \ + 'test wow = $(git-repo-config --get nextsection.nonewline !for)' + +test_expect_failure 'ambiguous get' \ + 'git-repo-config --get nextsection.nonewline' + +test_expect_success 'get multivar' \ + 'git-repo-config --get-all nextsection.nonewline' + +git-repo-config nextsection.nonewline "wow3" "wow$" + +cat > expect << EOF +[beta] ; silly comment # another comment +noIndent= sillyValue ; 'nother silly comment + +# empty line + ; comment +[nextSection] + nonewline = wow3 + NoNewLine = wow2 for me +EOF + +test_expect_success 'multivar replace' 'cmp .git/config expect' + +test_expect_failure 'ambiguous value' 'git-repo-config nextsection.nonewline' + +test_expect_failure 'ambiguous unset' \ + 'git-repo-config --unset nextsection.nonewline' + +test_expect_failure 'invalid unset' \ + 'git-repo-config --unset somesection.nonewline' + +git-repo-config --unset nextsection.nonewline "wow3$" + +cat > expect << EOF +[beta] ; silly comment # another comment +noIndent= sillyValue ; 'nother silly comment + +# empty line + ; comment +[nextSection] + NoNewLine = wow2 for me +EOF + +test_expect_success 'multivar unset' 'cmp .git/config expect' + +test_expect_failure 'invalid key' 'git-repo-config inval.2key blabla' + +test_expect_success 'correct key' 'git-repo-config 123456.a123 987' + +test_expect_success 'hierarchical section' \ + 'git-repo-config 1.2.3.alpha beta' + +cat > expect << EOF +[beta] ; silly comment # another comment +noIndent= sillyValue ; 'nother silly comment + +# empty line + ; comment +[nextSection] + NoNewLine = wow2 for me +[123456] + a123 = 987 +[1.2.3] + alpha = beta +EOF + +test_expect_success 'hierarchical section value' 'cmp .git/config expect' + +test_done +