git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] repo-config: learn the flag "--no-local"

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jun 8, 2006, 11:31 UTC
Message-ID
<Pine.LNX.4.63.0606081331140.11910@wbgn013.biozentrum.uni-wuerzburg.de>

Since there is a global config now, we need a way to access it conveniently. Now you can say

	git repo-config --no-local alias.l "log --stat -M ORIG_HEAD.."
to set the alias globally (it will be stored in ~/.gitconfig).
Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---
 cache.h       |    1 +
 config.c      |   23 ++++++++++++++++++-----
 repo-config.c |    5 ++++-
 3 files changed, 23 insertions(+), 6 deletions(-)
diff --git a/cache.h b/cache.h
index d5d7fe4..14fe5c8 100644
--- a/cache.h
+++ b/cache.h
@@ -348,6 +348,7 @@ extern void packed_object_info_detail(st
 /* Dumb servers support */
 extern int update_server_info(int);
 
+extern int git_ignore_local_config;
 typedef int (*config_fn_t)(const char *, const char *);
 extern int git_default_config(const char *, const char *);
 extern int git_config_from_file(config_fn_t fn, const char *);
diff --git a/config.c b/config.c
index 0987943..33f9109 100644
--- a/config.c
+++ b/config.c
@@ -10,6 +10,7 @@ #include <regex.h>
 
 #define MAXNAME (256)
 
+int git_ignore_local_config = 0;
 static FILE *config_file;
 static const char *config_file_name;
 static int config_linenr;
@@ -327,7 +328,8 @@ int git_config(config_fn_t fn)
 			ret = 0;
 	}
 
-	ret += git_config_from_file(fn, git_path("config"));
+	if (!git_ignore_local_config)
+		ret += git_config_from_file(fn, git_path("config"));
 	return ret;
 }
 
@@ -501,10 +503,20 @@ int git_config_set_multivar(const char* 
 	int i, dot;
 	int fd = -1, in_fd;
 	int ret;
-	char* config_filename = strdup(git_path("config"));
-	char* lock_file = strdup(git_path("config.lock"));
+	char *config_filename, *lock_file;
 	const char* last_dot = strrchr(key, '.');
 
+	if (git_ignore_local_config) {
+		const char *home = getenv("HOME");
+		if (!home)
+			die("No home?");
+		config_filename = strdup(mkpath("%s/.gitconfig", home));
+		lock_file = strdup(mkpath("%s/.gitconfig.lock", home));
+	} else {
+		config_filename = strdup(git_path("config"));
+		lock_file = strdup(git_path("config.lock"));
+	}
+
 	/*
 	 * Since "key" actually contains the section name and the real
 	 * key name separated by a dot, we have to know where the dot is.
@@ -611,8 +623,9 @@ int git_config_set_multivar(const char* 
 		 * As a side effect, we make sure to transform only a valid
 		 * existing config file.
 		 */
-		if (git_config(store_aux)) {
-			fprintf(stderr, "invalid config file\n");
+		if (git_config_from_file(store_aux, config_filename)) {
+			fprintf(stderr, "invalid config file: %s\n",
+					config_filename);
 			free(store.key);
 			if (store.value_regex != NULL) {
 				regfree(store.value_regex);
diff --git a/repo-config.c b/repo-config.c
index 59c2bfb..8c0bb20 100644
--- a/repo-config.c
+++ b/repo-config.c
@@ -97,7 +97,8 @@ static int get_value(const char* key_, c
 
 	if (do_all && global)
 		git_config_from_file(show_config, global);
-	git_config_from_file(show_config, git_path("config"));
+	if (!git_ignore_local_config)
+		git_config_from_file(show_config, git_path("config"));
 	if (!do_all && !seen)
 		git_config_from_file(show_config, global);
 
@@ -125,6 +126,8 @@ int main(int argc, const char **argv)
 			type = T_BOOL;
 		else if (!strcmp(argv[1], "--list") || !strcmp(argv[1], "-l"))
 			return git_config(show_all_config);
+		else if (!strcmp(argv[1], "--no-local"))
+			git_ignore_local_config = 1;
 		else
 			break;
 		argc--;
-- 
1.4.0.rc1.g2f47-dirty
Next: Lukas Sandström
Message 1 of 21 in “repo-config: learn the flag "--no-local"”
  1. 2/2 repo-config: learn the flag "--no-local"Johannes Schindelin, Jun 8, 2006
  2. Lukas SandströmJun 8, 2006
  3. Johannes SchindelinJun 8, 2006
  4. Karl HasselströmJun 8, 2006
  5. Aneesh Kumar K.VJun 8, 2006
  6. Jakub NarebskiJun 8, 2006
  7. Johannes SchindelinJun 8, 2006
  8. Alex RiesenJun 8, 2006
  9. Junio C HamanoJun 8, 2006
  10. SeanJun 8, 2006
  11. Johannes SchindelinJun 8, 2006
  12. SeanJun 8, 2006
  13. Johannes SchindelinJun 8, 2006
  14. SeanJun 8, 2006
  15. Johannes SchindelinJun 8, 2006
  16. SeanJun 8, 2006
  17. Jakub NarebskiJun 8, 2006
  18. Johannes SchindelinJun 8, 2006
  19. Jakub NarebskiJun 8, 2006
  20. Aneesh Kumar K.VJun 8, 2006
  21. Johannes SchindelinJun 8, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.