Re: builtin-clone does not fallback to copy when link fails
Show 9 quoted lines
>
> When cloning with the new builtin-clone, if the src repo is not
> on the same disk as the dest repo, cloning fails. This is because
> hard linking does not fall back to copying like the shell version
> did.
>
> The shell version also made a distinction between defaulting to
> hard linking and an explicit request to hard link. In the latter
> case it would not fall back to copying, but would die.
Something like this (if not too ugly) might do the trick:
diff --git a/builtin-clone.c b/builtin-clone.c
index 8713128..1062371 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -208,11 +208,17 @@ static void copy_or_link_directory(char *src, char *dest)
if (unlink(dest) && errno != ENOENT)
die("failed to unlink %s\n", dest);
if (option_no_hardlinks) {
+FALLBACK_TO_COPY:
if (copy_file(dest, src, 0666))
die("failed to copy file to %s\n", dest);
} else {
- if (link(src, dest))
+ if (link(src, dest)) {
+ if (errno == EXDEV && !option_local) {
+ option_no_hardlinks = 1;
+ goto FALLBACK_TO_COPY;
+ }
die("failed to create link %s\n", dest);
+ }
}
}
}