1 # git-gui remote adding support
2 # Copyright (C) 2008 Petr Baudis
6 field w ; # widget path
7 field w_name ; # new remote name widget
8 field w_loc ; # new remote location widget
10 field name {}; # name of the remote the user has chosen
11 field location {}; # location of the remote the user has chosen
13 field opt_action fetch; # action to do after registering the remote locally
15 constructor dialog {} {
16 global repo_config use_ttk NS
20 wm title $top [mc "%s (%s): Add Remote" [appname] [reponame]]
22 wm geometry $top "+[winfo rootx .]+[winfo rooty .]"
25 ${NS}::label $w.header -text [mc "Add New Remote"] \
26 -font font_uibold -anchor center
27 pack $w.header -side top -fill x
29 ${NS}::frame $w.buttons
30 ${NS}::button $w.buttons.create -text [mc Add] \
33 pack $w.buttons.create -side right
34 ${NS}::button $w.buttons.cancel -text [mc Cancel] \
35 -command [list destroy $w]
36 pack $w.buttons.cancel -side right -padx 5
37 pack $w.buttons -side bottom -fill x -pady 10 -padx 10
39 ${NS}::labelframe $w.desc -text [mc "Remote Details"]
41 ${NS}::label $w.desc.name_l -text [mc "Name:"]
42 set w_name $w.desc.name_t
43 ${NS}::entry $w_name \
47 -validatecommand [cb _validate_name %d %S]
48 grid $w.desc.name_l $w_name -sticky we -padx {0 5}
50 ${NS}::label $w.desc.loc_l -text [mc "Location:"]
51 set w_loc $w.desc.loc_t
54 -textvariable @location
55 grid $w.desc.loc_l $w_loc -sticky we -padx {0 5}
57 grid columnconfigure $w.desc 1 -weight 1
58 pack $w.desc -anchor nw -fill x -pady 5 -padx 5
60 ${NS}::labelframe $w.action -text [mc "Further Action"]
62 ${NS}::radiobutton $w.action.fetch \
63 -text [mc "Fetch Immediately"] \
66 pack $w.action.fetch -anchor nw
68 ${NS}::radiobutton $w.action.push \
69 -text [mc "Initialize Remote Repository and Push"] \
72 pack $w.action.push -anchor nw
74 ${NS}::radiobutton $w.action.none \
75 -text [mc "Do Nothing Else Now"] \
78 pack $w.action.none -anchor nw
80 grid columnconfigure $w.action 1 -weight 1
81 pack $w.action -anchor nw -fill x -pady 5 -padx 5
83 bind $w <Visibility> [cb _visible]
84 bind $w <Key-Escape> [list destroy $w]
85 bind $w <Key-Return> [cb _add]\;break
91 global repo_config env
98 -title [wm title $w] \
100 -message [mc "Please supply a remote name."]
105 # XXX: We abuse check-ref-format here, but
107 if {[catch {git check-ref-format "remotes/$name"}]} {
111 -title [wm title $w] \
113 -message [mc "'%s' is not an acceptable remote name." $name]
118 if {[catch {add_single_remote $name $location}]} {
122 -title [wm title $w] \
124 -message [mc "Failed to add remote '%s' of location '%s'." $name $location]
129 switch -- $opt_action {
131 set c [console::new \
132 [mc "fetch %s" $name] \
133 [mc "Fetching the %s" $name]]
134 console::exec $c [list git fetch $name]
140 if { [regexp {(?:git\+)?ssh://([^/]+)(/.+)} $location xx host path]
141 || [regexp {([^:][^:]+):(.+)} $location xx host path]} {
143 if {[info exists env(GIT_SSH)]} {
144 set ssh $env(GIT_SSH)
146 lappend cmds [list exec $ssh $host mkdir -p $location && git --git-dir=$path init --bare]
147 } elseif { ! [regexp {://} $location xx] } {
148 lappend cmds [list exec mkdir -p $location]
149 lappend cmds [list exec git --git-dir=$location init --bare]
154 -title [wm title $w] \
156 -message [mc "Do not know how to initialize repository at location '%s'." $location]
161 set c [console::new \
162 [mc "push %s" $name] \
163 [mc "Setting up the %s (at %s)" $name $location]]
165 lappend cmds [list exec git push -v --all $name]
166 console::chain $c $cmds
175 method _validate_name {d S} {
177 if {[regexp {[~^:?*\[\0- ]} $S]} {