documentation: use the word "index" in the git-add manual page
[gitweb.git] / builtin-config.c
index 0f9051da17c6e399709bd476ab867f4505ecba63..dbc2339d0f98d561e0263354321a5f2566f9918a 100644 (file)
@@ -2,7 +2,7 @@
 #include "cache.h"
 
 static const char git_config_set_usage[] =
-"git-config [ --global ] [ --bool | --int ] [--get | --get-all | --get-regexp | --replace-all | --add | --unset | --unset-all] name [value [value_regex]] | --rename-section old_name new_name | --list";
+"git-config [ --global | --system ] [ --bool | --int ] [--get | --get-all | --get-regexp | --replace-all | --add | --unset | --unset-all] name [value [value_regex]] | --rename-section old_name new_name | --remove-section name | --list";
 
 static char *key;
 static regex_t *key_regexp;
@@ -38,8 +38,12 @@ static int show_config(const char* key_, const char* value_)
                          regexec(regexp, (value_?value_:""), 0, NULL, 0)))
                return 0;
 
-       if (show_keys)
-               printf("%s ", key_);
+       if (show_keys) {
+               if (value_)
+                       printf("%s ", key_);
+               else
+                       printf("%s", key_);
+       }
        if (seen && !do_all)
                dup_error = 1;
        if (type == T_INT)
@@ -64,7 +68,7 @@ static int get_value(const char* key_, const char* regex_)
        int ret = -1;
        char *tl;
        char *global = NULL, *repo_config = NULL;
-       const char *local;
+       const char *system_wide = NULL, *local;
 
        local = getenv(CONFIG_ENVIRONMENT);
        if (!local) {
@@ -74,6 +78,7 @@ static int get_value(const char* key_, const char* regex_)
                        local = repo_config = xstrdup(git_path("config"));
                if (home)
                        global = xstrdup(mkpath("%s/.gitconfig", home));
+               system_wide = ETC_GITCONFIG;
        }
 
        key = xstrdup(key_);
@@ -103,11 +108,15 @@ static int get_value(const char* key_, const char* regex_)
                }
        }
 
+       if (do_all && system_wide)
+               git_config_from_file(show_config, system_wide);
        if (do_all && global)
                git_config_from_file(show_config, global);
        git_config_from_file(show_config, local);
        if (!do_all && !seen && global)
                git_config_from_file(show_config, global);
+       if (!do_all && !seen && system_wide)
+               git_config_from_file(show_config, system_wide);
 
        free(key);
        if (regexp) {
@@ -147,7 +156,10 @@ int cmd_config(int argc, const char **argv, const char *prefix)
                        } else {
                                die("$HOME not set");
                        }
-               } else if (!strcmp(argv[1], "--rename-section")) {
+               }
+               else if (!strcmp(argv[1], "--system"))
+                       setenv("GIT_CONFIG", ETC_GITCONFIG, 1);
+               else if (!strcmp(argv[1], "--rename-section")) {
                        int ret;
                        if (argc != 4)
                                usage(git_config_set_usage);
@@ -159,7 +171,21 @@ int cmd_config(int argc, const char **argv, const char *prefix)
                                return 1;
                        }
                        return 0;
-               } else
+               }
+               else if (!strcmp(argv[1], "--remove-section")) {
+                       int ret;
+                       if (argc != 3)
+                               usage(git_config_set_usage);
+                       ret = git_config_rename_section(argv[2], NULL);
+                       if (ret < 0)
+                               return ret;
+                       if (ret == 0) {
+                               fprintf(stderr, "No such section!\n");
+                               return 1;
+                       }
+                       return 0;
+               }
+               else
                        break;
                argc--;
                argv++;