summaryrefslogtreecommitdiff
path: root/t/t1300-repo-config.sh
AgeCommit message (Collapse)AuthorFilesLines
2014-09-09Merge branch 'jk/command-line-config-empty-string'Libravatar Junio C Hamano1-0/+11
"git -c section.var command" and "git -c section.var= command" should pass the configuration differently (the former should be a boolean true, the latter should be an empty string). * jk/command-line-config-empty-string: config: teach "git -c" to recognize an empty string
2014-08-05config: teach "git -c" to recognize an empty stringLibravatar Junio C Hamano1-0/+11
In a config file, you can do: [foo] bar to turn the "foo.bar" boolean flag on, and you can do: [foo] bar= to set "foo.bar" to the empty string. However, git's "-c" parameter treats both: git -c foo.bar and git -c foo.bar= as the boolean flag, and there is no way to set a variable to the empty string. This patch enables the latter form to do that. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-07-21test prerequisites: eradicate NOT_FOOLibravatar Junio C Hamano1-3/+3
Support for Back when bdccd3c1 (test-lib: allow negation of prerequisites, 2012-11-14) introduced negated predicates (e.g. "!MINGW,!CYGWIN"), we already had 5 test files that use NOT_MINGW (and a few MINGW) as prerequisites. Let's not add NOT_FOO and rewrite existing ones as !FOO for both MINGW and CYGWIN. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-06-03Merge branch 'ew/config-protect-mode'Libravatar Junio C Hamano1-0/+10
* ew/config-protect-mode: config: preserve config file permissions on edits
2014-05-06config: preserve config file permissions on editsLibravatar Eric Wong1-0/+10
Users may already store sensitive data such as imap.pass in .git/config; making the file world-readable when "git config" is called to edit means their password would be compromised on a shared system. [v2: updated for section renames, as noted by Junio] Signed-off-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-03-31Merge branch 'jk/tests-cleanup'Libravatar Junio C Hamano1-14/+14
* jk/tests-cleanup: t0001: drop subshells just for "cd" t0001: drop useless subshells t0001: use test_must_fail t0001: use test_config_global t0001: use test_path_is_* t0001: make symlink reinit test more careful t: prefer "git config --file" to GIT_CONFIG t: prefer "git config --file" to GIT_CONFIG with test_must_fail t: stop using GIT_CONFIG to cross repo boundaries t: drop useless sane_unset GIT_* calls t/test-lib: drop redundant unset of GIT_CONFIG t/Makefile: stop setting GIT_CONFIG
2014-03-31Merge branch 'dt/tests-with-env-not-subshell'Libravatar Junio C Hamano1-13/+4
* dt/tests-with-env-not-subshell: tests: use "env" to run commands with temporary env-var settings
2014-03-21t: prefer "git config --file" to GIT_CONFIGLibravatar Jeff King1-10/+10
Doing: GIT_CONFIG=foo git config ... is equivalent to: git config --file=foo ... The latter is easier to read and slightly less error-prone, because of issues with one-shot variables and shell functions (e.g., you cannot use the former with test_must_fail). Note that we explicitly leave one case in t1300 which checks the same operation on both GIT_CONFIG and "git config --file". They are equivalent in the code these days, but this will make sure it remains so. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-03-21t: prefer "git config --file" to GIT_CONFIG with test_must_failLibravatar Jeff King1-4/+4
This lets us get rid of an extra "env" invocation in the middle, and is slightly more readable. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-03-19tests: use "env" to run commands with temporary env-var settingsLibravatar David Tran1-13/+4
Ordinarily, we would say "VAR=VAL command" to execute a tested command with environment variable(s) set only for that command. This however does not work if 'command' is a shell function (most notably 'test_must_fail'); the result of the assignment is retained and affects later commands. To avoid this, we used to assign and export environment variables and run such a test in a subshell, like so: ( VAR=VAL && export VAR && test_must_fail git command to be tested ) But with "env" utility, we should be able to say: test_must_fail env VAR=VAL git command to be tested which is much shorter and easier to read. Signed-off-by: David Tran <unsignedzero@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-02-18config: teach "git config --file -" to read from the standard inputLibravatar Kirill A. Shutemov1-2/+15
The patch extends git config --file interface to allow read config from stdin. Editing stdin or setting value in stdin is an error. Include by absolute path is allowed in stdin config, but not by relative path. Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-09-12Merge branch 'jk/config-int-range-check'Libravatar Junio C Hamano1-3/+10
"git config" did not provide a way to set or access numbers larger than a native "int" on the platform; it now provides 64-bit signed integers on all platforms. * jk/config-int-range-check: git-config: always treat --int as 64-bit internally config: make numeric parsing errors more clear config: set errno in numeric git_parse_* functions config: properly range-check integer values config: factor out integer parsing from range checks
2013-09-09git-config: always treat --int as 64-bit internallyLibravatar Jeff King1-0/+7
When you run "git config --int", the maximum size of integer you get depends on how git was compiled, and what it considers to be an "int". This is almost useful, because your scripts calling "git config" will behave similarly to git internally. But relying on this is dubious; you have to actually know how git treats each value internally (e.g., int versus unsigned long), which is not documented and is subject to change. And even if you know it is "unsigned long", we do not have a git-config option to match that behavior. Furthermore, you may simply be asking git to store a value on your behalf (e.g., configuration for a hook). In that case, the relevant range check has nothing at all to do with git, but rather with whatever scripting tools you are using (and git has no way of knowing what the appropriate range is there). Not only is the range check useless, but it is actively harmful, as there is no way at all for scripts to look at config variables with large values. For instance, one cannot reliably get the value of pack.packSizeLimit via git-config. On an LP64 system, git happily uses a 64-bit "unsigned long" internally to represent the value, but the script cannot read any value over 2G. Ideally, the "--int" option would simply represent an arbitrarily large integer. For practical purposes, however, a 64-bit integer is large enough, and is much easier to implement (and if somebody overflows it, we will still notice the problem, and not simply return garbage). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-09-09config: make numeric parsing errors more clearLibravatar Jeff King1-3/+3
If we try to parse an integer config argument and get a number outside of the representable range, we die with the cryptic message: "bad config value for '%s'". We can improve two things: 1. Show the value that produced the error (e.g., bad config value '3g' for 'foo.bar'). 2. Mention the reason the value was rejected (e.g., "invalid unit" versus "out of range"). A few tests need to be updated with the new output, but that should not be representative of real-world breakage, as scripts should not be depending on the exact text of our stderr output, which is subject to i18n anyway. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-08-05config: "git config --get-urlmatch" parses section.<url>.keyLibravatar Junio C Hamano1-0/+25
Using the same urlmatch_config_entry() infrastructure, add a new mode "--get-urlmatch" to the "git config" command, to learn values for the "virtual" two-level variables customized for the specific URL. git config [--<type>] --get-urlmatch <section>[.<key>] <url> With <section>.<key> fully specified, the configuration data for <section>.<urlpattern>.<key> for <urlpattern> that best matches the given <url> is sought (and if not found, <section>.<key> is used) and reported. For example, with this configuration: [http] sslVerify [http "https://weak.example.com"] cookieFile = /tmp/cookie.txt sslVerify = false You would get $ git config --bool --get-urlmatch http.sslVerify https://good.example.com true $ git config --bool --get-urlmatch http.sslVerify https://weak.example.com false With only <section> specified, you can get a list of all variables in the section with their values that apply to the given URL. E.g $ git config --get-urlmatch http https://weak.example.com http.cookiefile /tmp/cookie.txt http.sslverify false Helped-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-03-29t1300: document some aesthetic failures of the config editorLibravatar Jeff King1-0/+35
The config-editing code used by "git config var value" is built around the regular config callback parser, whose only triggerable item is an actual key. As a result, it does not know anything about section headers, which can result in unnecessarily ugly output: 1. When we delete the last key in a section, we should be able to delete the section header. 2. When we add a key into a section, we should be able to reuse the same section header, even if that section did not have any keys in it already. Unfortunately, fixing these is not trivial with the current code. It would involve the config parser recording and passing back information on each item it finds, including headers, keys, and even comments (or even better, generating an actual in-memory parse-tree). Since these behaviors do not cause any functional problems (i.e., the resulting config parses as expected, it is just uglier than one would like), fixing them can wait until somebody feels like substantially refactoring the parsing code. In the meantime, let's document them as known issues with some tests. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-11-21Merge branch 'jk/config-ignore-duplicates'Libravatar Junio C Hamano1-129/+187
Drop duplicate detection from "git-config --get"; this lets it better match the internal config callbacks, which clears up some corner cases with includes. * jk/config-ignore-duplicates: builtin/config.c: Fix a sparse warning git-config: use git_config_with_options git-config: do not complain about duplicate entries git-config: collect values instead of immediately printing git-config: fix regexp memory leaks on error conditions git-config: remove memory leak of key regexp t1300: test "git config --get-all" more thoroughly t1300: remove redundant test t1300: style updates
2012-11-20Merge branch 'cn/config-missing-path'Libravatar Junio C Hamano1-0/+5
"git config --path $key" segfaulted on "[section] key" (a boolean "true" spelled without "=", not "[section] key = true"). * cn/config-missing-path: config: don't segfault when given --path with a missing value
2012-11-15config: don't segfault when given --path with a missing valueLibravatar Carlos Martín Nieto1-0/+5
When given a variable without a value, such as '[section] var' and asking git-config to treat it as a path, git_config_pathname returns an error and doesn't modify its output parameter. show_config assumes that the call is always successful and sets a variable to indicate that vptr should be freed. In case of an error however, trying to do this will cause the program to be killed, as it's pointing to memory in the stack. Detect the error and return immediately to avoid freeing or accessing the uninitialed memory in the stack. Signed-off-by: Carlos Martín Nieto <cmn@elego.de> Acked-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-10-24git-config: do not complain about duplicate entriesLibravatar Jeff King1-2/+4
If git-config is asked for a single value, it will complain and exit with an error if it finds multiple instances of that value. This is unlike the usual internal config parsing, however, which will generally overwrite previous values, leaving only the final one. For example: [set a multivar] $ git config user.email one@example.com $ git config --add user.email two@example.com [use the internal parser to fetch it] $ git var GIT_AUTHOR_IDENT Your Name <two@example.com> ... [use git-config to fetch it] $ git config user.email one@example.com error: More than one value for the key user.email: two@example.com This overwriting behavior is critical for the regular parser, which starts with the lowest-priority file (e.g., /etc/gitconfig) and proceeds to the highest-priority file ($GIT_DIR/config). Overwriting yields the highest priority value at the end. Git-config solves this problem by implementing its own parsing. It goes from highest to lowest priorty, but does not proceed to the next file if it has seen a value. So in practice, this distinction never mattered much, because it only triggered for values in the same file. And there was not much point in doing that; the real value is in overwriting values from lower-priority files. However, this changed with the implementation of config include files. Now we might see an include overriding a value from the parent file, which is a sensible thing to do, but git-config will flag as a duplication. This patch drops the duplicate detection for git-config and switches to a pure-overwrite model (for the single case; --get-all can still be used if callers want to do something more fancy). As is shown by the modifications to the test suite, this is a user-visible change in behavior. An alternative would be to just change the include case, but this is much cleaner for a few reasons: 1. If you change the include case, then to what? If you just stop parsing includes after getting a value, then you will get a _different_ answer than the regular config parser (you'll get the first value instead of the last value). So you'd want to implement overwrite semantics anyway. 2. Even though it is a change in behavior for git-config, it is bringing us in line with what the internal parsers already do. 3. The file-order reimplementation is the only thing keeping us from sharing more code with the internal config parser, which will help keep differences to a minimum. Going under the assumption that the primary purpose of git-config is to behave identically to how git's internal parsing works, this change can be seen as a bug-fix. Signed-off-by: Jeff King <peff@peff.net>
2012-10-24t1300: test "git config --get-all" more thoroughlyLibravatar Jeff King1-2/+7
We check that we can "--get-all" a multi-valued variable, but we do not actually confirm that the output is sensible. Doing so reveals that it works fine, but this will help us ensure we do not have regressions in the next few patches, which will touch this area. Signed-off-by: Jeff King <peff@peff.net>
2012-10-24t1300: remove redundant testLibravatar Jeff King1-4/+0
This test checks that git-config fails for an ambiguous "get", but we check the exact same thing 3 tests beforehand. Signed-off-by: Jeff King <peff@peff.net>
2012-10-24t1300: style updatesLibravatar Jeff King1-123/+178
The t1300 test script is quite old, and does not use our modern techniques or styles. This patch updates it in the following ways: 1. Use test_cmp instead of cmp (to make failures easier to debug). 2. Use test_cmp instead of 'test $(command) = expected'. This makes failures much easier to debug, and also makes sure that $(command) exits appropriately. 3. Use test_must_fail (easier to read, and checks more rigorously for signal death). 4. Write tests with the usual style of: test_expect_success 'test name' ' test commands && ... ' rather than one-liners, or using backslash-continuation. This is purely a style fixup. There are still a few command happening outside of test_expect invocations, but they are all innoccuous system commands like "cat" and "cp". In an ideal world, each test would be self sufficient and all commands would happen inside test_expect, but it is not immediately obvious how the grouping should work (some of the commands impact the subsequent tests, and some of them are setting up and modifying state that many tests depend on). This patch just picks the low-hanging style fruit, and we can do more fixes on top later. Signed-off-by: Jeff King <peff@peff.net>
2012-08-27Fix tests under GETTEXT_POISON on parseoptLibravatar Jiang Xin1-1/+1
Use the i18n-specific test functions in test scripts for parseopt tests. This issue was was introduced in v1.7.10.1-488-g54e6d: 54e6d i18n: parseopt: lookup help and argument translations when showing usage and been broken under GETTEXT_POISON=YesPlease since. Signed-off-by: Jiang Xin <worldhello.net@gmail.com> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-04-25config: reject bogus section names for --rename-sectionLibravatar Jeff King1-0/+8
You can feed junk to "git config --rename-section", which will result in a config file that git will not even parse (so you cannot fix it with git-config). We already have syntactic sanity checks when setting a variable; let's do the same for section names. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-03-13Merge branch 'ms/maint-config-error-at-eol-linecount'Libravatar Junio C Hamano1-0/+31
When "git config" diagnoses an error in a configuration file and shows the line number for the offending line, it miscounted if the error was at the end of line. By Martin Stenberg * ms/maint-config-error-at-eol-linecount: config: report errors at the EOL with correct line number Conflicts: t/t1300-repo-config.sh
2012-03-12config: report errors at the EOL with correct line numberLibravatar Martin Stenberg1-0/+31
A section in a config file with a missing "]" reports the next line as bad, same goes to a value with a missing end quote. This happens because the error is not detected until the end of the line, when line number is already increased. Fix this by decreasing line number by one for these cases. Signed-off-by: Martin Stenberg <martin@gnutiken.se> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-02-17config: stop using config_exclusive_filenameLibravatar Jeff King1-0/+25
The git-config command sometimes operates on the default set of config files (either reading from all, or writing to repo config), and sometimes operates on a specific file. In the latter case, we set the magic global config_exclusive_filename, and the code in config.c does the right thing. Instead, let's have git-config use the "advanced" variants of config.c's functions which let it specify an individual filename (or NULL for the default). This makes the code a lot more obvious, and fixes two small bugs: 1. A relative path specified by GIT_CONFIG=foo will look in the wrong directory if we have to chdir as part of repository setup. We already handle this properly for "git config -f foo", but the GIT_CONFIG lookup used config_exclusive_filename directly. By dropping to a single magic variable, the GIT_CONFIG case now just works. 2. Calling "git config -f foo --edit" would not respect core.editor. This is because just before editing, we called git_config, which would respect the config_exclusive_filename setting, even though this particular git_config call was not about looking in the user's specified file, but rather about loading actual git config, just as any other git program would. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-02-17t1300: add missing &&-chainingLibravatar Jeff King1-1/+1
Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-12-08test: fix '&&' chainingLibravatar Ramkumar Ramachandra1-1/+1
Breaks in a test assertion's && chain can potentially hide failures from earlier commands in the chain by adding " &&" at the end of line to the commands that need them. Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com> Acked-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-10-21Merge branch 'mm/maint-config-explicit-bool-display' into maintLibravatar Junio C Hamano1-0/+6
* mm/maint-config-explicit-bool-display: config: display key_delim for config --bool --get-regexp
2011-10-19Merge branch 'jk/config-test-cleanup'Libravatar Junio C Hamano1-12/+7
* jk/config-test-cleanup: t1300: attempting to remove a non-existent .git/config is not an error
2011-10-19t1300: attempting to remove a non-existent .git/config is not an errorLibravatar Johannes Sixt1-12/+7
Since some tests before test number 79 ("quoting") are skipped, .git/config does not exist and 'rm .git/config' fails. Fix this particular case. While at it, move other instance of 'rm .git/config' that occur in this file inside the test function to document that the test cases want to protect themselves from remnants of earlier tests. Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-10-17Merge branch 'jk/config-test-cleanup'Libravatar Junio C Hamano1-83/+120
* jk/config-test-cleanup: t1300: test mixed-case variable retrieval t1300: put git invocations inside test function
2011-10-17Merge branch 'mm/maint-config-explicit-bool-display'Libravatar Junio C Hamano1-0/+6
* mm/maint-config-explicit-bool-display: config: display key_delim for config --bool --get-regexp
2011-10-12t1300: test mixed-case variable retrievalLibravatar Jeff King1-0/+27
We should be able to ask for a config value both by its canonical all-lowercase name (as git does internally), as well as by random mixed-case (which will be canonicalized by git-config for us). Subsections are a tricky point, though. Since we have both [section "Foo"] and [section.Foo] you might want git-config to canonicalize the subsection or not, depending on which you are expecting. But there's no way to communicate this; git-config sees only the key, and doesn't know which type of section name will be in the config file. So it must leave the subsection intact, and it is up to the caller to provide a canonical version of the subsection if they want to match the latter form. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-10-12t1300: put git invocations inside test functionLibravatar Jeff King1-83/+93
This is a very old script, and did a lot of: echo whatever >expect git config foo bar test_expect_success 'cmp .git/config expect' which meant that we didn't actually check that the call to git-config succeeded. Fix this, and while we're at it, modernize the style to use test_cmp. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-10-10config: display key_delim for config --bool --get-regexpLibravatar Matthieu Moy1-0/+6
The previous logic in show_config was to print the delimiter when the value was set, but Boolean variables have an implicit value "true" when they appear with no value in the config file. As a result, we got: git_Config --get-regexp '.*\.Boolean' #1. Ok: example.boolean git_Config --bool --get-regexp '.*\.Boolean' #2. NO: example.booleantrue Fix this by defering the display of the separator until after the value to display has been computed. Reported-by: Brian Foster <brian.foster@maxim-ic.com> Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-06-22config: avoid segfault when parsing command-line configLibravatar Jeff King1-0/+4
We already check for an empty key on the left side of an equals, but we would segfault if there was no content at all. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-06-22config: die on error in command-line configLibravatar Jeff King1-0/+8
The error handling for git_config is somewhat confusing. We collect errors from running git_config_from_file on the various config files and carefully pass them back up. But the two odd things are: 1. We actually die on most errors in git_config_from_file. In fact, the only error we actually pass back up is if fopen() fails on the file. 2. Most callers of git_config do not check the error return at all, but will continue if git_config reports an error. When the code for "git -c core.foo=bar" was added, it dutifully passed errors up the call stack, only for them to be eventually ignored. This makes it inconsistent with the file-parsing code, which will die when it sees malformed config. And it's somewhat unsafe, because it means an error in parsing a typo like: git -c clean.requireforce=ture clean will continue the command, ignoring the config the user tried to give. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-06-22fix "git -c" parsing of values with equals signsLibravatar Jeff King1-0/+6
If you do something like: git -c core.foo="value with = in it" ... we would split your option on "=" into three fields and throw away the third one. With this patch we correctly take everything after the first "=" as the value (keys cannot have an equals sign in them, so the parsing is unambiguous). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-06-01Merge branch 'jk/maint-config-alias-fix' into maintLibravatar Junio C Hamano1-0/+7
* jk/maint-config-alias-fix: handle_options(): do not miscount how many arguments were used config: always parse GIT_CONFIG_PARAMETERS during git_config git_config: don't peek at global config_parameters config: make environment parsing routines static
2011-05-24handle_options(): do not miscount how many arguments were usedLibravatar Junio C Hamano1-1/+1
The handle_options() function advances the base of the argument array and returns the number of arguments it used. The caller in handle_alias() wants to reallocate the argv array it passes to this function, and attempts to do so by subtracting the returned value to compensate for the change handle_options() makes to the new_argv. But handle_options() did not correctly count when "-c <config=value>" is given, causing a wrong pointer to be passed to realloc(). Fix it by saving the original argv at the beginning of handle_options(), and return the difference between the final value of argv, which will relieve the places that move the array pointer from the additional burden of keeping track of "handled" counter. Noticed-by: Kazuki Tsujimoto Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-05-24config: always parse GIT_CONFIG_PARAMETERS during git_configLibravatar Jeff King1-0/+7
Previously we parsed GIT_CONFIG_PARAMETERS lazily into a linked list, and then checked that list during future invocations of git_config. However, that ignores the fact that the environment variable could change during our run (e.g., because we parse more "-c" as part of an alias). Instead, let's just re-parse the environment variable each time. It's generally not very big, and it's no more work than parsing the config files, anyway. As a bonus, we can ditch all of the linked list storage code entirely, making the code much simpler. The test unfortunately still does not pass because of an unrelated bug in handle_options. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-02-22Disallow empty section and variable namesLibravatar Libor Pechacek1-0/+4
It is possible to break your repository config by creating an invalid key. The config parser in turn chokes on it: $ git init Initialized empty Git repository in /tmp/gittest/.git/ $ git config .foo false $ git config core.bare fatal: bad config file line 6 in .git/config This patch makes git-config reject keys which start or end with a dot and adds tests for these cases. Signed-off-by: Libor Pechacek <lpechacek@suse.cz> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-02-22Sanity-check config variable namesLibravatar Libor Pechacek1-4/+14
Sanity-check config variable names when adding and retrieving them. As a side effect code duplication between git_config_set_multivar and get_value (in builtin/config.c) was removed and the common functionality was placed in git_config_parse_key. This breaks a test in t1300 which used invalid section-less keys in the tests for "git -c". However, allowing such names there was useless, since there was no way to set them via config file, and no part of git actually tried to use section-less keys. This patch updates the test to use more realistic examples as well as adding its own test. Signed-off-by: Libor Pechacek <lpechacek@suse.cz> Acked-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-10-21config: treat non-existent config files as emptyLibravatar Jeff King1-0/+29
The git_config() function signals error by returning -1 in two instances: 1. An actual error occurs in opening a config file (parse errors cause an immediate die). 2. Of the three possible config files, none was found. However, this second case is often not an error at all; it simply means that the user has no configuration (they are outside a repo, and they have no ~/.gitconfig file). This can lead to confusing errors, such as when the bash completion calls "git config --list" outside of a repo. If the user has a ~/.gitconfig, the command completes succesfully; if they do not, it complains to stderr. This patch allows callers of git_config to distinguish between the two cases. Error is signaled by -1, and otherwise the return value is the number of files parsed. This means that the traditional "git_config(...) < 0" check for error should work, but callers who want to know whether we parsed any files or not can still do so. [jc: with tests from Jonathan] Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-10-01Skip t1300.70 and 71 on msysGit.Libravatar Pat Thoyts1-3/+3
These two tests fail on msysGit because /dev/null is an alias for nul on Windows and when reading the value back from git config the alias does not match the real filename. Also the HOME environment variable has a unix-style path but git returns a native equivalent path for '~'. As these are platform-dependent equivalent results it seems simplest to skip the test entirely. Moves the NOT_MINGW prereq from t5503 into the test library. Signed-off-by: Pat Thoyts <patthoyts@users.sourceforge.net>
2010-07-27Sync with 1.7.1.2Libravatar Junio C Hamano1-1/+23
2010-07-27config --get --path: check for unset $HOMELibravatar Jonathan Nieder1-1/+23
If $HOME is unset (as in some automated build situations), currently git config --path path.home "~" git config --path --get path.home segfaults. Error out with Failed to expand user dir in: '~/' instead. Reported-by: Julien Cristau <jcristau@debian.org> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>