Skip to content

Commit 3ce650f

Browse files
committed
git-gui: default to full copy for linked worktrees
git-gui's default clone method is git-clone's default, and this uses hardlinks rather than copying the objects directory for local repositories. However, this method explicitly fails if a symlink (or .gitfile) exists in the path to the objects directory. Thus, the default clone option fails for worktrees created by git-new-workdir or git-worktree. git-gui's original do_clone trapped this error for a symlinked git-new-workdir tree, directly falling back to a full clone, while the updated git-gui using git-clone does not. (The old do_clone could not handle gitfile linked worktrees, however). Let's apply the more friendly fallback to a full clone in both these cases where git-clone behavior throws an error on the default method. Signed-off-by: Mark Levedahl <[email protected]>
1 parent 6ff8d68 commit 3ce650f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

lib/choose_repository.tcl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,25 @@ method _update_clone {args} {
557557
method _do_clone2 {} {
558558
if {[file isdirectory $origin_url]} {
559559
set origin_url [file normalize $origin_url]
560+
if {$clone_type eq {hardlink}} {
561+
# cannot use hardlinks if this is a linked worktree (.gitfile or git-new-workdir)
562+
if {[git -C $origin_url rev-parse --is-inside-work-tree] == {true}} {
563+
set islink 0
564+
set dotgit [file join $origin_url .git]
565+
if {[file isfile $dotgit]} {
566+
set islink 1
567+
} else {
568+
set objdir [file join $dotgit objects]
569+
if {[file exists $objdir] && [file type $objdir] == {link}} {
570+
set islink 1
571+
}
572+
}
573+
if {$islink} {
574+
info_popup [mc "Hardlinks are unavailable. Falling back to copying."]
575+
set clone_type full
576+
}
577+
}
578+
}
560579
}
561580

562581
if {$clone_type eq {hardlink} && ![file isdirectory $origin_url]} {

0 commit comments

Comments
 (0)