{"thread":{"id":"37215","subject":"[PATCH v2 1/3] config --global --edit: create a template file if needed","startedAt":"2014-07-25T18:00:05Z","lastAt":"2014-07-25T19:38:58Z","messageCount":10,"participants":["Matthieu Moy","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":3},"messages":[{"id":"246731","messageId":"1406311207-8276-1-git-send-email-Matthieu.Moy@imag.fr","threadId":"37215","inReplyTo":null,"subject":"[PATCH v2 1/3] config --global --edit: create a template file if needed","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2014-07-25T18:00:05Z","receivedAt":"2014-07-25T18:00:05Z","isPatch":true,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"When the user has no ~/.gitconfig file, git config --global --edit used\nto launch an editor on an nonexistant file name.\n\nInstead, create a file with a default content before launching the\neditor. The template contains only commented-out entries, to save a few\nkeystrokes for the user. If the values are guessed properly, the user\nwill only have to uncomment the entries.\n\nAdvanced users teaching newbies can create a minimalistic configuration\nfaster for newbies. Beginners reading a tutorial advising to run \"git\nconfig --global --edit\" as a first step will be slightly more guided for\ntheir first contact with Git.\n\nSigned-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>\n---\nHopefully, all remarks applied. I went for \"Git's user configuration\", but\nI can change it to whatever native speakers think is better.\n\n builtin/config.c | 31 ++++++++++++++++++++++++++++---\n cache.h          |  1 +\n ident.c          |  2 +-\n 3 files changed, 30 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/config.c b/builtin/config.c\nindex fcd8474..1363478 100644\n--- a/builtin/config.c\n+++ b/builtin/config.c\n@@ -445,6 +445,20 @@ static int get_urlmatch(const char *var, const char *url)\n \treturn 0;\n }\n \n+static char *default_user_config(void)\n+{\n+\tstruct strbuf buf = STRBUF_INIT;\n+\tstrbuf_addf(&buf,\n+\t\t    _(\"# This is Git's user configuration file.\\n\"\n+\t\t      \"[core]\\n\"\n+\t\t      \"# Please adapt and uncomment the following lines:\\n\"\n+\t\t      \"#\tuser = %s\\n\"\n+\t\t      \"#\temail = %s\\n\"),\n+\t\t    ident_default_name(),\n+\t\t    ident_default_email());\n+\treturn strbuf_detach(&buf, NULL);\n+}\n+\n int cmd_config(int argc, const char **argv, const char *prefix)\n {\n \tint nongit = !startup_info->have_repository;\n@@ -551,6 +565,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)\n \t\t}\n \t}\n \telse if (actions == ACTION_EDIT) {\n+\t\tconst char *config_file = given_config_source.file ?\n+\t\t\tgiven_config_source.file : git_path(\"config\");\n \t\tcheck_argc(argc, 0, 0);\n \t\tif (!given_config_source.file && nongit)\n \t\t\tdie(\"not in a git directory\");\n@@ -559,9 +575,18 @@ int cmd_config(int argc, const char **argv, const char *prefix)\n \t\tif (given_config_source.blob)\n \t\t\tdie(\"editing blobs is not supported\");\n \t\tgit_config(git_default_config, NULL);\n-\t\tlaunch_editor(given_config_source.file ?\n-\t\t\t      given_config_source.file : git_path(\"config\"),\n-\t\t\t      NULL, NULL);\n+\t\tif (use_global_config) {\n+\t\t\tint fd = open(config_file, O_CREAT | O_EXCL | O_WRONLY, 0666);\n+\t\t\tif (fd) {\n+\t\t\t\tchar *content = default_user_config();\n+\t\t\t\twrite_str_in_full(fd, content);\n+\t\t\t\tfree(content);\n+\t\t\t\tclose(fd);\n+\t\t\t}\n+\t\t\telse if (errno != EEXIST)\n+\t\t\t\tdie_errno(_(\"cannot create configuration file %s\"), config_file);\n+\t\t}\n+\t\tlaunch_editor(config_file, NULL, NULL);\n \t}\n \telse if (actions == ACTION_SET) {\n \t\tint ret;\ndiff --git a/cache.h b/cache.h\nindex fcb511d..b06cbb2 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1061,6 +1061,7 @@ extern const char *git_author_info(int);\n extern const char *git_committer_info(int);\n extern const char *fmt_ident(const char *name, const char *email, const char *date_str, int);\n extern const char *fmt_name(const char *name, const char *email);\n+extern const char *ident_default_name(void);\n extern const char *ident_default_email(void);\n extern const char *git_editor(void);\n extern const char *git_pager(int stdout_is_tty);\ndiff --git a/ident.c b/ident.c\nindex 1d9b6e7..77bc882 100644\n--- a/ident.c\n+++ b/ident.c\n@@ -102,7 +102,7 @@ static void copy_email(const struct passwd *pw, struct strbuf *email)\n \tadd_domainname(email);\n }\n \n-static const char *ident_default_name(void)\n+const char *ident_default_name(void)\n {\n \tif (!git_default_name.len) {\n \t\tcopy_gecos(xgetpwuid_self(), &git_default_name);\n-- \n2.0.2.737.gfb43bde\n"},{"id":"246733","messageId":"1406311207-8276-2-git-send-email-Matthieu.Moy@imag.fr","threadId":"37215","inReplyTo":"1406311207-8276-1-git-send-email-Matthieu.Moy@imag.fr","subject":"[PATCH v2 2/3] home_config_path: allow NULL xdg parameter","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2014-07-25T18:00:06Z","receivedAt":"2014-07-25T18:00:06Z","isPatch":true,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"This allows a caller to request the global config file without requesting\nthe XDG one.\n\nSigned-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>\n---\n path.c | 10 ++++++----\n 1 file changed, 6 insertions(+), 4 deletions(-)\n\ndiff --git a/path.c b/path.c\nindex 3afcdb4..f68df0c 100644\n--- a/path.c\n+++ b/path.c\n@@ -148,10 +148,12 @@ void home_config_paths(char **global, char **xdg, char *file)\n \t\t\t*global = mkpathdup(\"%s/.gitconfig\", home);\n \t}\n \n-\tif (!xdg_home)\n-\t\t*xdg = NULL;\n-\telse\n-\t\t*xdg = mkpathdup(\"%s/git/%s\", xdg_home, file);\n+\tif (xdg) {\n+\t\tif (!xdg_home)\n+\t\t\t*xdg = NULL;\n+\t\telse\n+\t\t\t*xdg = mkpathdup(\"%s/git/%s\", xdg_home, file);\n+\t}\n \n \tfree(to_free);\n }\n-- \n2.0.2.737.gfb43bde\n"},{"id":"246732","messageId":"1406311207-8276-3-git-send-email-Matthieu.Moy@imag.fr","threadId":"37215","inReplyTo":"1406311207-8276-1-git-send-email-Matthieu.Moy@imag.fr","subject":"[PATCH v2 3/3] commit: advertise config --global --edit on guessed identity","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2014-07-25T18:00:07Z","receivedAt":"2014-07-25T18:00:07Z","isPatch":true,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"When the user has no user-wide configuration file, it's faster to use the\nnewly introduced config file template than to run two commands to set\nuser.name and user.email. Advise this to the user.\n\nThe old advice is kept if the user already has a configuration file since\nthe template feature would not trigger in this case.\n\nSigned-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>\n---\n builtin/commit.c | 34 ++++++++++++++++++++++++++++++++--\n 1 file changed, 32 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 5ed6036..7502b0e 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -42,7 +42,20 @@ static const char * const builtin_status_usage[] = {\n \tNULL\n };\n \n-static const char implicit_ident_advice[] =\n+static const char implicit_ident_advice_noconfig[] =\n+N_(\"Your name and email address were configured automatically based\\n\"\n+\"on your username and hostname. Please check that they are accurate.\\n\"\n+\"You can suppress this message by setting them explicitly. Run the\\n\"\n+\"following command and follow the instructions in your editor to edit\\n\"\n+\"your configuration file:\\n\"\n+\"\\n\"\n+\"    git config --global --edit\\n\"\n+\"\\n\"\n+\"After doing this, you may fix the identity used for this commit with:\\n\"\n+\"\\n\"\n+\"    git commit --amend --reset-author\\n\");\n+\n+static const char implicit_ident_advice_config[] =\n N_(\"Your name and email address were configured automatically based\\n\"\n \"on your username and hostname. Please check that they are accurate.\\n\"\n \"You can suppress this message by setting them explicitly:\\n\"\n@@ -1402,6 +1415,23 @@ int cmd_status(int argc, const char **argv, const char *prefix)\n \treturn 0;\n }\n \n+static const char *implicit_ident_advice() {\n+\tchar *user_config = NULL;\n+\tchar *xdg_config = NULL;\n+\tint config_exists;\n+\n+\thome_config_paths(&user_config, &xdg_config, \"config\");\n+\tconfig_exists = file_exists(user_config) || file_exists(xdg_config);\n+\tfree(user_config);\n+\tfree(xdg_config);\n+\n+\tif (config_exists)\n+\t\treturn _(implicit_ident_advice_config);\n+\telse\n+\t\treturn _(implicit_ident_advice_noconfig);\n+\n+}\n+\n static void print_summary(const char *prefix, const unsigned char *sha1,\n \t\t\t  int initial_commit)\n {\n@@ -1440,7 +1470,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1,\n \t\tstrbuf_addbuf_percentquote(&format, &committer_ident);\n \t\tif (advice_implicit_identity) {\n \t\t\tstrbuf_addch(&format, '\\n');\n-\t\t\tstrbuf_addstr(&format, _(implicit_ident_advice));\n+\t\t\tstrbuf_addstr(&format, implicit_ident_advice());\n \t\t}\n \t}\n \tstrbuf_release(&author_ident);\n-- \n2.0.2.737.gfb43bde\n"},{"id":"246737","messageId":"xmqq1tt96yyh.fsf@gitster.dls.corp.google.com","threadId":"37215","inReplyTo":"1406311207-8276-1-git-send-email-Matthieu.Moy@imag.fr","subject":"Re: [PATCH v2 1/3] config --global --edit: create a template file if needed","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-07-25T19:05:42Z","receivedAt":"2014-07-25T19:05:42Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Matthieu Moy <Matthieu.Moy@imag.fr> writes:\n\n> When the user has no ~/.gitconfig file, git config --global --edit used\n> to launch an editor on an nonexistant file name.\n>\n> Instead, create a file with a default content before launching the\n> editor. The template contains only commented-out entries, to save a few\n> keystrokes for the user. If the values are guessed properly, the user\n> will only have to uncomment the entries.\n>\n> Advanced users teaching newbies can create a minimalistic configuration\n> faster for newbies. Beginners reading a tutorial advising to run \"git\n> config --global --edit\" as a first step will be slightly more guided for\n> their first contact with Git.\n>\n> Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>\n> ---\n> Hopefully, all remarks applied. I went for \"Git's user configuration\", but\n> I can change it to whatever native speakers think is better.\n\nI am not native but I have a slight worry that a template that lists\nonly core.{user,email} and marked as Git's \"user configuration\" will\neasily mislead the reader that the file is only about these two\n(i.e. I am telling the stupid Git who I am), and is not meant to\nhold any other configuration that are private to the user.  I still\nhave funny feeling about \"user-wide\", but \"Git's user configuration\"\nsomehow smells worse for that reason.\n\nWhat the patch attempts to do is a good idea and the code looks done\nright.  Let's queue it and hope people can polish the wording.\n\nThanks.\n\n>  builtin/config.c | 31 ++++++++++++++++++++++++++++---\n>  cache.h          |  1 +\n>  ident.c          |  2 +-\n>  3 files changed, 30 insertions(+), 4 deletions(-)\n>\n> diff --git a/builtin/config.c b/builtin/config.c\n> index fcd8474..1363478 100644\n> --- a/builtin/config.c\n> +++ b/builtin/config.c\n> @@ -445,6 +445,20 @@ static int get_urlmatch(const char *var, const char *url)\n>  \treturn 0;\n>  }\n>  \n> +static char *default_user_config(void)\n> +{\n> +\tstruct strbuf buf = STRBUF_INIT;\n> +\tstrbuf_addf(&buf,\n> +\t\t    _(\"# This is Git's user configuration file.\\n\"\n> +\t\t      \"[core]\\n\"\n> +\t\t      \"# Please adapt and uncomment the following lines:\\n\"\n> +\t\t      \"#\tuser = %s\\n\"\n> +\t\t      \"#\temail = %s\\n\"),\n> +\t\t    ident_default_name(),\n> +\t\t    ident_default_email());\n> +\treturn strbuf_detach(&buf, NULL);\n> +}\n> +\n>  int cmd_config(int argc, const char **argv, const char *prefix)\n>  {\n>  \tint nongit = !startup_info->have_repository;\n> @@ -551,6 +565,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)\n>  \t\t}\n>  \t}\n>  \telse if (actions == ACTION_EDIT) {\n> +\t\tconst char *config_file = given_config_source.file ?\n> +\t\t\tgiven_config_source.file : git_path(\"config\");\n>  \t\tcheck_argc(argc, 0, 0);\n>  \t\tif (!given_config_source.file && nongit)\n>  \t\t\tdie(\"not in a git directory\");\n> @@ -559,9 +575,18 @@ int cmd_config(int argc, const char **argv, const char *prefix)\n>  \t\tif (given_config_source.blob)\n>  \t\t\tdie(\"editing blobs is not supported\");\n>  \t\tgit_config(git_default_config, NULL);\n> -\t\tlaunch_editor(given_config_source.file ?\n> -\t\t\t      given_config_source.file : git_path(\"config\"),\n> -\t\t\t      NULL, NULL);\n> +\t\tif (use_global_config) {\n> +\t\t\tint fd = open(config_file, O_CREAT | O_EXCL | O_WRONLY, 0666);\n> +\t\t\tif (fd) {\n> +\t\t\t\tchar *content = default_user_config();\n> +\t\t\t\twrite_str_in_full(fd, content);\n> +\t\t\t\tfree(content);\n> +\t\t\t\tclose(fd);\n> +\t\t\t}\n> +\t\t\telse if (errno != EEXIST)\n> +\t\t\t\tdie_errno(_(\"cannot create configuration file %s\"), config_file);\n> +\t\t}\n> +\t\tlaunch_editor(config_file, NULL, NULL);\n>  \t}\n>  \telse if (actions == ACTION_SET) {\n>  \t\tint ret;\n> diff --git a/cache.h b/cache.h\n> index fcb511d..b06cbb2 100644\n> --- a/cache.h\n> +++ b/cache.h\n> @@ -1061,6 +1061,7 @@ extern const char *git_author_info(int);\n>  extern const char *git_committer_info(int);\n>  extern const char *fmt_ident(const char *name, const char *email, const char *date_str, int);\n>  extern const char *fmt_name(const char *name, const char *email);\n> +extern const char *ident_default_name(void);\n>  extern const char *ident_default_email(void);\n>  extern const char *git_editor(void);\n>  extern const char *git_pager(int stdout_is_tty);\n> diff --git a/ident.c b/ident.c\n> index 1d9b6e7..77bc882 100644\n> --- a/ident.c\n> +++ b/ident.c\n> @@ -102,7 +102,7 @@ static void copy_email(const struct passwd *pw, struct strbuf *email)\n>  \tadd_domainname(email);\n>  }\n>  \n> -static const char *ident_default_name(void)\n> +const char *ident_default_name(void)\n>  {\n>  \tif (!git_default_name.len) {\n>  \t\tcopy_gecos(xgetpwuid_self(), &git_default_name);\n"},{"id":"246738","messageId":"xmqqwqb15k7h.fsf@gitster.dls.corp.google.com","threadId":"37215","inReplyTo":"1406311207-8276-2-git-send-email-Matthieu.Moy@imag.fr","subject":"Re: [PATCH v2 2/3] home_config_path: allow NULL xdg parameter","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-07-25T19:09:38Z","receivedAt":"2014-07-25T19:09:38Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Matthieu Moy <Matthieu.Moy@imag.fr> writes:\n\n> This allows a caller to request the global config file without requesting\n> the XDG one.\n>\n> Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>\n> ---\n\nWill rephrase\n\n    A caller can ask only for XDG location by passing global=NULL.\n    Allow it to ask only for the $HOME/.gitconfig by passing\n    xdg=NULL.\n\nas you seem to have forgotten ;-)\n\n>  path.c | 10 ++++++----\n>  1 file changed, 6 insertions(+), 4 deletions(-)\n>\n> diff --git a/path.c b/path.c\n> index 3afcdb4..f68df0c 100644\n> --- a/path.c\n> +++ b/path.c\n> @@ -148,10 +148,12 @@ void home_config_paths(char **global, char **xdg, char *file)\n>  \t\t\t*global = mkpathdup(\"%s/.gitconfig\", home);\n>  \t}\n>  \n> -\tif (!xdg_home)\n> -\t\t*xdg = NULL;\n> -\telse\n> -\t\t*xdg = mkpathdup(\"%s/git/%s\", xdg_home, file);\n> +\tif (xdg) {\n> +\t\tif (!xdg_home)\n> +\t\t\t*xdg = NULL;\n> +\t\telse\n> +\t\t\t*xdg = mkpathdup(\"%s/git/%s\", xdg_home, file);\n> +\t}\n>  \n>  \tfree(to_free);\n>  }\n"},{"id":"246741","messageId":"1406315496-10237-1-git-send-email-Matthieu.Moy@imag.fr","threadId":"37215","inReplyTo":"xmqq1tt96yyh.fsf@gitster.dls.corp.google.com","subject":"[PATCH v3 1/3] config --global --edit: create a template file if needed","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2014-07-25T19:11:34Z","receivedAt":"2014-07-25T19:11:34Z","isPatch":true,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"When the user has no ~/.gitconfig file, git config --global --edit used\nto launch an editor on an nonexistant file name.\n\nInstead, create a file with a default content before launching the\neditor. The template contains only commented-out entries, to save a few\nkeystrokes for the user. If the values are guessed properly, the user\nwill only have to uncomment the entries.\n\nAdvanced users teaching newbies can create a minimalistic configuration\nfaster for newbies. Beginners reading a tutorial advising to run \"git\nconfig --global --edit\" as a first step will be slightly more guided for\ntheir first contact with Git.\n\nSigned-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>\n---\n> I am not native but I have a slight worry that a template that lists\n> only core.{user,email} and marked as Git's \"user configuration\" will\n> easily mislead the reader that the file is only about these two\n\nGood point, here's the one with \"per-user\", and PATCH 2 with your\nimproved commit message.\n\n builtin/config.c | 31 ++++++++++++++++++++++++++++---\n cache.h          |  1 +\n ident.c          |  2 +-\n 3 files changed, 30 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/config.c b/builtin/config.c\nindex fcd8474..aba7135 100644\n--- a/builtin/config.c\n+++ b/builtin/config.c\n@@ -445,6 +445,20 @@ static int get_urlmatch(const char *var, const char *url)\n \treturn 0;\n }\n \n+static char *default_user_config(void)\n+{\n+\tstruct strbuf buf = STRBUF_INIT;\n+\tstrbuf_addf(&buf,\n+\t\t    _(\"# This is Git's per-user configuration file.\\n\"\n+\t\t      \"[core]\\n\"\n+\t\t      \"# Please adapt and uncomment the following lines:\\n\"\n+\t\t      \"#\tuser = %s\\n\"\n+\t\t      \"#\temail = %s\\n\"),\n+\t\t    ident_default_name(),\n+\t\t    ident_default_email());\n+\treturn strbuf_detach(&buf, NULL);\n+}\n+\n int cmd_config(int argc, const char **argv, const char *prefix)\n {\n \tint nongit = !startup_info->have_repository;\n@@ -551,6 +565,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)\n \t\t}\n \t}\n \telse if (actions == ACTION_EDIT) {\n+\t\tconst char *config_file = given_config_source.file ?\n+\t\t\tgiven_config_source.file : git_path(\"config\");\n \t\tcheck_argc(argc, 0, 0);\n \t\tif (!given_config_source.file && nongit)\n \t\t\tdie(\"not in a git directory\");\n@@ -559,9 +575,18 @@ int cmd_config(int argc, const char **argv, const char *prefix)\n \t\tif (given_config_source.blob)\n \t\t\tdie(\"editing blobs is not supported\");\n \t\tgit_config(git_default_config, NULL);\n-\t\tlaunch_editor(given_config_source.file ?\n-\t\t\t      given_config_source.file : git_path(\"config\"),\n-\t\t\t      NULL, NULL);\n+\t\tif (use_global_config) {\n+\t\t\tint fd = open(config_file, O_CREAT | O_EXCL | O_WRONLY, 0666);\n+\t\t\tif (fd) {\n+\t\t\t\tchar *content = default_user_config();\n+\t\t\t\twrite_str_in_full(fd, content);\n+\t\t\t\tfree(content);\n+\t\t\t\tclose(fd);\n+\t\t\t}\n+\t\t\telse if (errno != EEXIST)\n+\t\t\t\tdie_errno(_(\"cannot create configuration file %s\"), config_file);\n+\t\t}\n+\t\tlaunch_editor(config_file, NULL, NULL);\n \t}\n \telse if (actions == ACTION_SET) {\n \t\tint ret;\ndiff --git a/cache.h b/cache.h\nindex fcb511d..b06cbb2 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1061,6 +1061,7 @@ extern const char *git_author_info(int);\n extern const char *git_committer_info(int);\n extern const char *fmt_ident(const char *name, const char *email, const char *date_str, int);\n extern const char *fmt_name(const char *name, const char *email);\n+extern const char *ident_default_name(void);\n extern const char *ident_default_email(void);\n extern const char *git_editor(void);\n extern const char *git_pager(int stdout_is_tty);\ndiff --git a/ident.c b/ident.c\nindex 1d9b6e7..77bc882 100644\n--- a/ident.c\n+++ b/ident.c\n@@ -102,7 +102,7 @@ static void copy_email(const struct passwd *pw, struct strbuf *email)\n \tadd_domainname(email);\n }\n \n-static const char *ident_default_name(void)\n+const char *ident_default_name(void)\n {\n \tif (!git_default_name.len) {\n \t\tcopy_gecos(xgetpwuid_self(), &git_default_name);\n-- \n2.0.2.737.gfb43bde\n"},{"id":"246739","messageId":"1406315496-10237-2-git-send-email-Matthieu.Moy@imag.fr","threadId":"37215","inReplyTo":"1406315496-10237-1-git-send-email-Matthieu.Moy@imag.fr","subject":"[PATCH v3 2/3] home_config_paths(): let the caller ignore xdg path","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2014-07-25T19:11:35Z","receivedAt":"2014-07-25T19:11:35Z","isPatch":true,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"The caller can signal that it is not interested in learning\nthe location of $HOME/.gitconfig by passing global=NULL, but\nthere is no way to decline the path to the configuration\nfile based on $XDG_CONFIG_HOME.\n\nAllow the caller to pass xdg=NULL to signal that it is not\ninterested in the XDG location.\n\nCommit-message-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>\n---\n path.c | 10 ++++++----\n 1 file changed, 6 insertions(+), 4 deletions(-)\n\ndiff --git a/path.c b/path.c\nindex 3afcdb4..f68df0c 100644\n--- a/path.c\n+++ b/path.c\n@@ -148,10 +148,12 @@ void home_config_paths(char **global, char **xdg, char *file)\n \t\t\t*global = mkpathdup(\"%s/.gitconfig\", home);\n \t}\n \n-\tif (!xdg_home)\n-\t\t*xdg = NULL;\n-\telse\n-\t\t*xdg = mkpathdup(\"%s/git/%s\", xdg_home, file);\n+\tif (xdg) {\n+\t\tif (!xdg_home)\n+\t\t\t*xdg = NULL;\n+\t\telse\n+\t\t\t*xdg = mkpathdup(\"%s/git/%s\", xdg_home, file);\n+\t}\n \n \tfree(to_free);\n }\n-- \n2.0.2.737.gfb43bde\n"},{"id":"246740","messageId":"1406315496-10237-3-git-send-email-Matthieu.Moy@imag.fr","threadId":"37215","inReplyTo":"1406315496-10237-1-git-send-email-Matthieu.Moy@imag.fr","subject":"[PATCH v3 3/3] commit: advertise config --global --edit on guessed identity","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2014-07-25T19:11:36Z","receivedAt":"2014-07-25T19:11:36Z","isPatch":true,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"When the user has no user-wide configuration file, it's faster to use the\nnewly introduced config file template than to run two commands to set\nuser.name and user.email. Advise this to the user.\n\nThe old advice is kept if the user already has a configuration file since\nthe template feature would not trigger in this case.\n\nSigned-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>\n---\n builtin/commit.c | 34 ++++++++++++++++++++++++++++++++--\n 1 file changed, 32 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 5ed6036..7502b0e 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -42,7 +42,20 @@ static const char * const builtin_status_usage[] = {\n \tNULL\n };\n \n-static const char implicit_ident_advice[] =\n+static const char implicit_ident_advice_noconfig[] =\n+N_(\"Your name and email address were configured automatically based\\n\"\n+\"on your username and hostname. Please check that they are accurate.\\n\"\n+\"You can suppress this message by setting them explicitly. Run the\\n\"\n+\"following command and follow the instructions in your editor to edit\\n\"\n+\"your configuration file:\\n\"\n+\"\\n\"\n+\"    git config --global --edit\\n\"\n+\"\\n\"\n+\"After doing this, you may fix the identity used for this commit with:\\n\"\n+\"\\n\"\n+\"    git commit --amend --reset-author\\n\");\n+\n+static const char implicit_ident_advice_config[] =\n N_(\"Your name and email address were configured automatically based\\n\"\n \"on your username and hostname. Please check that they are accurate.\\n\"\n \"You can suppress this message by setting them explicitly:\\n\"\n@@ -1402,6 +1415,23 @@ int cmd_status(int argc, const char **argv, const char *prefix)\n \treturn 0;\n }\n \n+static const char *implicit_ident_advice() {\n+\tchar *user_config = NULL;\n+\tchar *xdg_config = NULL;\n+\tint config_exists;\n+\n+\thome_config_paths(&user_config, &xdg_config, \"config\");\n+\tconfig_exists = file_exists(user_config) || file_exists(xdg_config);\n+\tfree(user_config);\n+\tfree(xdg_config);\n+\n+\tif (config_exists)\n+\t\treturn _(implicit_ident_advice_config);\n+\telse\n+\t\treturn _(implicit_ident_advice_noconfig);\n+\n+}\n+\n static void print_summary(const char *prefix, const unsigned char *sha1,\n \t\t\t  int initial_commit)\n {\n@@ -1440,7 +1470,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1,\n \t\tstrbuf_addbuf_percentquote(&format, &committer_ident);\n \t\tif (advice_implicit_identity) {\n \t\t\tstrbuf_addch(&format, '\\n');\n-\t\t\tstrbuf_addstr(&format, _(implicit_ident_advice));\n+\t\t\tstrbuf_addstr(&format, implicit_ident_advice());\n \t\t}\n \t}\n \tstrbuf_release(&author_ident);\n-- \n2.0.2.737.gfb43bde\n"},{"id":"246742","messageId":"xmqqsilp5jj6.fsf@gitster.dls.corp.google.com","threadId":"37215","inReplyTo":"1406315496-10237-1-git-send-email-Matthieu.Moy@imag.fr","subject":"Re: [PATCH v3 1/3] config --global --edit: create a template file if needed","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-07-25T19:24:13Z","receivedAt":"2014-07-25T19:24:13Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks; will queue the patches from this iteration.\n"},{"id":"246744","messageId":"xmqqoawd5iul.fsf@gitster.dls.corp.google.com","threadId":"37215","inReplyTo":"1406315496-10237-3-git-send-email-Matthieu.Moy@imag.fr","subject":"Re: [PATCH v3 3/3] commit: advertise config --global --edit on guessed identity","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-07-25T19:38:58Z","receivedAt":"2014-07-25T19:38:58Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Matthieu Moy <Matthieu.Moy@imag.fr> writes:\n\n> +static const char *implicit_ident_advice() {\n\nStyle:\n\nstatic const char *implicit_ident_advice(void)\n{\n\nNo need to resend.\n\nThanks.\n"}]}