Skip to content

Commit 2202b8b

Browse files
HenriGEISTpatthoyts
authored andcommitted
git-gui: Add a 'recursive' checkbox in the clone menu.
Permit to do a 'git clone --recursive' through git-gui. Add a 'recursive' checkbox in the clone menu which allows users to clone a repository and all its submodules in one go (unless the 'update' flag is set to "none" in the .gitmodules file for a submodule, in that case that specific submodule is not cloned automatically). Enable this new option per default, as most users want to clone all submodules too when cloning the superproject (This is currently not possible without leaving git gui or adding a custom tool entry for that). Signed-off-by: Henri GEIST <[email protected]> Thanks-to: Jens Lehmann <[email protected]> Signed-off-by: Pat Thoyts <[email protected]>
1 parent 3decb8e commit 2202b8b

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

lib/choose_repository.tcl

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ field local_path {} ; # Where this repository is locally
1818
field origin_url {} ; # Where we are cloning from
1919
field origin_name origin ; # What we shall call 'origin'
2020
field clone_type hardlink ; # Type of clone to construct
21+
field recursive true ; # Recursive cloning flag
2122
field readtree_err ; # Error output from read-tree (if any)
2223
field sorted_recent ; # recent repositories (sorted)
2324

@@ -525,6 +526,11 @@ method _do_clone {} {
525526
foreach r $w_types {
526527
pack $r -anchor w
527528
}
529+
${NS}::checkbutton $args.type_f.recursive \
530+
-text [mc "Recursively clone submodules too"] \
531+
-variable @recursive \
532+
-onvalue true -offvalue false
533+
pack $args.type_f.recursive
528534
grid $args.type_l $args.type_f -sticky new
529535

530536
grid columnconfigure $args 1 -weight 1
@@ -952,6 +958,30 @@ method _do_clone_checkout {HEAD} {
952958
fileevent $fd readable [cb _readtree_wait $fd]
953959
}
954960

961+
method _do_validate_submodule_cloning {ok} {
962+
if {$ok} {
963+
$o_cons done $ok
964+
set done 1
965+
} else {
966+
_clone_failed $this [mc "Cannot clone submodules."]
967+
}
968+
}
969+
970+
method _do_clone_submodules {} {
971+
if {$recursive eq {true}} {
972+
destroy $w_body
973+
set o_cons [console::embed \
974+
$w_body \
975+
[mc "Cloning submodules"]]
976+
pack $w_body -fill both -expand 1 -padx 10
977+
$o_cons exec \
978+
[list git submodule update --init --recursive] \
979+
[cb _do_validate_submodule_cloning]
980+
} else {
981+
set done 1
982+
}
983+
}
984+
955985
method _readtree_wait {fd} {
956986
set buf [read $fd]
957987
$o_cons update_meter $buf
@@ -982,7 +1012,7 @@ method _readtree_wait {fd} {
9821012
fconfigure $fd_ph -blocking 0 -translation binary -eofchar {}
9831013
fileevent $fd_ph readable [cb _postcheckout_wait $fd_ph]
9841014
} else {
985-
set done 1
1015+
_do_clone_submodules $this
9861016
}
9871017
}
9881018

@@ -996,7 +1026,7 @@ method _postcheckout_wait {fd_ph} {
9961026
hook_failed_popup post-checkout $pch_error 0
9971027
}
9981028
unset pch_error
999-
set done 1
1029+
_do_clone_submodules $this
10001030
return
10011031
}
10021032
fconfigure $fd_ph -blocking 0

0 commit comments

Comments
 (0)