Merge branch 'jg/prompt-localize-temporary'
[gitweb.git] / builtin / config.c
index d11105d9070c9aaf4c5170715a4a53ce091dc094..15a7bea936d667042cef27f83c86a863df2caa8f 100644 (file)
@@ -450,6 +450,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) {
+               char *config_file;
+
                check_argc(argc, 0, 0);
                if (!given_config_source.file && nongit)
                        die("not in a git directory");
@@ -559,9 +575,21 @@ 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);
+               config_file = xstrdup(given_config_source.file ?
+                                     given_config_source.file : git_path("config"));
+               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);
+               free(config_file);
        }
        else if (actions == ACTION_SET) {
                int ret;