@matheusbsbs / matheus-bagliano / commits / 32043c9f8c
Fork 0

config: read system-wide defaults from /etc/gitconfig

The settings in /etc/gitconfig can be overridden in ~/.gitconfig, which in turn can be overridden in .git/config. Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>

Johannes Schindelin committed Feb 14, 2007 at 12:48 UTC 32043c9f8c60fc03b0b6a324c559d98094729323
4 files changed +20 -5
Documentation/config.txt
+2 -1
@@ -5,7 +5,8 @@ The git configuration file contains a number of variables that affect
5 the git command's behavior. `.git/config` file for each repository
6 is used to store the information for that repository, and
7 `$HOME/.gitconfig` is used to store per user information to give
8 -fallback values for `.git/config` file.
8 +fallback values for `.git/config` file. The file `/etc/gitconfig`
9 +can be used to store system-wide defaults.
10
11 They can be used by both the git plumbing
12 and the porcelains. The variables are divided into sections, where
Makefile
+4 -1
@@ -124,6 +124,7 @@ prefix = $(HOME)
124 bindir = $(prefix)/bin
125 gitexecdir = $(bindir)
126 template_dir = $(prefix)/share/git-core/templates/
127 +ETC_GITCONFIG = $(prefix)/etc/gitconfig
128 # DESTDIR=
129
130 # default configuration for gitweb
@@ -584,6 +585,7 @@ endif
585 # Shell quote (do not use $(call) to accommodate ancient setups);
586
587 SHA1_HEADER_SQ = $(subst ','\'',$(SHA1_HEADER))
588 +ETC_GITCONFIG_SQ = $(subst ','\'',$(ETC_GITCONFIG))
589
590 DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
591 bindir_SQ = $(subst ','\'',$(bindir))
@@ -596,7 +598,8 @@ PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
598
599 LIBS = $(GITLIBS) $(EXTLIBS)
600
599 -BASIC_CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER_SQ)' $(COMPAT_CFLAGS)
601 +BASIC_CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER_SQ)' \
602 + -DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"' $(COMPAT_CFLAGS)
603 LIB_OBJS += $(COMPAT_OBJS)
604
605 ALL_CFLAGS += $(BASIC_CFLAGS)
builtin-config.c
+12 -3
@@ -64,7 +64,7 @@ static int get_value(const char* key_, const char* regex_)
64 int ret = -1;
65 char *tl;
66 char *global = NULL, *repo_config = NULL;
67 - const char *local;
67 + const char *system_wide = NULL, *local;
68
69 local = getenv(CONFIG_ENVIRONMENT);
70 if (!local) {
@@ -74,6 +74,7 @@ static int get_value(const char* key_, const char* regex_)
74 local = repo_config = xstrdup(git_path("config"));
75 if (home)
76 global = xstrdup(mkpath("%s/.gitconfig", home));
77 + system_wide = ETC_GITCONFIG;
78 }
79
80 key = xstrdup(key_);
@@ -103,11 +104,15 @@ static int get_value(const char* key_, const char* regex_)
104 }
105 }
106
107 + if (do_all && system_wide)
108 + git_config_from_file(show_config, system_wide);
109 if (do_all && global)
110 git_config_from_file(show_config, global);
111 git_config_from_file(show_config, local);
112 if (!do_all && !seen && global)
113 git_config_from_file(show_config, global);
114 + if (!do_all && !seen && system_wide)
115 + git_config_from_file(show_config, system_wide);
116
117 free(key);
118 if (regexp) {
@@ -147,7 +152,10 @@ int cmd_config(int argc, const char **argv, const char *prefix)
152 } else {
153 die("$HOME not set");
154 }
150 - } else if (!strcmp(argv[1], "--rename-section")) {
155 + }
156 + else if (!strcmp(argv[1], "--system"))
157 + setenv("GIT_CONFIG", ETC_GITCONFIG, 1);
158 + else if (!strcmp(argv[1], "--rename-section")) {
159 int ret;
160 if (argc != 4)
161 usage(git_config_set_usage);
@@ -159,7 +167,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
167 return 1;
168 }
169 return 0;
162 - } else
170 + }
171 + else
172 break;
173 argc--;
174 argv++;
config.c
+2
@@ -383,6 +383,8 @@ int git_config(config_fn_t fn)
383 * config file otherwise. */
384 filename = getenv(CONFIG_ENVIRONMENT);
385 if (!filename) {
386 + if (!access(ETC_GITCONFIG, R_OK))
387 + ret += git_config_from_file(fn, ETC_GITCONFIG);
388 home = getenv("HOME");
389 filename = getenv(CONFIG_LOCAL_ENVIRONMENT);
390 if (!filename)