Code

Documentation: fix invalid reference to 'mybranch' in user manual
[git.git] / setup.c
diff --git a/setup.c b/setup.c
index 53580fde43ce01f12dc326b419d94573ea14787a..3b111ea7cf5f68ecca085f5a56421ea190e1771a 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -292,15 +292,16 @@ void setup_work_tree(void)
        work_tree = get_git_work_tree();
        git_dir = get_git_dir();
        if (!is_absolute_path(git_dir))
-               set_git_dir(make_absolute_path(git_dir));
+               git_dir = make_absolute_path(git_dir);
        if (!work_tree || chdir(work_tree))
                die("This operation must be run in a work tree");
+       set_git_dir(make_relative_path(git_dir, work_tree));
        initialized = 1;
 }
 
 static int check_repository_format_gently(int *nongit_ok)
 {
-       git_config(check_repository_format_version);
+       git_config(check_repository_format_version, NULL);
        if (GIT_REPO_VERSION < repository_format_version) {
                if (!nongit_ok)
                        die ("Expected git repo version <= %d, found %d",
@@ -475,24 +476,56 @@ const char *setup_git_directory_gently(int *nongit_ok)
 
 int git_config_perm(const char *var, const char *value)
 {
-       if (value) {
-               int i;
-               if (!strcmp(value, "umask"))
-                       return PERM_UMASK;
-               if (!strcmp(value, "group"))
-                       return PERM_GROUP;
-               if (!strcmp(value, "all") ||
-                   !strcmp(value, "world") ||
-                   !strcmp(value, "everybody"))
-                       return PERM_EVERYBODY;
-               i = atoi(value);
-               if (i > 1)
-                       return i;
+       int i;
+       char *endptr;
+
+       if (value == NULL)
+               return PERM_GROUP;
+
+       if (!strcmp(value, "umask"))
+               return PERM_UMASK;
+       if (!strcmp(value, "group"))
+               return PERM_GROUP;
+       if (!strcmp(value, "all") ||
+           !strcmp(value, "world") ||
+           !strcmp(value, "everybody"))
+               return PERM_EVERYBODY;
+
+       /* Parse octal numbers */
+       i = strtol(value, &endptr, 8);
+
+       /* If not an octal number, maybe true/false? */
+       if (*endptr != 0)
+               return git_config_bool(var, value) ? PERM_GROUP : PERM_UMASK;
+
+       /*
+        * Treat values 0, 1 and 2 as compatibility cases, otherwise it is
+        * a chmod value.
+        */
+       switch (i) {
+       case PERM_UMASK:               /* 0 */
+               return PERM_UMASK;
+       case OLD_PERM_GROUP:           /* 1 */
+               return PERM_GROUP;
+       case OLD_PERM_EVERYBODY:       /* 2 */
+               return PERM_EVERYBODY;
        }
-       return git_config_bool(var, value);
+
+       /* A filemode value was given: 0xxx */
+
+       if ((i & 0600) != 0600)
+               die("Problem with core.sharedRepository filemode value "
+                   "(0%.3o).\nThe owner of files must always have "
+                   "read and write permissions.", i);
+
+       /*
+        * Mask filemode value. Others can not get write permission.
+        * x flags for directories are handled separately.
+        */
+       return i & 0666;
 }
 
-int check_repository_format_version(const char *var, const char *value)
+int check_repository_format_version(const char *var, const char *value, void *cb)
 {
        if (strcmp(var, "core.repositoryformatversion") == 0)
                repository_format_version = git_config_int(var, value);