cherry-pick: do not error on non-merge commits when '-m 1' is specified
[gitweb.git] / setup.c
diff --git a/setup.c b/setup.c
index 72877796420b06213665f5d357decb202e71fa91..1be5037f129646cd46d3dc048e8f58dc3bdac0b9 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -3,6 +3,7 @@
 #include "config.h"
 #include "dir.h"
 #include "string-list.h"
+#include "chdir-notify.h"
 
 static int inside_git_dir = -1;
 static int inside_work_tree = -1;
@@ -378,7 +379,7 @@ int is_inside_work_tree(void)
 
 void setup_work_tree(void)
 {
-       const char *work_tree, *git_dir;
+       const char *work_tree;
        static int initialized = 0;
 
        if (initialized)
@@ -388,10 +389,7 @@ void setup_work_tree(void)
                die(_("unable to set up work tree using invalid config"));
 
        work_tree = get_git_work_tree();
-       git_dir = get_git_dir();
-       if (!is_absolute_path(git_dir))
-               git_dir = real_path(get_git_dir());
-       if (!work_tree || chdir(work_tree))
+       if (!work_tree || chdir_notify(work_tree))
                die(_("this operation must be run in a work tree"));
 
        /*
@@ -401,10 +399,23 @@ void setup_work_tree(void)
        if (getenv(GIT_WORK_TREE_ENVIRONMENT))
                setenv(GIT_WORK_TREE_ENVIRONMENT, ".", 1);
 
-       set_git_dir(remove_leading_path(git_dir, work_tree));
        initialized = 1;
 }
 
+static int read_worktree_config(const char *var, const char *value, void *vdata)
+{
+       struct repository_format *data = vdata;
+
+       if (strcmp(var, "core.bare") == 0) {
+               data->is_bare = git_config_bool(var, value);
+       } else if (strcmp(var, "core.worktree") == 0) {
+               if (!value)
+                       return config_error_nonbool(var);
+               data->work_tree = xstrdup(value);
+       }
+       return 0;
+}
+
 static int check_repo_format(const char *var, const char *value, void *vdata)
 {
        struct repository_format *data = vdata;
@@ -426,16 +437,13 @@ static int check_repo_format(const char *var, const char *value, void *vdata)
                        if (!value)
                                return config_error_nonbool(var);
                        data->partial_clone = xstrdup(value);
-               } else
+               } else if (!strcmp(ext, "worktreeconfig"))
+                       data->worktree_config = git_config_bool(var, value);
+               else
                        string_list_append(&data->unknown_extensions, ext);
-       } else if (strcmp(var, "core.bare") == 0) {
-               data->is_bare = git_config_bool(var, value);
-       } else if (strcmp(var, "core.worktree") == 0) {
-               if (!value)
-                       return config_error_nonbool(var);
-               data->work_tree = xstrdup(value);
        }
-       return 0;
+
+       return read_worktree_config(var, value, vdata);
 }
 
 static int check_repository_format_gently(const char *gitdir, struct repository_format *candidate, int *nongit_ok)
@@ -469,7 +477,20 @@ static int check_repository_format_gently(const char *gitdir, struct repository_
 
        repository_format_precious_objects = candidate->precious_objects;
        repository_format_partial_clone = candidate->partial_clone;
+       repository_format_worktree_config = candidate->worktree_config;
        string_list_clear(&candidate->unknown_extensions, 0);
+
+       if (repository_format_worktree_config) {
+               /*
+                * pick up core.bare and core.worktree from per-worktree
+                * config if present
+                */
+               strbuf_addf(&sb, "%s/config.worktree", gitdir);
+               git_config_from_file(read_worktree_config, sb.buf, candidate);
+               strbuf_release(&sb);
+               has_common = 0;
+       }
+
        if (!has_common) {
                if (candidate->is_bare != -1) {
                        is_bare_repository_cfg = candidate->is_bare;
@@ -542,7 +563,7 @@ void read_gitfile_error_die(int error_code, const char *path, const char *dir)
        case READ_GITFILE_ERR_NOT_A_REPO:
                die(_("not a git repository: %s"), dir);
        default:
-               die("BUG: unknown error code");
+               BUG("unknown error code");
        }
 }
 
@@ -1089,7 +1110,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
                      "Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set)."),
                    dir.buf);
        default:
-               die("BUG: unhandled setup_git_directory_1() result");
+               BUG("unhandled setup_git_directory_1() result");
        }
 
        if (prefix)
@@ -1116,8 +1137,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
                        const char *gitdir = getenv(GIT_DIR_ENVIRONMENT);
                        if (!gitdir)
                                gitdir = DEFAULT_GIT_DIR_ENVIRONMENT;
-                       repo_set_gitdir(the_repository, gitdir);
-                       setup_git_env();
+                       setup_git_env(gitdir);
                }
                if (startup_info->have_repository)
                        repo_set_hash_algo(the_repository, repo_fmt.hash_algo);