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 {} {
19 wm title $top [append "[appname] ([reponame]): " [mc "Add Remote"]]
21 wm geometry $top "+[winfo rootx .]+[winfo rooty .]"
24 label $w.header -text [mc "Add New Remote"] -font font_uibold
25 pack $w.header -side top -fill x
28 button $w.buttons.create -text [mc Add] \
31 pack $w.buttons.create -side right
32 button $w.buttons.cancel -text [mc Cancel] \
33 -command [list destroy $w]
34 pack $w.buttons.cancel -side right -padx 5
35 pack $w.buttons -side bottom -fill x -pady 10 -padx 10
37 labelframe $w.desc -text [mc "Remote Details"]
39 label $w.desc.name_l -text [mc "Name:"]
40 set w_name $w.desc.name_t
47 -validatecommand [cb _validate_name %d %S]
48 grid $w.desc.name_l $w_name -sticky we -padx {0 5}
50 label $w.desc.loc_l -text [mc "Location:"]
51 set w_loc $w.desc.loc_t
56 -textvariable @location
57 grid $w.desc.loc_l $w_loc -sticky we -padx {0 5}
59 grid columnconfigure $w.desc 1 -weight 1
60 pack $w.desc -anchor nw -fill x -pady 5 -padx 5
62 labelframe $w.action -text [mc "Further Action"]
64 radiobutton $w.action.fetch \
65 -text [mc "Fetch Immediately"] \
68 pack $w.action.fetch -anchor nw
70 radiobutton $w.action.push \
71 -text [mc "Initialize Remote Repository and Push"] \
74 pack $w.action.push -anchor nw
76 radiobutton $w.action.none \
77 -text [mc "Do Nothing Else Now"] \
80 pack $w.action.none -anchor nw
82 grid columnconfigure $w.action 1 -weight 1
83 pack $w.action -anchor nw -fill x -pady 5 -padx 5
85 bind $w <Visibility> [cb _visible]
86 bind $w <Key-Escape> [list destroy $w]
87 bind $w <Key-Return> [cb _add]\;break
92 global repo_config env
99 -title [wm title $w] \
101 -message [mc "Please supply a remote name."]
106 # XXX: We abuse check-ref-format here, but
108 if {[catch {git check-ref-format "remotes/$name"}]} {
112 -title [wm title $w] \
114 -message [mc "'%s' is not an acceptable remote name." $name]
119 if {[catch {add_single_remote $name $location}]} {
123 -title [wm title $w] \
125 -message [mc "Failed to add remote '%s' of location '%s'." $name $location]
130 switch -- $opt_action {
132 set c [console::new \
133 [mc "fetch %s" $name] \
134 [mc "Fetching the %s" $name]]
135 console::exec $c [list git fetch $name]
141 if { [regexp {(?:git\+)?ssh://([^/]+)(/.+)} $location xx host path]
142 || [regexp {([^:][^:]+):(.+)} $location xx host path]} {
144 if {[info exists env(GIT_SSH)]} {
145 set ssh $env(GIT_SSH)
147 lappend cmds [list exec $ssh $host mkdir -p $location && git --git-dir=$path init --bare]
148 } elseif { ! [regexp {://} $location xx] } {
149 lappend cmds [list exec mkdir -p $location]
150 lappend cmds [list exec git --git-dir=$location init --bare]
155 -title [wm title $w] \
157 -message [mc "Do not know how to initialize repository at location '%s'." $location]
162 set c [console::new \
163 [mc "push %s" $name] \
164 [mc "Setting up the %s (at %s)" $name $location]]
166 lappend cmds [list exec git push -v --all $name]
167 console::chain $c $cmds
176 method _validate_name {d S} {
178 if {[regexp {[~^:?*\[\0- ]} $S]} {