Merge branch 'fc/parseopt-config'
authorJunio C Hamano <gitster@pobox.com>
Fri, 20 Mar 2009 21:29:03 +0000 (14:29 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 20 Mar 2009 21:29:03 +0000 (14:29 -0700)
* fc/parseopt-config:
config: test for --replace-all with one argument and fix documentation.
config: set help text for --bool-or-int
git config: don't allow --get-color* and variable type
git config: don't allow extra arguments for -e or -l.
git config: don't allow multiple variable types
git config: don't allow multiple config file locations
git config: reorganize to use parseopt
git config: reorganize get_color*
git config: trivial rename in preparation for parseopt
git_config(): not having a per-repo config file is not an error

1  2 
Documentation/git-config.txt
config.c
t/t1300-repo-config.sh
index 82ce89eae849e5a1c697a3c7f659a80521600348,8b94f19b170ba86cf44b91a5be4ceae7888b1fa7..7131ee3c66951de5981a82e304f4619de88064c5
@@@ -11,7 -11,7 +11,7 @@@ SYNOPSI
  [verse]
  'git config' [<file-option>] [type] [-z|--null] name [value [value_regex]]
  'git config' [<file-option>] [type] --add name value
- 'git config' [<file-option>] [type] --replace-all name [value [value_regex]]
+ 'git config' [<file-option>] [type] --replace-all name value [value_regex]
  'git config' [<file-option>] [type] [-z|--null] --get name [value_regex]
  'git config' [<file-option>] [type] [-z|--null] --get-all name [value_regex]
  'git config' [<file-option>] [type] [-z|--null] --get-regexp name_regex [value_regex]
@@@ -131,10 -131,6 +131,10 @@@ See also <<FILES>>
        in the config file will cause the value to be multiplied
        by 1024, 1048576, or 1073741824 prior to output.
  
 +--bool-or-int::
 +      'git-config' will ensure that the output matches the format of
 +      either --bool or --int, as described above.
 +
  -z::
  --null::
        For all options that output values and/or keys, always
diff --combined config.c
index 0c8c76f13b03028ad400b1c5b72b3cf0a7ec0940,b4aae71bd3e682744645ba1ffa26d3b0dd49f8e0..50efd639c4d68af1428a8a45606ae4897a8d2dd9
+++ b/config.c
@@@ -469,6 -469,11 +469,6 @@@ static int git_default_core_config(cons
                return 0;
        }
  
 -      if (!strcmp(var, "core.notesref")) {
 -              notes_ref_name = xstrdup(value);
 -              return 0;
 -      }
 -
        if (!strcmp(var, "core.pager"))
                return git_config_string(&pager_program, var, value);
  
@@@ -565,15 -570,6 +565,15 @@@ static int git_default_branch_config(co
        return 0;
  }
  
 +static int git_default_mailmap_config(const char *var, const char *value)
 +{
 +      if (!strcmp(var, "mailmap.file"))
 +              return git_config_string(&git_mailmap_file, var, value);
 +
 +      /* Add other config variables here and to Documentation/config.txt. */
 +      return 0;
 +}
 +
  int git_default_config(const char *var, const char *value, void *dummy)
  {
        if (!prefixcmp(var, "core."))
        if (!prefixcmp(var, "branch."))
                return git_default_branch_config(var, value);
  
 +      if (!prefixcmp(var, "mailmap."))
 +              return git_default_mailmap_config(var, value);
 +
        if (!strcmp(var, "pager.color") || !strcmp(var, "color.pager")) {
                pager_use_color = git_config_bool(var,value);
                return 0;
@@@ -644,28 -637,37 +644,37 @@@ int git_config_global(void
  
  int git_config(config_fn_t fn, void *data)
  {
-       int ret = 0;
+       int ret = 0, found = 0;
        char *repo_config = NULL;
        const char *home = NULL;
  
        /* Setting $GIT_CONFIG makes git read _only_ the given config file. */
        if (config_exclusive_filename)
                return git_config_from_file(fn, config_exclusive_filename, data);
-       if (git_config_system() && !access(git_etc_gitconfig(), R_OK))
+       if (git_config_system() && !access(git_etc_gitconfig(), R_OK)) {
                ret += git_config_from_file(fn, git_etc_gitconfig(),
                                            data);
+               found += 1;
+       }
  
        home = getenv("HOME");
        if (git_config_global() && home) {
                char *user_config = xstrdup(mkpath("%s/.gitconfig", home));
-               if (!access(user_config, R_OK))
+               if (!access(user_config, R_OK)) {
                        ret += git_config_from_file(fn, user_config, data);
+                       found += 1;
+               }
                free(user_config);
        }
  
        repo_config = git_pathdup("config");
-       ret += git_config_from_file(fn, repo_config, data);
+       if (!access(repo_config, R_OK)) {
+               ret += git_config_from_file(fn, repo_config, data);
+               found += 1;
+       }
        free(repo_config);
+       if (found == 0)
+               return -1;
        return ret;
  }
  
diff --combined t/t1300-repo-config.sh
index 3c06842d99a68ea37ce82546b4bfa0cd487b87d7,f0a75380b3fbb82b78f42b8ea7c24e9e8af2a24f..9c81e041b9f688ebeffacce06b3ff94e153bb9b2
@@@ -118,7 -118,14 +118,14 @@@ EO
  
  test_expect_success 'multiple unset is correct' 'cmp .git/config expect'
  
- mv .git/config2 .git/config
+ cp .git/config2 .git/config
+ test_expect_success '--replace-all missing value' '
+       test_must_fail git config --replace-all beta.haha &&
+       test_cmp .git/config2 .git/config
+ '
+ rm .git/config2
  
  test_expect_success '--replace-all' \
        'git config --replace-all beta.haha gamma'
@@@ -336,10 -343,10 +343,10 @@@ test_expect_success 'get bool variable 
        'git config --bool emptyvalue.variable > output &&
         cmp output expect'
  
 -git config > output 2>&1
 -
 -test_expect_success 'no arguments, but no crash' \
 -      "test $? = 129 && grep usage output"
 +test_expect_success 'no arguments, but no crash' '
 +      test_must_fail git config >output 2>&1 &&
 +      grep usage output
 +'
  
  cat > .git/config << EOF
  [a.b]
@@@ -373,7 -380,7 +380,7 @@@ EO
  test_expect_success 'new variable inserts into proper section' 'cmp .git/config expect'
  
  test_expect_success 'alternative GIT_CONFIG (non-existing file should fail)' \
 -      'git config --file non-existing-config -l; test $? != 0'
 +      'test_must_fail git config --file non-existing-config -l'
  
  cat > other-config << EOF
  [ein]