Skip to contentSkip to conversation

Minor documentation problems

PATCH New Matthieu Moy 4 participants 9 messages Aug 11, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

Hi,

I'm giving a try to git/cogito after using other systems (particularly GNU Arch and Bazaar).

I'm looking for a VCS which can suite me (willing to spend some time learning it) and some collegues (NOT willing to spend more than a few minutes learning a new tool. "patch" was already too complex, and someone already requested me to send a full version instead of this "weird thing that I don't have time to learn"). I'm also looking for a system for my students, ranging from the somewhat experienced hacker to the mathematician not caring about computers at all.

The git/cogito duo might do it, let's see.

I found minor problems with the doc, which deserve to be fixed:

* http://www.kernel.org/pub/software/scm/cogito/docs/cg-commit.1.html
Mentions .git/config, but not ~/.gitconfig (which is indeed _the_ place where I think most people want to set their name and email).

Side note: it can be interesting to have a command to do this. For example, bzr has "bzr whoami 'me <[email protected]>'", which avoids having to learn the config file syntax.

* RSS link on the wiki:
The URL
http://git.or.cz/gitwiki/RecentChanges?action=rss_rc&ddiffs=1&unique=1
seems to be working as an RSS feed for changes, but it's not linked to by http://git.or.cz/gitwiki/RecentChanges. Usually, there's an RSS icon, and an HTML <link rel="alternate" ...> to help finding it.

Thanks,

#1 lore raw

Re: Minor documentation problems [RFC PATCH]

Quoted 7 lines · On Thu, 02 Nov 2006 11:40:23 +0100 Matthieu Moy <[email protected]> wrote:

* http://www.kernel.org/pub/software/scm/cogito/docs/cg-commit.1.html
Mentions .git/config, but not ~/.gitconfig (which is indeed _the_ place where I think most people want to set their name and email).

Side note: it can be interesting to have a command to do this. For example, bzr has "bzr whoami 'me <[email protected]>'", which avoids having to learn the config file syntax.

This is the git version :

$ git repo-config user.email "[email protected]"
$ git repo-config user.name "me"

Unfortunately repo-config doesn't update ~/.gitconfig only the .git/config file.

The patch below adds a --global option to allow:

$ git repo-config --global user.email "[email protected]"
$ git repo-config --global user.name "me"

Although the syntax is a bit depressing, it would seem to be the path of least resistance.

The patch below always updates ~/.gitconfig but perhaps it should respect GIT_CONFIG and/or GIT_CONFIG_LOCAL environment variables.

Sean

builtin-repo-config.c +22 -9
index f60cee1..8c2b58a 100644
@@ -127,9 +127,20 @@ free_strings:
 	return ret;
 }
 
