Merge branch 'gc/better-error-when-local-clone-fails-with-symlink'
"git clone --local" stops copying from an original repository that has symbolic links inside its $GIT_DIR; an error message when that happens has been updated. * gc/better-error-when-local-clone-fails-with-symlink: clone: error specifically with --local and symlinked objects
This commit is contained in:
commit
a4a4db8cf7
@ -58,6 +58,11 @@ never use the local optimizations). Specifying `--no-local` will
|
|||||||
override the default when `/path/to/repo` is given, using the regular
|
override the default when `/path/to/repo` is given, using the regular
|
||||||
Git transport instead.
|
Git transport instead.
|
||||||
+
|
+
|
||||||
|
If the repository's `$GIT_DIR/objects` has symbolic links or is a
|
||||||
|
symbolic link, the clone will fail. This is a security measure to
|
||||||
|
prevent the unintentional copying of files by dereferencing the symbolic
|
||||||
|
links.
|
||||||
|
+
|
||||||
*NOTE*: this operation can race with concurrent modification to the
|
*NOTE*: this operation can race with concurrent modification to the
|
||||||
source repository, similar to running `cp -r src dst` while modifying
|
source repository, similar to running `cp -r src dst` while modifying
|
||||||
`src`.
|
`src`.
|
||||||
|
@ -331,8 +331,18 @@ static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest,
|
|||||||
|
|
||||||
iter = dir_iterator_begin(src->buf, DIR_ITERATOR_PEDANTIC);
|
iter = dir_iterator_begin(src->buf, DIR_ITERATOR_PEDANTIC);
|
||||||
|
|
||||||
if (!iter)
|
if (!iter) {
|
||||||
|
if (errno == ENOTDIR) {
|
||||||
|
int saved_errno = errno;
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
|
if (!lstat(src->buf, &st) && S_ISLNK(st.st_mode))
|
||||||
|
die(_("'%s' is a symlink, refusing to clone with --local"),
|
||||||
|
src->buf);
|
||||||
|
errno = saved_errno;
|
||||||
|
}
|
||||||
die_errno(_("failed to start iterator over '%s'"), src->buf);
|
die_errno(_("failed to start iterator over '%s'"), src->buf);
|
||||||
|
}
|
||||||
|
|
||||||
strbuf_addch(src, '/');
|
strbuf_addch(src, '/');
|
||||||
src_len = src->len;
|
src_len = src->len;
|
||||||
|
@ -358,7 +358,7 @@ test_expect_success SYMLINKS 'clone repo with symlinked objects directory' '
|
|||||||
test_must_fail git clone --local malicious clone 2>err &&
|
test_must_fail git clone --local malicious clone 2>err &&
|
||||||
|
|
||||||
test_path_is_missing clone &&
|
test_path_is_missing clone &&
|
||||||
grep "failed to start iterator over" err
|
grep "is a symlink, refusing to clone with --local" err
|
||||||
'
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
Loading…
Reference in New Issue
Block a user