[PATCH] user.default: New config to prevent using the default values for user.*

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Useful when you want a different email/name for each repository

Signed-off-by: Santi Béjar <sbejar@xxxxxxxxx>
---
 Documentation/config.txt |    5 +++++
 cache.h                  |    1 +
 config.c                 |    5 +++++
 environment.c            |    1 +
 ident.c                  |    6 +++---
 5 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 4027726..d7e5b6d 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -914,6 +914,11 @@ url.<base>.insteadOf::
 	never-before-seen repository on the site.  When more than one
 	insteadOf strings match a given URL, the longest match is used.
 
+user.default::
+	If false the defaults values for user.email and user.name are not
+	used. Useful when you want a different email/name for each
+	repository, normally set in the global config file.
+
 user.email::
 	Your email address to be recorded in any newly created commits.
 	Can be overridden by the 'GIT_AUTHOR_EMAIL', 'GIT_COMMITTER_EMAIL', and
diff --git a/cache.h b/cache.h
index e230302..70f08d0 100644
--- a/cache.h
+++ b/cache.h
@@ -703,6 +703,7 @@ extern int config_error_nonbool(const char *);
 #define MAX_GITNAME (1000)
 extern char git_default_email[MAX_GITNAME];
 extern char git_default_name[MAX_GITNAME];
+extern int default_ident;
 
 extern const char *git_commit_encoding;
 extern const char *git_log_output_encoding;
diff --git a/config.c b/config.c
index 0624494..ea1fa71 100644
--- a/config.c
+++ b/config.c
@@ -445,6 +445,11 @@ int git_default_config(const char *var, const char *value)
 		return 0;
 	}
 
+	if (!strcmp(var, "user.default")) {
+		default_ident = git_config_bool(var, value);
+		return 0;
+	}
+
 	if (!strcmp(var, "i18n.commitencoding"))
 		return git_config_string(&git_commit_encoding, var, value);
 
diff --git a/environment.c b/environment.c
index 6739a3f..8e252e2 100644
--- a/environment.c
+++ b/environment.c
@@ -11,6 +11,7 @@
 
 char git_default_email[MAX_GITNAME];
 char git_default_name[MAX_GITNAME];
+int default_ident = 1;
 int trust_executable_bit = 1;
 int quote_path_fully = 1;
 int has_symlinks = 1;
diff --git a/ident.c b/ident.c
index b839dcf..0f62a94 100644
--- a/ident.c
+++ b/ident.c
@@ -75,7 +75,7 @@ static void setup_ident(void)
 	struct passwd *pw = NULL;
 
 	/* Get the name ("gecos") */
-	if (!git_default_name[0]) {
+	if (!git_default_name[0] && default_ident) {
 		pw = getpwuid(getuid());
 		if (!pw)
 			die("You don't exist. Go away!");
@@ -88,7 +88,7 @@ static void setup_ident(void)
 		if (email && email[0])
 			strlcpy(git_default_email, email,
 				sizeof(git_default_email));
-		else {
+		else if (default_ident) {
 			if (!pw)
 				pw = getpwuid(getuid());
 			if (!pw)
@@ -171,7 +171,7 @@ static const char au_env[] = "GIT_AUTHOR_NAME";
 static const char co_env[] = "GIT_COMMITTER_NAME";
 static const char *env_hint =
 "\n"
-"*** Your name cannot be determined from your system services (gecos).\n"
+"*** Your name cannot be determined.\n"
 "\n"
 "Run\n"
 "\n"
-- 
1.5.4.3.447.gc95b3.dirty

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux