@matheusbsbs / matheus-bagliano / commits / 34eb33407d
Fork 0

Add --global option to git-repo-config.

Allow user to set variables in global ~/.gitconfig file using command line. Signed-off-by: Sean Estabrooks <seanlkml@sympatico.ca> Signed-off-by: Junio C Hamano <junkio@cox.net>

Sean committed Nov 2, 2006 at 10:44 UTC 34eb33407d4d7eef6d7ddcd6e51525018ef9edf7
2 files changed +29 -15
Documentation/git-repo-config.txt
+18 -13
@@ -3,19 +3,19 @@ git-repo-config(1)
3
4 NAME
5 ----
6 -git-repo-config - Get and set options in .git/config
6 +git-repo-config - Get and set repository or global options.
7
8
9 SYNOPSIS
10 --------
11 [verse]
12 -'git-repo-config' [type] name [value [value_regex]]
13 -'git-repo-config' [type] --replace-all name [value [value_regex]]
14 -'git-repo-config' [type] --get name [value_regex]
15 -'git-repo-config' [type] --get-all name [value_regex]
16 -'git-repo-config' [type] --unset name [value_regex]
17 -'git-repo-config' [type] --unset-all name [value_regex]
18 -'git-repo-config' -l | --list
12 +'git-repo-config' [--global] [type] name [value [value_regex]]
13 +'git-repo-config' [--global] [type] --replace-all name [value [value_regex]]
14 +'git-repo-config' [--global] [type] --get name [value_regex]
15 +'git-repo-config' [--global] [type] --get-all name [value_regex]
16 +'git-repo-config' [--global] [type] --unset name [value_regex]
17 +'git-repo-config' [--global] [type] --unset-all name [value_regex]
18 +'git-repo-config' [--global] -l | --list
19
20 DESCRIPTION
21 -----------
@@ -41,8 +41,9 @@ This command will fail if:
41 . Can not write to .git/config,
42 . no section was provided,
43 . the section or key is invalid,
44 -. you try to unset an option which does not exist, or
45 -. you try to unset/set an option for which multiple lines match.
44 +. you try to unset an option which does not exist,
45 +. you try to unset/set an option for which multiple lines match, or
46 +. you use --global option without $HOME being properly set.
47
48
49 OPTIONS
@@ -64,14 +65,17 @@ OPTIONS
65 --get-regexp::
66 Like --get-all, but interprets the name as a regular expression.
67
68 +--global::
69 + Use global ~/.gitconfig file rather than the repository .git/config.
70 +
71 --unset::
68 - Remove the line matching the key from .git/config.
72 + Remove the line matching the key from config file.
73
74 --unset-all::
71 - Remove all matching lines from .git/config.
75 + Remove all matching lines from config file.
76
77 -l, --list::
74 - List all variables set in .git/config.
78 + List all variables set in config file.
79
80
81 ENVIRONMENT
@@ -79,6 +83,7 @@ ENVIRONMENT
83
84 GIT_CONFIG::
85 Take the configuration from the given file instead of .git/config.
86 + Using the "--global" option forces this to ~/.gitconfig.
87
88 GIT_CONFIG_LOCAL::
89 Currently the same as $GIT_CONFIG; when Git will support global
builtin-repo-config.c
+11 -2
@@ -3,7 +3,7 @@
3 #include <regex.h>
4
5 static const char git_config_set_usage[] =
6 -"git-repo-config [ --bool | --int ] [--get | --get-all | --get-regexp | --replace-all | --unset | --unset-all] name [value [value_regex]] | --list";
6 +"git-repo-config [ --global ] [ --bool | --int ] [--get | --get-all | --get-regexp | --replace-all | --unset | --unset-all] name [value [value_regex]] | --list";
7
8 static char *key;
9 static regex_t *key_regexp;
@@ -139,7 +139,16 @@ int cmd_repo_config(int argc, const char **argv, const char *prefix)
139 type = T_BOOL;
140 else if (!strcmp(argv[1], "--list") || !strcmp(argv[1], "-l"))
141 return git_config(show_all_config);
142 - else
142 + else if (!strcmp(argv[1], "--global")) {
143 + char *home = getenv("HOME");
144 + if (home) {
145 + char *user_config = xstrdup(mkpath("%s/.gitconfig", home));
146 + setenv("GIT_CONFIG", user_config, 1);
147 + free(user_config);
148 + } else {
149 + die("$HOME not set");
150 + }
151 + } else
152 break;
153 argc--;
154 argv++;