Code

Merge branch 'jn/setup-fixes' into next
authorJunio C Hamano <gitster@pobox.com>
Fri, 21 Jan 2011 22:38:37 +0000 (14:38 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 21 Jan 2011 22:38:37 +0000 (14:38 -0800)
* jn/setup-fixes:
  Subject: setup: officially support --work-tree without --git-dir
  tests: compress the setup tests
  tests: cosmetic improvements to the repo-setup test

1  2 
setup.c

diff --combined setup.c
index 424716be8ccdd8cbefdf78427934c361125aeda8,dadc66659a4037b614b215b7f812c4df8969562b..021d0133ae1d6cf7f3a6a8284cb5b6e9a42dbe0d
+++ b/setup.c
@@@ -7,13 -7,10 +7,13 @@@ static int inside_work_tree = -1
  char *prefix_path(const char *prefix, int len, const char *path)
  {
        const char *orig = path;
 -      char *sanitized = xmalloc(len + strlen(path) + 1);
 -      if (is_absolute_path(orig))
 -              strcpy(sanitized, path);
 -      else {
 +      char *sanitized;
 +      if (is_absolute_path(orig)) {
 +              const char *temp = make_absolute_path(path);
 +              sanitized = xmalloc(len + strlen(temp) + 1);
 +              strcpy(sanitized, temp);
 +      } else {
 +              sanitized = xmalloc(len + strlen(path) + 1);
                if (len)
                        memcpy(sanitized, prefix, len);
                strcpy(sanitized + len, path);
@@@ -414,6 -411,15 +414,15 @@@ static const char *setup_discovered_git
        if (check_repository_format_gently(gitdir, nongit_ok))
                return NULL;
  
+       /* --work-tree is set without --git-dir; use discovered one */
+       if (getenv(GIT_WORK_TREE_ENVIRONMENT) || git_work_tree_cfg) {
+               if (offset != len && !is_absolute_path(gitdir))
+                       gitdir = xstrdup(make_absolute_path(gitdir));
+               if (chdir(cwd))
+                       die_errno("Could not come back to cwd");
+               return setup_explicit_git_dir(gitdir, cwd, len, nongit_ok);
+       }
        /* #16.2, #17.2, #20.2, #21.2, #24, #25, #28, #29 (see t1510) */
        if (is_bare_repository_cfg > 0) {
                set_git_dir(offset == len ? gitdir : make_absolute_path(gitdir));
@@@ -446,6 -452,16 +455,16 @@@ static const char *setup_bare_git_dir(c
        if (check_repository_format_gently(".", nongit_ok))
                return NULL;
  
+       /* --work-tree is set without --git-dir; use discovered one */
+       if (getenv(GIT_WORK_TREE_ENVIRONMENT) || git_work_tree_cfg) {
+               const char *gitdir;
+               gitdir = offset == len ? "." : xmemdupz(cwd, offset);
+               if (chdir(cwd))
+                       die_errno("Could not come back to cwd");
+               return setup_explicit_git_dir(gitdir, cwd, len, nongit_ok);
+       }
        inside_git_dir = 1;
        inside_work_tree = 0;
        if (offset != len) {