Skip to content

Commit

Permalink
Merge branch 'js/etc-config'
Browse files Browse the repository at this point in the history
* js/etc-config:
  Make tests independent of global config files
  config: read system-wide defaults from /etc/gitconfig
  • Loading branch information
Junio C Hamano committed Feb 24, 2007
2 parents 8a13bec + 8565d2d commit cc58fc0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Documentation/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ The git configuration file contains a number of variables that affect
the git command's behavior. `.git/config` file for each repository
is used to store the information for that repository, and
`$HOME/.gitconfig` is used to store per user information to give
fallback values for `.git/config` file.
fallback values for `.git/config` file. The file `/etc/gitconfig`
can be used to store system-wide defaults.

They can be used by both the git plumbing
and the porcelains. The variables are divided into sections, where
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ prefix = $(HOME)
bindir = $(prefix)/bin
gitexecdir = $(bindir)
template_dir = $(prefix)/share/git-core/templates/
ETC_GITCONFIG = $(prefix)/etc/gitconfig
# DESTDIR=

# default configuration for gitweb
Expand Down Expand Up @@ -598,6 +599,7 @@ endif
# Shell quote (do not use $(call) to accommodate ancient setups);

SHA1_HEADER_SQ = $(subst ','\'',$(SHA1_HEADER))
ETC_GITCONFIG_SQ = $(subst ','\'',$(ETC_GITCONFIG))

DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
bindir_SQ = $(subst ','\'',$(bindir))
Expand All @@ -610,7 +612,8 @@ PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))

LIBS = $(GITLIBS) $(EXTLIBS)

BASIC_CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER_SQ)' $(COMPAT_CFLAGS)
BASIC_CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER_SQ)' \
-DETC_GITCONFIG='"$(ETC_GITCONFIG_SQ)"' $(COMPAT_CFLAGS)
LIB_OBJS += $(COMPAT_OBJS)

ALL_CFLAGS += $(BASIC_CFLAGS)
Expand Down
15 changes: 12 additions & 3 deletions builtin-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,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) {
Expand All @@ -74,6 +74,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_);
Expand Down Expand Up @@ -103,11 +104,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) {
Expand Down Expand Up @@ -147,7 +152,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);
Expand All @@ -159,7 +167,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
return 1;
}
return 0;
} else
}
else
break;
argc--;
argv++;
Expand Down
2 changes: 2 additions & 0 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,8 @@ int git_config(config_fn_t fn)
* config file otherwise. */
filename = getenv(CONFIG_ENVIRONMENT);
if (!filename) {
if (!access(ETC_GITCONFIG, R_OK))
ret += git_config_from_file(fn, ETC_GITCONFIG);
home = getenv("HOME");
filename = getenv(CONFIG_LOCAL_ENVIRONMENT);
if (!filename)
Expand Down
4 changes: 2 additions & 2 deletions t/test-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ test_done () {
PATH=$(pwd)/..:$PATH
GIT_EXEC_PATH=$(pwd)/..
GIT_TEMPLATE_DIR=$(pwd)/../templates/blt
HOME=$(pwd)/trash
export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR HOME
GIT_CONFIG=.git/config
export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG

GITPERLLIB=$(pwd)/../perl/blib/lib:$(pwd)/../perl/blib/arch/auto/Git
export GITPERLLIB
Expand Down

0 comments on commit cc58fc0

Please sign in to comment.