Skip to content

Commit bba2875

Browse files
committed
Merge branch 'jc/maint-checkout-index-to-prefix' into maint
* jc/maint-checkout-index-to-prefix: check_path(): allow symlinked directories to checkout-index --prefix
2 parents 4197ce3 + da02ca5 commit bba2875

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ extern int index_path(unsigned char *sha1, const char *path, struct stat *st, in
469469
extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);
470470

471471
/* "careful lstat()" */
472-
extern int check_path(const char *path, int len, struct stat *st);
472+
extern int check_path(const char *path, int len, struct stat *st, int skiplen);
473473

474474
#define REFRESH_REALLY 0x0001 /* ignore_valid */
475475
#define REFRESH_UNMERGED 0x0002 /* allow unmerged */

entry.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,15 @@ static int write_entry(struct cache_entry *ce, char *path, const struct checkout
177177

178178
/*
179179
* This is like 'lstat()', except it refuses to follow symlinks
180-
* in the path.
180+
* in the path, after skipping "skiplen".
181181
*/
182-
int check_path(const char *path, int len, struct stat *st)
182+
int check_path(const char *path, int len, struct stat *st, int skiplen)
183183
{
184-
if (has_symlink_leading_path(path, len)) {
184+
const char *slash = path + len;
185+
186+
while (path < slash && *slash != '/')
187+
slash--;
188+
if (!has_dirs_only_path(path, slash - path, skiplen)) {
185189
errno = ENOENT;
186190
return -1;
187191
}
@@ -201,7 +205,7 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *t
201205
strcpy(path + len, ce->name);
202206
len += ce_namelen(ce);
203207

204-
if (!check_path(path, len, &st)) {
208+
if (!check_path(path, len, &st, state->base_dir_len)) {
205209
unsigned changed = ce_match_stat(ce, &st, CE_MATCH_IGNORE_VALID);
206210
if (!changed)
207211
return 0;

t/t2000-checkout-cache-clash.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,13 @@ test_expect_success \
4848
'git checkout-index conflicting paths.' \
4949
'test -f path0 && test -d path1 && test -f path1/file1'
5050

51+
test_expect_success SYMLINKS 'checkout-index -f twice with --prefix' '
52+
mkdir -p tar/get &&
53+
ln -s tar/get there &&
54+
echo first &&
55+
git checkout-index -a -f --prefix=there/ &&
56+
echo second &&
57+
git checkout-index -a -f --prefix=there/
58+
'
59+
5160
test_done

0 commit comments

Comments
 (0)