1 # git-gui Git repository chooser
2 # Copyright (C) 2007 Shawn Pearce
4 class choose_repository
{
8 field w_body
; # Widget holding the center content
9 field w_next
; # Next button
10 field w_quit
; # Quit button
11 field o_cons
; # Console object (if active)
13 # Status mega-widget instance during _do_clone2 (used by _copy_files and
14 # _link_files). Widget is destroyed before _do_clone2 calls
18 # Operation displayed by status mega-widget during _do_clone_checkout =>
19 # _readtree_wait => _postcheckout_wait => _do_clone_submodules =>
20 # _do_validate_submodule_cloning. The status mega-widget is a different
21 # instance than that stored in $o_status in earlier operations.
24 field w_types
; # List of type buttons in clone
25 field w_recentlist
; # Listbox containing recent repositories
26 field w_localpath
; # Entry widget bound to local_path
28 field done
0 ; # Finished picking the repository?
29 field local_path
{} ; # Where this repository is locally
30 field origin_url
{} ; # Where we are cloning from
31 field origin_name origin
; # What we shall call 'origin'
32 field clone_type hardlink
; # Type of clone to construct
33 field recursive true
; # Recursive cloning flag
34 field readtree_err
; # Error output from read-tree (if any)
35 field sorted_recent
; # recent repositories (sorted)
38 global M1T M1B use_ttk NS
40 if {[set maxrecent
[get_config gui.maxrecentrepo
]] eq
{}} {
45 wm title
$top [mc
"Git Gui"]
48 menu $w.mbar
-tearoff 0
49 $top configure
-menu $w.mbar
51 set m_repo
$w.mbar.repository
53 -label [mc Repository
] \
58 $w.mbar add cascade
-label Apple
-menu .mbar.apple
60 $w.mbar.apple add command
\
61 -label [mc
"About %s" [appname
]] \
63 $w.mbar.apple add command
\
64 -label [mc
"Show SSH Key"] \
67 $w.mbar add cascade
-label [mc Help
] -menu $w.mbar.help
69 $w.mbar.help add command
\
70 -label [mc
"About %s" [appname
]] \
72 $w.mbar.help add command
\
73 -label [mc
"Show SSH Key"] \
77 wm protocol
$top WM_DELETE_WINDOW
exit
78 bind $top <$M1B-q
> exit
79 bind $top <$M1B-Q
> exit
80 bind $top <Key-Escape
> exit
82 wm geometry
$top "+[winfo rootx .]+[winfo rooty .]"
83 bind $top <Key-Escape
> [list destroy $top]
87 pack [git_logo
$w.git_logo
] -side left
-fill y
-padx 10 -pady 10
90 set opts
$w_body.
options
93 -cursor $::cursor_ptr \
95 -background [get_bg_color
$w_body] \
100 pack $opts -anchor w
-fill x
102 $opts tag conf link_new
-foreground blue
-underline 1
103 $opts tag
bind link_new
<1> [cb _next new
]
104 $opts insert end
[mc
"Create New Repository"] link_new
105 $opts insert end
"\n"
107 $m_repo add command
\
108 -command [cb _next new
] \
109 -accelerator $M1T-N
\
111 bind $top <$M1B-n
> [cb _next new
]
112 bind $top <$M1B-N
> [cb _next new
]
115 $opts tag conf link_clone
-foreground blue
-underline 1
116 $opts tag
bind link_clone
<1> [cb _next clone
]
117 $opts insert end
[mc
"Clone Existing Repository"] link_clone
118 $opts insert end
"\n"
120 if {[tk windowingsystem
] eq
"win32"} {
125 $m_repo add command
\
126 -command [cb _next clone
] \
127 -accelerator $M1T-$key \
128 -label [mc
"Clone..."]
129 bind $top <$M1B-[string tolower
$key]> [cb _next clone
]
130 bind $top <$M1B-[string toupper
$key]> [cb _next clone
]
133 $opts tag conf link_open
-foreground blue
-underline 1
134 $opts tag
bind link_open
<1> [cb _next
open]
135 $opts insert end
[mc
"Open Existing Repository"] link_open
136 $opts insert end
"\n"
138 $m_repo add command
\
139 -command [cb _next
open] \
140 -accelerator $M1T-O
\
141 -label [mc
"Open..."]
142 bind $top <$M1B-o
> [cb _next
open]
143 bind $top <$M1B-O
> [cb _next
open]
146 $opts conf
-state disabled
148 set sorted_recent
[_get_recentrepos
]
149 if {[llength $sorted_recent] > 0} {
151 $m_repo add separator
152 $m_repo add command
\
154 -label [mc
"Recent Repositories"]
157 if {[set lenrecent
[llength $sorted_recent]] < $maxrecent} {
158 set lenrecent
$maxrecent
161 ${NS
}::label $w_body.space
162 ${NS
}::label $w_body.recentlabel
\
164 -text [mc
"Open Recent Repository:"]
165 set w_recentlist
$w_body.recentlist
167 -cursor $::cursor_ptr \
169 -background [get_bg_color
$w_body.recentlabel
] \
173 $w_recentlist tag conf link
\
176 set home
$::env(HOME
)
178 set home
[exec cygpath
--windows --absolute $home]
180 set home
"[file normalize $home]/"
181 set hlen
[string length
$home]
182 foreach p
$sorted_recent {
184 if {[string equal
-length $hlen $home $p]} {
185 set p
"~/[string range $p $hlen end]"
187 regsub -all "\n" $p "\\n" p
188 $w_recentlist insert end
$p link
189 $w_recentlist insert end
"\n"
192 $m_repo add command
\
193 -command [cb _open_recent_path
$path] \
197 $w_recentlist conf
-state disabled
198 $w_recentlist tag
bind link
<1> [cb _open_recent
%x
,%y
]
199 pack $w_body.space
-anchor w
-fill x
200 pack $w_body.recentlabel
-anchor w
-fill x
201 pack $w_recentlist -anchor w
-fill x
203 pack $w_body -fill x
-padx 10 -pady 10
205 ${NS
}::frame $w.buttons
206 set w_next
$w.buttons.next
207 set w_quit
$w.buttons.quit
208 ${NS
}::button $w_quit \
211 pack $w_quit -side right
-padx 5
212 pack $w.buttons
-side bottom
-fill x
-padx 10 -pady 10
215 $m_repo add separator
216 $m_repo add command
\
222 bind $top <Return
> [cb _invoke_next
]
223 bind $top <Visibility
> "
227 bind $top <Visibility> {}
230 tkwait variable @done
234 eval destroy [winfo children
$top]
239 set nx
[winfo reqwidth
$top]
240 set ny
[winfo reqheight
$top]
241 set rx
[expr {([winfo screenwidth
$top] - $nx) / 3}]
242 set ry
[expr {([winfo screenheight
$top] - $ny) / 3}]
243 wm geometry
$top [format {+%d
+%d
} $rx $ry]
246 method _invoke_next
{} {
247 if {[winfo exists
$w_next]} {
248 uplevel #0 [$w_next cget -command]
252 proc _get_recentrepos
{} {
254 foreach p
[lsort -unique [get_config gui.recentrepo
]] {
255 if {[_is_git
[file join $p .git
]]} {
264 proc _unset_recentrepo
{p
} {
265 regsub -all -- {([()\[\]{}\.^
$+*?
\\])} $p {\\\1} p
266 catch {git config
--global --unset-all gui.recentrepo
"^$p\$"}
270 proc _append_recentrepos
{path
} {
271 set path
[file normalize
$path]
272 set recent
[get_config gui.recentrepo
]
274 if {[lindex $recent end
] eq
$path} {
278 set i
[lsearch $recent $path]
280 _unset_recentrepo
$path
283 git config
--global --add gui.recentrepo
$path
285 set recent
[get_config gui.recentrepo
]
287 if {[set maxrecent
[get_config gui.maxrecentrepo
]] eq
{}} {
291 while {[llength $recent] > $maxrecent} {
292 _unset_recentrepo
[lindex $recent 0]
293 set recent
[get_config gui.recentrepo
]
297 method _open_recent
{xy
} {
298 set id
[lindex [split [$w_recentlist index
@$xy] .
] 0]
299 set local_path
[lindex $sorted_recent [expr {$id - 1}]]
303 method _open_recent_path
{p
} {
308 method _next
{action
} {
311 if {![winfo exists
$w_next]} {
312 ${NS
}::button $w_next -default active
314 if {[tk windowingsystem
] eq
"win32"} { set pos
-after }
315 pack $w_next -side right
-padx 5 $pos $w_quit
320 method _write_local_path
{args
} {
321 if {$local_path eq
{}} {
322 $w_next conf
-state disabled
324 $w_next conf
-state normal
328 method _git_init
{} {
329 if {[catch {file mkdir
$local_path} err
]} {
330 error_popup
[strcat
\
331 [mc
"Failed to create repository %s:" $local_path] \
336 if {[catch {cd $local_path} err
]} {
337 error_popup
[strcat
\
338 [mc
"Failed to create repository %s:" $local_path] \
343 if {[catch {git init
} err
]} {
344 error_popup
[strcat
\
345 [mc
"Failed to create repository %s:" $local_path] \
350 _append_recentrepos
[pwd]
356 proc _is_git
{path
{outdir_var
""}} {
357 if {$outdir_var ne
""} {
358 upvar 1 $outdir_var outdir
360 if {[catch {set outdir
[git rev-parse
--resolve-git
-dir
$path]}]} {
366 proc _objdir
{path
} {
367 set objdir
[file join $path .git objects
]
368 if {[file isdirectory
$objdir]} {
372 set objdir
[file join $path objects
]
373 if {[file isdirectory
$objdir]} {
378 set objdir
[file join $path .git objects.lnk
]
379 if {[file isfile
$objdir]} {
380 return [win32_read_lnk
$objdir]
383 set objdir
[file join $path objects.lnk
]
384 if {[file isfile
$objdir]} {
385 return [win32_read_lnk
$objdir]
392 ######################################################################
394 ## Create New Repository
400 -command [cb _do_new2
] \
404 ${NS
}::label $w_body.h
\
405 -font font_uibold
-anchor center
\
406 -text [mc
"Create New Repository"]
407 pack $w_body.h
-side top
-fill x
-pady 10
408 pack $w_body -fill x
-padx 10
410 ${NS
}::frame $w_body.where
411 ${NS
}::label $w_body.where.l
-text [mc
"Directory:"]
412 ${NS
}::entry $w_body.where.t
\
413 -textvariable @local_path
\
415 ${NS
}::button $w_body.where.b
\
416 -text [mc
"Browse"] \
417 -command [cb _new_local_path
]
418 set w_localpath
$w_body.where.t
420 grid $w_body.where.l
$w_body.where.t
$w_body.where.b
-sticky ew
421 pack $w_body.where
-fill x
423 grid columnconfigure
$w_body.where
1 -weight 1
425 trace add
variable @local_path write
[cb _write_local_path
]
426 bind $w_body.h
<Destroy
> [list trace remove
variable @local_path write
[cb _write_local_path
]]
428 focus $w_body.where.t
431 method _new_local_path
{} {
432 if {$local_path ne
{}} {
433 set p
[file dirname
$local_path]
438 set p
[tk_chooseDirectory \
441 -title [mc
"Git Repository"] \
445 set p
[file normalize
$p]
450 $w_localpath icursor end
454 if {![_new_ok
$local_path]} {
457 if {![_git_init
$this]} {
464 if {[file isdirectory
$p]} {
465 if {[_is_git
[file join $p .git
]]} {
466 error_popup
[mc
"Directory %s already exists." $p]
469 } elseif
{[file exists
$p]} {
470 error_popup
[mc
"File %s already exists." $p]
476 ######################################################################
478 ## Clone Existing Repository
480 method _do_clone
{} {
484 -command [cb _do_clone2
] \
488 ${NS
}::label $w_body.h
\
489 -font font_uibold
-anchor center
\
490 -text [mc
"Clone Existing Repository"]
491 pack $w_body.h
-side top
-fill x
-pady 10
492 pack $w_body -fill x
-padx 10
494 set args
$w_body.args
495 ${NS
}::frame $w_body.args
496 pack $args -fill both
498 ${NS
}::label $args.origin_l
-text [mc
"Source Location:"]
499 ${NS
}::entry $args.origin_t
\
500 -textvariable @origin_url
\
502 ${NS
}::button $args.origin_b
\
503 -text [mc
"Browse"] \
504 -command [cb _open_origin
]
505 grid $args.origin_l
$args.origin_t
$args.origin_b
-sticky ew
507 ${NS
}::label $args.where_l
-text [mc
"Target Directory:"]
508 ${NS
}::entry $args.where_t
\
509 -textvariable @local_path
\
511 ${NS
}::button $args.where_b
\
512 -text [mc
"Browse"] \
513 -command [cb _new_local_path
]
514 grid $args.where_l
$args.where_t
$args.where_b
-sticky ew
515 set w_localpath
$args.where_t
517 ${NS
}::label $args.type_l
-text [mc
"Clone Type:"]
518 ${NS
}::frame $args.type_f
520 lappend w_types
[${NS
}::radiobutton $args.type_f.hardlink
\
522 -text [mc
"Standard (Fast, Semi-Redundant, Hardlinks)"] \
523 -variable @clone_type
\
525 lappend w_types
[${NS
}::radiobutton $args.type_f.full
\
527 -text [mc
"Full Copy (Slower, Redundant Backup)"] \
528 -variable @clone_type
\
530 lappend w_types
[${NS
}::radiobutton $args.type_f.shared
\
532 -text [mc
"Shared (Fastest, Not Recommended, No Backup)"] \
533 -variable @clone_type
\
538 ${NS
}::checkbutton $args.type_f.recursive
\
539 -text [mc
"Recursively clone submodules too"] \
540 -variable @recursive
\
541 -onvalue true
-offvalue false
542 pack $args.type_f.recursive
-anchor w
543 grid $args.type_l
$args.type_f
-sticky new
545 grid columnconfigure
$args 1 -weight 1
547 trace add
variable @local_path write
[cb _update_clone
]
548 trace add
variable @origin_url write
[cb _update_clone
]
549 bind $w_body.h
<Destroy
> "
550 [list trace remove variable @local_path write [cb _update_clone]]
551 [list trace remove variable @origin_url write [cb _update_clone]]
557 method _open_origin
{} {
558 if {$origin_url ne
{} && [file isdirectory
$origin_url]} {
564 set p
[tk_chooseDirectory \
567 -title [mc
"Git Repository"] \
571 set p
[file normalize
$p]
572 if {![_is_git
[file join $p .git
]] && ![_is_git
$p]} {
573 error_popup
[mc
"Not a Git repository: %s" [file tail
$p]]
579 method _update_clone
{args
} {
580 if {$local_path ne
{} && $origin_url ne
{}} {
581 $w_next conf
-state normal
583 $w_next conf
-state disabled
586 if {$origin_url ne
{} &&
587 ( [_is_git
[file join $origin_url .git
]]
588 ||
[_is_git
$origin_url])} {
590 if {[[lindex $w_types 0] cget
-state] eq
{disabled
}} {
591 set clone_type hardlink
603 method _do_clone2
{} {
604 if {[file isdirectory
$origin_url]} {
605 set origin_url
[file normalize
$origin_url]
608 if {$clone_type eq
{hardlink
} && ![file isdirectory
$origin_url]} {
609 error_popup
[mc
"Standard only available for local repository."]
612 if {$clone_type eq
{shared
} && ![file isdirectory
$origin_url]} {
613 error_popup
[mc
"Shared only available for local repository."]
617 if {$clone_type eq
{hardlink
} ||
$clone_type eq
{shared
}} {
618 set objdir
[_objdir
$origin_url]
620 error_popup
[mc
"Not a Git repository: %s" [file tail
$origin_url]]
625 set giturl
$origin_url
626 if {[is_Cygwin
] && [file isdirectory
$giturl]} {
627 set giturl
[exec cygpath
--unix --absolute $giturl]
628 if {$clone_type eq
{shared
}} {
629 set objdir
[exec cygpath
--unix --absolute $objdir]
633 if {[file exists
$local_path]} {
634 error_popup
[mc
"Location %s already exists." $local_path]
638 if {![_git_init
$this]} return
642 git config remote.
$origin_name.url
$giturl
643 git config remote.
$origin_name.fetch
+refs
/heads
/*:refs
/remotes
/$origin_name/*
645 error_popup
[strcat
[mc
"Failed to configure origin"] "\n\n$err"]
649 destroy $w_body $w_next
651 switch -exact -- $clone_type {
653 set o_status
[status_bar
::two_line $w_body]
654 pack $w_body -fill x
-padx 10 -pady 10
656 set status_op
[$o_status start
\
657 [mc
"Counting objects"] \
661 if {[file exists
[file join $objdir info alternates
]]} {
664 file mkdir
[gitdir objects
info]
665 set f_in
[open [file join $objdir info alternates
] r
]
666 set f_cp
[open [gitdir objects
info alternates
] w
]
667 fconfigure $f_in -translation binary -encoding binary
668 fconfigure $f_cp -translation binary -encoding binary
670 while {[gets $f_in line
] >= 0} {
672 puts $f_cp [exec cygpath
--unix --absolute $line]
674 puts $f_cp [file normalize
$line]
682 _clone_failed
$this [mc
"Unable to copy objects/info/alternates: %s" $err]
692 -directory [file join $objdir] ??
]
693 set bcnt
[expr {[llength $buckets] + 2}]
695 $status_op update $bcur $bcnt
698 file mkdir
[file join .git objects
pack]
699 foreach i
[glob -tails -nocomplain \
700 -directory [file join $objdir pack] *] {
701 lappend tolink
[file join pack $i]
703 $status_op update [incr bcur
] $bcnt
707 file mkdir
[file join .git objects
$i]
708 foreach j
[glob -tails -nocomplain \
709 -directory [file join $objdir $i] *] {
710 lappend tolink
[file join $i $j]
712 $status_op update [incr bcur
] $bcnt
719 [mc
"Nothing to clone from %s." $origin_url] \
721 [mc
"The 'master' branch has not been initialized."] \
728 set i
[lindex $tolink 0]
731 [file join .git objects
$i] \
732 [file join $objdir $i]
734 info_popup
[mc
"Hardlinks are unavailable. Falling back to copying."]
735 set i
[_copy_files
$this $objdir $tolink]
737 set i
[_link_files
$this $objdir [lrange $tolink 1 end
]]
746 set o_cons
[console::embed \
748 [mc
"Cloning from %s" $origin_url]]
749 pack $w_body -fill both
-expand 1 -padx 10
751 [list git fetch
--no-tags
-k $origin_name] \
755 set fd
[open [gitdir objects
info alternates
] w
]
756 fconfigure $fd -translation binary
762 if {$clone_type eq
{hardlink
} ||
$clone_type eq
{shared
}} {
763 if {![_clone_refs
$this]} return
767 set HEAD
[git rev-parse
--verify HEAD^
0]
769 _clone_failed
$this [mc
"Not a Git repository: %s" [file tail
$origin_url]]
773 _do_clone_checkout
$this $HEAD
777 method _copy_files
{objdir tocopy
} {
778 set status_op
[$o_status start
\
779 [mc
"Copying objects"] \
784 incr tot
[file size
[file join $objdir $p]]
788 set f_in
[open [file join $objdir $p] r
]
789 set f_cp
[open [file join .git objects
$p] w
]
790 fconfigure $f_in -translation binary -encoding binary
791 fconfigure $f_cp -translation binary -encoding binary
793 while {![eof $f_in]} {
794 incr cmp
[fcopy $f_in $f_cp -size 16384]
796 [expr {$cmp / 1024}] \
804 _clone_failed
$this [mc
"Unable to copy object: %s" $err]
813 method _link_files
{objdir tolink
} {
814 set total
[llength $tolink]
815 set status_op
[$o_status start
\
816 [mc
"Linking objects"] \
818 for {set i
0} {$i < $total} {} {
819 set p
[lindex $tolink $i]
822 [file join .git objects
$p] \
823 [file join $objdir $p]
825 _clone_failed
$this [mc
"Unable to hardlink object: %s" $err]
832 $status_op update $i $total
840 method _clone_refs
{} {
842 if {[catch {cd $origin_url} err
]} {
843 error_popup
[mc
"Not a Git repository: %s" [file tail
$origin_url]]
846 set fd_in
[git_read for-each-ref
\
848 {--format=list %(refname
) %(objectname
) %(*objectname
)}]
851 set fd
[open [gitdir packed-refs
] w
]
852 fconfigure $fd -translation binary
853 puts $fd "# pack-refs with: peeled"
854 while {[gets $fd_in line
] >= 0} {
855 set line
[eval $line]
856 set refn
[lindex $line 0]
857 set robj
[lindex $line 1]
858 set tobj
[lindex $line 2]
860 if {[regsub ^refs
/heads
/ $refn \
861 "refs/remotes/$origin_name/" refn
]} {
862 puts $fd "$robj $refn"
863 } elseif
{[string match refs
/tags
/* $refn]} {
864 puts $fd "$robj $refn"
875 method _do_clone_tags
{ok
} {
878 [list git fetch
--tags -k $origin_name] \
882 _clone_failed
$this [mc
"Cannot fetch branches and objects. See console output for details."]
886 method _do_clone_HEAD
{ok
} {
889 [list git fetch
$origin_name HEAD
] \
890 [cb _do_clone_full_end
]
893 _clone_failed
$this [mc
"Cannot fetch tags. See console output for details."]
897 method _do_clone_full_end
{ok
} {
904 if {[file exists
[gitdir FETCH_HEAD
]]} {
905 set fd
[open [gitdir FETCH_HEAD
] r
]
906 while {[gets $fd line
] >= 0} {
907 if {[regexp "^(.{40})\t\t" $line line HEAD
]} {
914 catch {git pack-refs
}
915 _do_clone_checkout
$this $HEAD
917 _clone_failed
$this [mc
"Cannot determine HEAD. See console output for details."]
921 method _clone_failed
{{why
{}}} {
922 if {[catch {file delete
-force $local_path} err
]} {
926 [mc
"Unable to cleanup %s" $local_path] \
932 error_popup
[strcat
[mc
"Clone failed."] "\n" $why]
936 method _do_clone_checkout
{HEAD
} {
939 [mc
"No default branch obtained."] \
941 [mc
"The 'master' branch has not been initialized."] \
947 git update-ref HEAD
$HEAD^
0
950 [mc
"Cannot resolve %s as a commit." $HEAD^
0] \
953 [mc
"The 'master' branch has not been initialized."] \
959 set status
[status_bar
::two_line $w_body]
960 pack $w_body -fill x
-padx 10 -pady 10
962 # We start the status operation here.
964 # This function calls _readtree_wait as a callback.
966 # _readtree_wait in turn either calls _do_clone_submodules directly,
967 # or calls _postcheckout_wait as a callback which then calls
968 # _do_clone_submodules.
970 # _do_clone_submodules calls _do_validate_submodule_cloning.
972 # _do_validate_submodule_cloning stops the status operation.
974 # There are no other calls into this chain from other code.
976 set o_status_op
[$status start
\
977 [mc
"Creating working directory"] \
981 set fd
[git_read
--stderr read-tree
\
988 fconfigure $fd -blocking 0 -translation binary
989 fileevent $fd readable
[cb _readtree_wait
$fd]
992 method _readtree_wait
{fd
} {
994 $o_status_op update_meter
$buf
995 append readtree_err
$buf
997 fconfigure $fd -blocking 1
999 fconfigure $fd -blocking 0
1003 if {[catch {close $fd}]} {
1004 set err
$readtree_err
1005 regsub {^fatal
: } $err {} err
1006 error_popup
[strcat
\
1007 [mc
"Initial file checkout failed."] \
1012 # -- Run the post-checkout hook.
1014 set fd_ph
[githook_read post-checkout
[string repeat
0 40] \
1015 [git rev-parse HEAD
] 1]
1019 fconfigure $fd_ph -blocking 0 -translation binary -eofchar {}
1020 fileevent $fd_ph readable
[cb _postcheckout_wait
$fd_ph]
1022 _do_clone_submodules
$this
1026 method _postcheckout_wait
{fd_ph
} {
1029 append pch_error
[read $fd_ph]
1030 fconfigure $fd_ph -blocking 1
1032 if {[catch {close $fd_ph}]} {
1033 hook_failed_popup post-checkout
$pch_error 0
1036 _do_clone_submodules
$this
1039 fconfigure $fd_ph -blocking 0
1042 method _do_clone_submodules
{} {
1043 if {$recursive eq
{true
}} {
1049 set o_cons
[console::embed \
1051 [mc
"Cloning submodules"]]
1052 pack $w_body -fill both
-expand 1 -padx 10
1054 [list git submodule
update --init --recursive] \
1055 [cb _do_validate_submodule_cloning
]
1061 method _do_validate_submodule_cloning
{ok
} {
1066 _clone_failed
$this [mc
"Cannot clone submodules."]
1070 ######################################################################
1072 ## Open Existing Repository
1074 method _do_open
{} {
1078 -command [cb _do_open2
] \
1081 ${NS
}::frame $w_body
1082 ${NS
}::label $w_body.h
\
1083 -font font_uibold
-anchor center
\
1084 -text [mc
"Open Existing Repository"]
1085 pack $w_body.h
-side top
-fill x
-pady 10
1086 pack $w_body -fill x
-padx 10
1088 ${NS
}::frame $w_body.where
1089 ${NS
}::label $w_body.where.l
-text [mc
"Repository:"]
1090 ${NS
}::entry $w_body.where.t
\
1091 -textvariable @local_path
\
1093 ${NS
}::button $w_body.where.b
\
1094 -text [mc
"Browse"] \
1095 -command [cb _open_local_path
]
1097 grid $w_body.where.l
$w_body.where.t
$w_body.where.b
-sticky ew
1098 pack $w_body.where
-fill x
1100 grid columnconfigure
$w_body.where
1 -weight 1
1102 trace add
variable @local_path write
[cb _write_local_path
]
1103 bind $w_body.h
<Destroy
> [list trace remove
variable @local_path write
[cb _write_local_path
]]
1105 focus $w_body.where.t
1108 method _open_local_path
{} {
1109 if {$local_path ne
{}} {
1115 set p
[tk_chooseDirectory \
1118 -title [mc
"Git Repository"] \
1120 if {$p eq
{}} return
1122 set p
[file normalize
$p]
1123 if {![_is_git
[file join $p .git
]]} {
1124 error_popup
[mc
"Not a Git repository: %s" [file tail
$p]]
1130 method _do_open2
{} {
1131 if {![_is_git
[file join $local_path .git
] actualgit
]} {
1132 error_popup
[mc
"Not a Git repository: %s" [file tail
$local_path]]
1136 if {[catch {cd $local_path} err
]} {
1137 error_popup
[strcat
\
1138 [mc
"Failed to open repository %s:" $local_path] \
1143 _append_recentrepos
[pwd]
1144 set ::_gitdir $actualgit