Merge branch 'jp/symlink-dirs' into maint
* jp/symlink-dirs: t6035-merge-dir-to-symlink depends on SYMLINKS prerequisite git-checkout: be careful about untracked symlinks lstat_cache: guard against full match of length of 'name' parameter Demonstrate bugs when a directory is replaced with a symlink
This commit is contained in:
commit
6dfa21309f
3
cache.h
3
cache.h
@ -468,6 +468,9 @@ extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_obje
|
||||
extern int index_path(unsigned char *sha1, const char *path, struct stat *st, int write_object);
|
||||
extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);
|
||||
|
||||
/* "careful lstat()" */
|
||||
extern int check_path(const char *path, int len, struct stat *st);
|
||||
|
||||
#define REFRESH_REALLY 0x0001 /* ignore_valid */
|
||||
#define REFRESH_UNMERGED 0x0002 /* allow unmerged */
|
||||
#define REFRESH_QUIET 0x0004 /* be quiet about it */
|
||||
|
15
entry.c
15
entry.c
@ -175,6 +175,19 @@ static int write_entry(struct cache_entry *ce, char *path, const struct checkout
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* This is like 'lstat()', except it refuses to follow symlinks
|
||||
* in the path.
|
||||
*/
|
||||
int check_path(const char *path, int len, struct stat *st)
|
||||
{
|
||||
if (has_symlink_leading_path(path, len)) {
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
return lstat(path, st);
|
||||
}
|
||||
|
||||
int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath)
|
||||
{
|
||||
static char path[PATH_MAX + 1];
|
||||
@ -188,7 +201,7 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *t
|
||||
strcpy(path + len, ce->name);
|
||||
len += ce_namelen(ce);
|
||||
|
||||
if (!lstat(path, &st)) {
|
||||
if (!check_path(path, len, &st)) {
|
||||
unsigned changed = ce_match_stat(ce, &st, CE_MATCH_IGNORE_VALID);
|
||||
if (!changed)
|
||||
return 0;
|
||||
|
@ -91,6 +91,10 @@ static int lstat_cache(struct cache_def *cache, const char *name, int len,
|
||||
longest_path_match(name, len, cache->path, cache->len,
|
||||
&previous_slash);
|
||||
match_flags = cache->flags & track_flags & (FL_NOENT|FL_SYMLINK);
|
||||
|
||||
if (!(track_flags & FL_FULLPATH) && match_len == len)
|
||||
match_len = last_slash = previous_slash;
|
||||
|
||||
if (match_flags && match_len == cache->len)
|
||||
return match_flags;
|
||||
/*
|
||||
|
93
t/t6035-merge-dir-to-symlink.sh
Executable file
93
t/t6035-merge-dir-to-symlink.sh
Executable file
@ -0,0 +1,93 @@
|
||||
#!/bin/sh
|
||||
|
||||
test_description='merging when a directory was replaced with a symlink'
|
||||
. ./test-lib.sh
|
||||
|
||||
if ! test_have_prereq SYMLINKS
|
||||
then
|
||||
say 'Symbolic links not supported, skipping tests.'
|
||||
test_done
|
||||
fi
|
||||
|
||||
test_expect_success 'create a commit where dir a/b changed to symlink' '
|
||||
mkdir -p a/b/c a/b-2/c &&
|
||||
> a/b/c/d &&
|
||||
> a/b-2/c/d &&
|
||||
> a/x &&
|
||||
git add -A &&
|
||||
git commit -m base &&
|
||||
git tag start &&
|
||||
rm -rf a/b &&
|
||||
ln -s b-2 a/b &&
|
||||
git add -A &&
|
||||
git commit -m "dir to symlink"
|
||||
'
|
||||
|
||||
test_expect_success 'keep a/b-2/c/d across checkout' '
|
||||
git checkout HEAD^0 &&
|
||||
git reset --hard master &&
|
||||
git rm --cached a/b &&
|
||||
git commit -m "untracked symlink remains" &&
|
||||
git checkout start^0 &&
|
||||
test -f a/b-2/c/d
|
||||
'
|
||||
|
||||
test_expect_success 'checkout should not have deleted a/b-2/c/d' '
|
||||
git checkout HEAD^0 &&
|
||||
git reset --hard master &&
|
||||
git checkout start^0 &&
|
||||
test -f a/b-2/c/d
|
||||
'
|
||||
|
||||
test_expect_success 'setup for merge test' '
|
||||
git reset --hard &&
|
||||
test -f a/b-2/c/d &&
|
||||
echo x > a/x &&
|
||||
git add a/x &&
|
||||
git commit -m x &&
|
||||
git tag baseline
|
||||
'
|
||||
|
||||
test_expect_success 'do not lose a/b-2/c/d in merge (resolve)' '
|
||||
git reset --hard &&
|
||||
git checkout baseline^0 &&
|
||||
git merge -s resolve master &&
|
||||
test -h a/b &&
|
||||
test -f a/b-2/c/d
|
||||
'
|
||||
|
||||
test_expect_failure 'do not lose a/b-2/c/d in merge (recursive)' '
|
||||
git reset --hard &&
|
||||
git checkout baseline^0 &&
|
||||
git merge -s recursive master &&
|
||||
test -h a/b &&
|
||||
test -f a/b-2/c/d
|
||||
'
|
||||
|
||||
test_expect_success 'setup a merge where dir a/b-2 changed to symlink' '
|
||||
git reset --hard &&
|
||||
git checkout start^0 &&
|
||||
rm -rf a/b-2 &&
|
||||
ln -s b a/b-2 &&
|
||||
git add -A &&
|
||||
git commit -m "dir a/b-2 to symlink" &&
|
||||
git tag test2
|
||||
'
|
||||
|
||||
test_expect_failure 'merge should not have conflicts (resolve)' '
|
||||
git reset --hard &&
|
||||
git checkout baseline^0 &&
|
||||
git merge -s resolve test2 &&
|
||||
test -h a/b-2 &&
|
||||
test -f a/b/c/d
|
||||
'
|
||||
|
||||
test_expect_failure 'merge should not have conflicts (recursive)' '
|
||||
git reset --hard &&
|
||||
git checkout baseline^0 &&
|
||||
git merge -s recursive test2 &&
|
||||
test -h a/b-2 &&
|
||||
test -f a/b/c/d
|
||||
'
|
||||
|
||||
test_done
|
Loading…
Reference in New Issue
Block a user