summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2011-03-27 03:13:16 (GMT)
committerJunio C Hamano <gitster@pobox.com>2011-03-27 03:13:16 (GMT)
commitad7bb2f68c0b7786521173e05ef58d0f3e0db3d7 (patch)
tree9fc6b2df2743b837f774c0ce925cdad2427c4535
parent54f6a8dbd65cbe6ad31a8b6b531de81009514eb3 (diff)
parent90a6464b4ad5887e4d12e660f51dabdbd5c00812 (diff)
downloadgit-ad7bb2f68c0b7786521173e05ef58d0f3e0db3d7.zip
git-ad7bb2f68c0b7786521173e05ef58d0f3e0db3d7.tar.gz
git-ad7bb2f68c0b7786521173e05ef58d0f3e0db3d7.tar.bz2
Merge branch 'jc/maint-rerere-in-workdir'
* jc/maint-rerere-in-workdir: rerere: make sure it works even in a workdir attached to a young repository
-rw-r--r--cache.h1
-rw-r--r--rerere.c3
-rw-r--r--sha1_file.c29
-rwxr-xr-xt/t1021-rerere-in-workdir.sh55
4 files changed, 86 insertions, 2 deletions
diff --git a/cache.h b/cache.h
index f765cf5..abef5b6 100644
--- a/cache.h
+++ b/cache.h
@@ -726,6 +726,7 @@ int set_shared_perm(const char *path, int mode);
#define adjust_shared_perm(path) set_shared_perm((path), 0)
int safe_create_leading_directories(char *path);
int safe_create_leading_directories_const(const char *path);
+int mkdir_in_gitdir(const char *path);
extern char *expand_user_path(const char *path);
char *enter_repo(char *path, int strict);
static inline int is_absolute_path(const char *path)
diff --git a/rerere.c b/rerere.c
index 22996bd..3d00a71 100644
--- a/rerere.c
+++ b/rerere.c
@@ -590,8 +590,7 @@ static int is_rerere_enabled(void)
if (rerere_enabled < 0)
return rr_cache_exists;
- if (!rr_cache_exists &&
- (mkdir(rr_cache, 0777) || adjust_shared_perm(rr_cache)))
+ if (!rr_cache_exists && mkdir_in_gitdir(rr_cache))
die("Could not create directory %s", rr_cache);
return 1;
}
diff --git a/sha1_file.c b/sha1_file.c
index 7829d61..df0edba 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -68,6 +68,35 @@ static struct cached_object *find_cached_object(const unsigned char *sha1)
return NULL;
}
+int mkdir_in_gitdir(const char *path)
+{
+ if (mkdir(path, 0777)) {
+ int saved_errno = errno;
+ struct stat st;
+ struct strbuf sb = STRBUF_INIT;
+
+ if (errno != EEXIST)
+ return -1;
+ /*
+ * Are we looking at a path in a symlinked worktree
+ * whose original repository does not yet have it?
+ * e.g. .git/rr-cache pointing at its original
+ * repository in which the user hasn't performed any
+ * conflict resolution yet?
+ */
+ if (lstat(path, &st) || !S_ISLNK(st.st_mode) ||
+ strbuf_readlink(&sb, path, st.st_size) ||
+ !is_absolute_path(sb.buf) ||
+ mkdir(sb.buf, 0777)) {
+ strbuf_release(&sb);
+ errno = saved_errno;
+ return -1;
+ }
+ strbuf_release(&sb);
+ }
+ return adjust_shared_perm(path);
+}
+
int safe_create_leading_directories(char *path)
{
char *pos = path + offset_1st_component(path);
diff --git a/t/t1021-rerere-in-workdir.sh b/t/t1021-rerere-in-workdir.sh
new file mode 100755
index 0000000..301e071
--- /dev/null
+++ b/t/t1021-rerere-in-workdir.sh
@@ -0,0 +1,55 @@
+#!/bin/sh
+
+test_description='rerere run in a workdir'
+. ./test-lib.sh
+
+test_expect_success SYMLINKS setup '
+ git config rerere.enabled true &&
+ >world &&
+ git add world &&
+ test_tick &&
+ git commit -m initial &&
+
+ echo hello >world &&
+ test_tick &&
+ git commit -a -m hello &&
+
+ git checkout -b side HEAD^ &&
+ echo goodbye >world &&
+ test_tick &&
+ git commit -a -m goodbye &&
+
+ git checkout master
+'
+
+test_expect_success SYMLINKS 'rerere in workdir' '
+ rm -rf .git/rr-cache &&
+ "$SHELL_PATH" "$TEST_DIRECTORY/../contrib/workdir/git-new-workdir" . work &&
+ (
+ cd work &&
+ test_must_fail git merge side &&
+ git rerere status >actual &&
+ echo world >expect &&
+ test_cmp expect actual
+ )
+'
+
+# This fails because we don't resolve relative symlink in mkdir_in_gitdir()
+# For the purpose of helping contrib/workdir/git-new-workdir users, we do not
+# have to support relative symlinks, but it might be nicer to make this work
+# with a relative symbolic link someday.
+test_expect_failure SYMLINKS 'rerere in workdir (relative)' '
+ rm -rf .git/rr-cache &&
+ "$SHELL_PATH" "$TEST_DIRECTORY/../contrib/workdir/git-new-workdir" . krow &&
+ (
+ cd krow &&
+ rm -f .git/rr-cache &&
+ ln -s ../.git/rr-cache .git/rr-cache &&
+ test_must_fail git merge side &&
+ git rerere status >actual &&
+ echo world >expect &&
+ test_cmp expect actual
+ )
+'
+
+test_done