diff options
author | Junio C Hamano <gitster@pobox.com> | 2014-09-02 13:23:19 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-09-02 13:23:20 -0700 |
commit | 1d8a6f6929054919baf4032e22935523c2843f2c (patch) | |
tree | 676ad7699612e6f200bad9647b15a07983b95247 /builtin/config.c | |
parent | c518279c0efbee88c31bb9916572ddfd9ac8eb00 (diff) | |
parent | 8b27ff7eacc3bafcb12afcd6bbc99cdb8d718a26 (diff) | |
download | git-1d8a6f6929054919baf4032e22935523c2843f2c.tar.gz |
Merge branch 'mm/config-edit-global'
Start "git config --edit --global" from a skeletal per-user
configuration file contents, instead of a total blank, when the
user does not already have any. This immediately reduces the need
for a later "Have you forgotten setting core.user?" and we can add
more to the template as we gain more experience.
* mm/config-edit-global:
commit: advertise config --global --edit on guessed identity
home_config_paths(): let the caller ignore xdg path
config --global --edit: create a template file if needed
Diffstat (limited to 'builtin/config.c')
-rw-r--r-- | builtin/config.c | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/builtin/config.c b/builtin/config.c index fcd8474701..aba71355f8 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -445,6 +445,20 @@ static int get_urlmatch(const char *var, const char *url) return 0; } +static char *default_user_config(void) +{ + struct strbuf buf = STRBUF_INIT; + strbuf_addf(&buf, + _("# This is Git's per-user configuration file.\n" + "[core]\n" + "# Please adapt and uncomment the following lines:\n" + "# user = %s\n" + "# email = %s\n"), + ident_default_name(), + ident_default_email()); + return strbuf_detach(&buf, NULL); +} + int cmd_config(int argc, const char **argv, const char *prefix) { int nongit = !startup_info->have_repository; @@ -551,6 +565,8 @@ int cmd_config(int argc, const char **argv, const char *prefix) } } else if (actions == ACTION_EDIT) { + const char *config_file = given_config_source.file ? + given_config_source.file : git_path("config"); check_argc(argc, 0, 0); if (!given_config_source.file && nongit) die("not in a git directory"); @@ -559,9 +575,18 @@ int cmd_config(int argc, const char **argv, const char *prefix) if (given_config_source.blob) die("editing blobs is not supported"); git_config(git_default_config, NULL); - launch_editor(given_config_source.file ? - given_config_source.file : git_path("config"), - NULL, NULL); + if (use_global_config) { + int fd = open(config_file, O_CREAT | O_EXCL | O_WRONLY, 0666); + if (fd) { + char *content = default_user_config(); + write_str_in_full(fd, content); + free(content); + close(fd); + } + else if (errno != EEXIST) + die_errno(_("cannot create configuration file %s"), config_file); + } + launch_editor(config_file, NULL, NULL); } else if (actions == ACTION_SET) { int ret; |