+static int set_config(int global, const char* key, const char* value,
+		const char* value_regex, int multi_replace)
+{
+	if (global)
+		return git_global_config_set_multivar(key, value,
+				value_regex, multi_replace);
+	else
+		return git_config_set_multivar(key, value,
+				value_regex, multi_replace);
+}
+
 int cmd_repo_config(int argc, const char **argv, const char *prefix)
 {
-	int nongit = 0;
+	int nongit = 0, global = 0;
 	setup_git_directory_gently(&nongit);
 
 	while (1 < argc) {
@@ -139,6 +150,8 @@ int cmd_repo_config(int argc, const char
 			type = T_BOOL;
 		else if (!strcmp(argv[1], "--list") || !strcmp(argv[1], "-l"))
 			return git_config(show_all_config);
+		else if (!strcmp(argv[1], "--global"))
+			global = 1;
 		else
 			break;
 		argc--;
@@ -150,9 +163,9 @@ int cmd_repo_config(int argc, const char
 		return get_value(argv[1], NULL);
 	case 3:
 		if (!strcmp(argv[1], "--unset"))
-			return git_config_set(argv[2], NULL);
+			return set_config(global, argv[2], NULL, NULL, 0);
 		else if (!strcmp(argv[1], "--unset-all"))
-			return git_config_set_multivar(argv[2], NULL, NULL, 1);
+			return set_config(global, argv[2], NULL, NULL, 1);
 		else if (!strcmp(argv[1], "--get"))
 			return get_value(argv[2], NULL);
 		else if (!strcmp(argv[1], "--get-all")) {
@@ -165,12 +178,12 @@ int cmd_repo_config(int argc, const char
 			return get_value(argv[2], NULL);
 		} else
 
-			return git_config_set(argv[1], argv[2]);
+			return set_config(global, argv[1], argv[2], NULL, 0);
 	case 4:
 		if (!strcmp(argv[1], "--unset"))
-			return git_config_set_multivar(argv[2], NULL, argv[3], 0);
+			return set_config(global, argv[2], NULL, argv[3], 0);
 		else if (!strcmp(argv[1], "--unset-all"))
-			return git_config_set_multivar(argv[2], NULL, argv[3], 1);
+			return set_config(global, argv[2], NULL, argv[3], 1);
 		else if (!strcmp(argv[1], "--get"))
 			return get_value(argv[2], argv[3]);
 		else if (!strcmp(argv[1], "--get-all")) {
@@ -183,13 +196,13 @@ int cmd_repo_config(int argc, const char
 			return get_value(argv[2], argv[3]);
 		} else if (!strcmp(argv[1], "--replace-all"))
 
-			return git_config_set_multivar(argv[2], argv[3], NULL, 1);
+			return set_config(global, argv[2], argv[3], NULL, 1);
 		else
 
-			return git_config_set_multivar(argv[1], argv[2], argv[3], 0);
+			return set_config(global, argv[1], argv[2], argv[3], 0);
 	case 5:
 		if (!strcmp(argv[1], "--replace-all"))
-			return git_config_set_multivar(argv[2], argv[3], argv[4], 1);
+			return set_config(global, argv[2], argv[3], argv[4], 1);
 	case 1:
 	default:
 		usage(git_config_set_usage);
cache.h +2 -0
index d0a1657..5f7c599 100644
@@ -402,6 +402,8 @@ extern int git_config_int(const char *,
 extern int git_config_bool(const char *, const char *);
 extern int git_config_set(const char *, const char *);
 extern int git_config_set_multivar(const char *, const char *, const char *, int);
+extern int git_global_config_set(const char*, const char*);
+extern int git_global_config_set_multivar(const char*, const char*, const char*, int);
 extern int check_repository_format_version(const char *var, const char *value);
 
 #define MAX_GITNAME (1000)
config.c +34 -8

59 lines not on this page · raw message

#2 lore raw

Re: Minor documentation problems [RFC PATCH]

Hi,

Quoted 3 lines · Sean

The patch below always updates ~/.gitconfig but perhaps it should respect GIT_CONFIG and/or GIT_CONFIG_LOCAL environment variables.

Your patch would be loads shorter and easier to read if you'd just override the GIT_CONFIG environment variable (like --git-dir sets GIT_DIR).

Ciao,
Dscho

#3 lore raw

Re: Minor documentation problems [RFC PATCH]

Quoted 4 lines · On Thu, 2 Nov 2006 14:54:24 +0100 (CET) Johannes Schindelin…

Your patch would be loads shorter and easier to read if you'd just override the GIT_CONFIG environment variable (like --git-dir sets GIT_DIR).

Indeed. Thanks... How 'bout this:

builtin-repo-config.c +10 -1
index f60cee1..dcdae81 100644
@@ -139,7 +139,16 @@ int cmd_repo_config(int argc, const char
 			type = T_BOOL;
 		else if (!strcmp(argv[1], "--list") || !strcmp(argv[1], "-l"))
 			return git_config(show_all_config);
-		else
+		else if (!strcmp(argv[1], "--global")) {
+			char *home = getenv("HOME");
+			if (home) {
+				char *user_config = xstrdup(mkpath("%s/.gitconfig", home));
+				setenv("GIT_CONFIG", user_config, 1);
+				free(user_config);
+			} else {
+				return -1;
+			}
+		} else
 			break;
 		argc--;
 		argv++;
#4 lore raw

Re: Minor documentation problems [RFC PATCH]

Hi,

builtin-repo-config.c int cmd_repo_config(int argc, const char · line 149

Quoted 9 lines · Sean
builtin-repo-config.c +8 -1
-		else
+		else if (!strcmp(argv[1], "--global")) {
+			char *home = getenv("HOME");
+			if (home) {
+				char *user_config = xstrdup(mkpath("%s/.gitconfig", home));
+				setenv("GIT_CONFIG", user_config, 1);
+				free(user_config);
+			} else {
+				return -1;

Micronit: might be useful to tell the user that she's homeless.

Else: ACK.

Ciao,
Dscho

#5 lore raw

PATCH 1/1 Add --global option to git-repo-config.

Allow user to set variables in global ~/.gitconfig file using command line.

---
 Documentation/git-repo-config.txt |   31 ++++++++++++++++++-------------
 builtin-repo-config.c             |   13 +++++++++++--
 2 files changed, 29 insertions(+), 15 deletions(-)
Documentation/git-repo-config.txt +18 -13
index 8a1ab61..8199615 100644
@@ -3,19 +3,19 @@ git-repo-config(1)
 
 NAME
 ----
-git-repo-config - Get and set options in .git/config
+git-repo-config - Get and set repository or global options.
 
 
 SYNOPSIS
 --------
 [verse]
-'git-repo-config' [type] name [value [value_regex]]
-'git-repo-config' [type] --replace-all name [value [value_regex]]
-'git-repo-config' [type] --get name [value_regex]
-'git-repo-config' [type] --get-all name [value_regex]
-'git-repo-config' [type] --unset name [value_regex]
-'git-repo-config' [type] --unset-all name [value_regex]
-'git-repo-config' -l | --list
+'git-repo-config' [--global] [type] name [value [value_regex]]
+'git-repo-config' [--global] [type] --replace-all name [value [value_regex]]
+'git-repo-config' [--global] [type] --get name [value_regex]
+'git-repo-config' [--global] [type] --get-all name [value_regex]
+'git-repo-config' [--global] [type] --unset name [value_regex]
+'git-repo-config' [--global] [type] --unset-all name [value_regex]
+'git-repo-config' [--global] -l | --list
 
 DESCRIPTION
 -----------
@@ -41,8 +41,9 @@ This command will fail if:
 . Can not write to .git/config,
 . no section was provided,
 . the section or key is invalid,
-. you try to unset an option which does not exist, or
-. you try to unset/set an option for which multiple lines match.
+. you try to unset an option which does not exist,
+. you try to unset/set an option for which multiple lines match, or
+. you use --global option without $HOME being properly set.
 
 
 OPTIONS
@@ -64,14 +65,17 @@ OPTIONS
 --get-regexp::
 	Like --get-all, but interprets the name as a regular expression.
 
+--global::
+	Use global ~/.gitconfig file rather than the repository .git/config.
+
 --unset::
-	Remove the line matching the key from .git/config.
+	Remove the line matching the key from config file.
 
 --unset-all::
-	Remove all matching lines from .git/config.
+	Remove all matching lines from config file.
 
 -l, --list::
-	List all variables set in .git/config.
+	List all variables set in config file.
 
 
 ENVIRONMENT
@@ -79,6 +83,7 @@ ENVIRONMENT
 
 GIT_CONFIG::
 	Take the configuration from the given file instead of .git/config.
+	Using the "--global" option forces this to ~/.gitconfig.
 
 GIT_CONFIG_LOCAL::
 	Currently the same as $GIT_CONFIG; when Git will support global
builtin-repo-config.c +11 -2
index f60cee1..7b6e572 100644
@@ -3,7 +3,7 @@
 #include <regex.h>
 
 static const char git_config_set_usage[] =
-"git-repo-config [ --bool | --int ] [--get | --get-all | --get-regexp | --replace-all | --unset | --unset-all] name [value [value_regex]] | --list";
+"git-repo-config [ --global ] [ --bool | --int ] [--get | --get-all | --get-regexp | --replace-all | --unset | --unset-all] name [value [value_regex]] | --list";
 
 static char *key;
 static regex_t *key_regexp;
@@ -139,7 +139,16 @@ int cmd_repo_config(int argc, const char
 			type = T_BOOL;
 		else if (!strcmp(argv[1], "--list") || !strcmp(argv[1], "-l"))
 			return git_config(show_all_config);
-		else
+		else if (!strcmp(argv[1], "--global")) {
+			char *home = getenv("HOME");
+			if (home) {
+				char *user_config = xstrdup(mkpath("%s/.gitconfig", home));
+				setenv("GIT_CONFIG", user_config, 1);
+				free(user_config);
+			} else {
+				die("$HOME not set");
+			}
+		} else
 			break;
 		argc--;
 		argv++;
Signature · 1 line
1.4.3.3.g869c
#6 lore raw

Re: Minor documentation problems [RFC PATCH]

In reply to Sean
Quoted 4 lines · Sean

This is the git version :

$ git repo-config user.email "[email protected]"
$ git repo-config user.name "me"

Great!

But this should be mentionned in
http://www.kernel.org/pub/software/scm/git/docs/git-commit-tree.html
too.

Perhaps, "As an alternative to editing the .git/config or ~/.gitconfig manually, you can use git-repo-config".

BTW,
http://www.kernel.org/pub/software/scm/git/docs/git-commit-tree.html
also fails to mention ~/.gitconfig.

#7 lore raw
In reply to Matthieu Moy

Hi,

Dear diary, on Thu, Nov 02, 2006 at 11:40:23AM CET, I got a letter where Matthieu Moy <[email protected]> said that...

Quoted 5 lines

I found minor problems with the doc, which deserve to be fixed:

* http://www.kernel.org/pub/software/scm/cogito/docs/cg-commit.1.html
Mentions .git/config, but not ~/.gitconfig (which is indeed _the_ place where I think most people want to set their name and email).

thanks for pointing this out, further releases will mention both.

Quoted 3 lines

Side note: it can be interesting to have a command to do this. For example, bzr has "bzr whoami 'me <[email protected]>'", which avoids having to learn the config file syntax.

Yes, you are certainly not the first to wish this, I'm seriously
thinking about introducing cg-admin-config for setting the most common configuration variables.

Moreover, I'm more and more thinking about removing the fallback on
guessing based on /etc/passwd and hostname. _Many_ people were and will be burnt by it, and I think it's more sane to require the user to confirm once what the valid credentials are (at _that_ point it's ok to guess, but the user has to confirm it) than let them unconsciously do 200 commits with completely bogus author lines.

What do the Git people think? Perhaps we could introduce GIT_NO_GUESS
environment variable which will prevent var.c from guessing?

Quoted 6 lines

* RSS link on the wiki:
The URL
http://git.or.cz/gitwiki/RecentChanges?action=rss_rc&ddiffs=1&unique=1
seems to be working as an RSS feed for changes, but it's not linked to by http://git.or.cz/gitwiki/RecentChanges. Usually, there's an RSS icon, and an HTML <link rel="alternate" ...> to help finding it.

Fixed, thanks.

Signature · 4 lines
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
#!/bin/perl -sp0777i<X+d*lMLa^*lN%0]dsXx++lMlN/dsM0<j]dsj
$/=unpack('H*',$_);$_=`echo 16dio\U$k"SK$/SM$n\EsN0p[lN*1
#8 lore raw
Quoted 6 lines · Petr Baudis

Moreover, I'm more and more thinking about removing the fallback on
guessing based on /etc/passwd and hostname. _Many_ people were and will be burnt by it, and I think it's more sane to require the user to confirm once what the valid credentials are (at _that_ point it's ok to guess, but the user has to confirm it) than let them unconsciously do 200 commits with completely bogus author lines.

IIRC, Darcs will prompt interactively the first time and remember it. The problem of interactive prompt is that it can break scripts (which are not always ran from an interactive prompt), so it's probably OK to do this in cogito, but less so in git.

One nice thing with guess-and-don't-ask is that people who don't care don't have to bother about this. I mean, some people have been satisfied with CVS storing the username of the guy doing the access which is often wrong for years, so ... it's probably OK to use an incorrect guess for a private project with, say, <5 contributors.