Skip to content

Commit 75d8ff1

Browse files
committed
Merge branch 'master' of git://repo.or.cz/git-gui
* 'master' of git://repo.or.cz/git-gui: git-gui: Internalize symbolic-ref HEAD reading logic git-gui: Expose the merge.diffstat configuration option git-gui: Allow users to delete remote branches git-gui: Allow users to rename branches through 'branch -m' git-gui: Disable tearoff menus on Windows, Mac OS X git-gui: Provide fatal error if library is unavailable git-gui: Enable verbose Tcl loading earlier git-gui: Show the git-gui library path in 'About git-gui' git-gui: GUI support for running 'git remote prune <name>' git gui 0.8.0
2 parents 27c1dbe + 32af629 commit 75d8ff1

File tree

7 files changed

+601
-52
lines changed

7 files changed

+601
-52
lines changed

git-gui/GIT-VERSION-GEN

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22

33
GVF=GIT-VERSION-FILE
4-
DEF_VER=0.7.GITGUI
4+
DEF_VER=0.8.GITGUI
55

66
LF='
77
'

git-gui/git-gui.sh

Lines changed: 75 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,24 @@ if {[catch {package require Tcl 8.4} err]
3636
exit 1
3737
}
3838

39+
######################################################################
40+
##
41+
## enable verbose loading?
42+
43+
if {![catch {set _verbose $env(GITGUI_VERBOSE)}]} {
44+
unset _verbose
45+
rename auto_load real__auto_load
46+
proc auto_load {name args} {
47+
puts stderr "auto_load $name"
48+
return [uplevel 1 real__auto_load $name $args]
49+
}
50+
rename source real__source
51+
proc source {name} {
52+
puts stderr "source $name"
53+
uplevel 1 real__source $name
54+
}
55+
}
56+
3957
######################################################################
4058
##
4159
## configure our library
@@ -48,48 +66,41 @@ if {$oguirel eq {1}} {
4866
} elseif {[string match @@* $oguirel]} {
4967
set oguilib [file join [file dirname [file normalize $argv0]] lib]
5068
}
69+
5170
set idx [file join $oguilib tclIndex]
52-
catch {
53-
set fd [open $idx r]
54-
if {[gets $fd] eq {# Autogenerated by git-gui Makefile}} {
55-
set idx [list]
56-
while {[gets $fd n] >= 0} {
57-
if {$n ne {} && ![string match #* $n]} {
58-
lappend idx $n
59-
}
71+
if {[catch {set fd [open $idx r]} err]} {
72+
catch {wm withdraw .}
73+
tk_messageBox \
74+
-icon error \
75+
-type ok \
76+
-title "git-gui: fatal error" \
77+
-message $err
78+
exit 1
79+
}
80+
if {[gets $fd] eq {# Autogenerated by git-gui Makefile}} {
81+
set idx [list]
82+
while {[gets $fd n] >= 0} {
83+
if {$n ne {} && ![string match #* $n]} {
84+
lappend idx $n
6085
}
61-
} else {
62-
set idx {}
6386
}
64-
close $fd
87+
} else {
88+
set idx {}
6589
}
90+
close $fd
91+
6692
if {$idx ne {}} {
6793
set loaded [list]
6894
foreach p $idx {
6995
if {[lsearch -exact $loaded $p] >= 0} continue
70-
puts $p
7196
source [file join $oguilib $p]
7297
lappend loaded $p
7398
}
7499
unset loaded p
75100
} else {
76101
set auto_path [concat [list $oguilib] $auto_path]
77102
}
78-
unset -nocomplain oguilib oguirel idx fd
79-
80-
if {![catch {set _verbose $env(GITGUI_VERBOSE)}]} {
81-
unset _verbose
82-
rename auto_load real__auto_load
83-
proc auto_load {name args} {
84-
puts stderr "auto_load $name"
85-
return [uplevel 1 real__auto_load $name $args]
86-
}
87-
rename source real__source
88-
proc source {name} {
89-
puts stderr "source $name"
90-
uplevel 1 real__source $name
91-
}
92-
}
103+
unset -nocomplain oguirel idx fd
93104

94105
######################################################################
95106
##
@@ -205,6 +216,15 @@ proc is_config_true {name} {
205216
}
206217
}
207218

219+
proc get_config {name} {
220+
global repo_config
221+
if {[catch {set v $repo_config($name)}]} {
222+
return {}
223+
} else {
224+
return $v
225+
}
226+
}
227+
208228
proc load_config {include_global} {
209229
global repo_config global_config default_config
210230

@@ -258,6 +278,17 @@ proc git {args} {
258278
return [eval exec git $args]
259279
}
260280

281+
proc current-branch {} {
282+
set ref {}
283+
set fd [open [gitdir HEAD] r]
284+
if {[gets $fd ref] <16
285+
|| ![regsub {^ref: refs/heads/} $ref {} ref]} {
286+
set ref {}
287+
}
288+
close $fd
289+
return $ref
290+
}
291+
261292
auto_load tk_optionMenu
262293
rename tk_optionMenu real__tkOptionMenu
263294
proc tk_optionMenu {w varName args} {
@@ -406,15 +437,7 @@ proc repository_state {ctvar hdvar mhvar} {
406437

407438
set mh [list]
408439

409-
if {[catch {set current_branch [git symbolic-ref HEAD]}]} {
410-
set current_branch {}
411-
} else {
412-
regsub ^refs/((heads|tags|remotes)/)? \
413-
$current_branch \
414-
{} \
415-
current_branch
416-
}
417-
440+
set current_branch [current-branch]
418441
if {[catch {set hd [git rev-parse --verify HEAD]}]} {
419442
set hd {}
420443
set ct initial
@@ -1229,6 +1252,10 @@ foreach class {Button Checkbutton Entry Label
12291252
}
12301253
unset class
12311254

1255+
if {[is_Windows] || [is_MacOSX]} {
1256+
option add *Menu.tearOff 0
1257+
}
1258+
12321259
if {[is_MacOSX]} {
12331260
set M1B M1
12341261
set M1T Cmd
@@ -1259,11 +1286,13 @@ proc apply_config {} {
12591286
}
12601287
}
12611288

1289+
set default_config(merge.diffstat) true
12621290
set default_config(merge.summary) false
12631291
set default_config(merge.verbosity) 2
12641292
set default_config(user.name) {}
12651293
set default_config(user.email) {}
12661294

1295+
set default_config(gui.pruneduringfetch) false
12671296
set default_config(gui.trustmtime) false
12681297
set default_config(gui.diffcontext) 5
12691298
set default_config(gui.newbranchtemplate) {}
@@ -1425,6 +1454,11 @@ if {[is_enabled branch]} {
14251454
lappend disable_on_lock [list .mbar.branch entryconf \
14261455
[.mbar.branch index last] -state]
14271456

1457+
.mbar.branch add command -label {Rename...} \
1458+
-command branch_rename::dialog
1459+
lappend disable_on_lock [list .mbar.branch entryconf \
1460+
[.mbar.branch index last] -state]
1461+
14281462
.mbar.branch add command -label {Delete...} \
14291463
-command do_delete_branch
14301464
lappend disable_on_lock [list .mbar.branch entryconf \
@@ -1522,6 +1556,8 @@ if {[is_enabled transport]} {
15221556
menu .mbar.push
15231557
.mbar.push add command -label {Push...} \
15241558
-command do_push_anywhere
1559+
.mbar.push add command -label {Delete...} \
1560+
-command remote_branch_delete::dialog
15251561
}
15261562

15271563
if {[is_MacOSX]} {
@@ -1639,14 +1675,8 @@ switch -- $subcommand {
16391675
browser {
16401676
set subcommand_args {rev?}
16411677
switch [llength $argv] {
1642-
0 {
1643-
set current_branch [git symbolic-ref HEAD]
1644-
regsub ^refs/((heads|tags|remotes)/)? \
1645-
$current_branch {} current_branch
1646-
}
1647-
1 {
1648-
set current_branch [lindex $argv 0]
1649-
}
1678+
0 { set current_branch [current-branch] }
1679+
1 { set current_branch [lindex $argv 0] }
16501680
default usage
16511681
}
16521682
browser::new $current_branch
@@ -1679,9 +1709,7 @@ blame {
16791709
unset is_path
16801710

16811711
if {$head eq {}} {
1682-
set current_branch [git symbolic-ref HEAD]
1683-
regsub ^refs/((heads|tags|remotes)/)? \
1684-
$current_branch {} current_branch
1712+
set current_branch [current-branch]
16851713
} else {
16861714
set current_branch $head
16871715
}

git-gui/lib/branch_rename.tcl

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# git-gui branch rename support
2+
# Copyright (C) 2007 Shawn Pearce
3+
4+
class branch_rename {
5+
6+
field w
7+
field oldname
8+
field newname
9+
10+
constructor dialog {} {
11+
global all_heads current_branch
12+
13+
make_toplevel top w
14+
wm title $top "[appname] ([reponame]): Rename Branch"
15+
if {$top ne {.}} {
16+
wm geometry $top "+[winfo rootx .]+[winfo rooty .]"
17+
}
18+
19+
set oldname $current_branch
20+
set newname [get_config gui.newbranchtemplate]
21+
22+
label $w.header -text {Rename Branch} -font font_uibold
23+
pack $w.header -side top -fill x
24+
25+
frame $w.buttons
26+
button $w.buttons.rename -text Rename \
27+
-default active \
28+
-command [cb _rename]
29+
pack $w.buttons.rename -side right
30+
button $w.buttons.cancel -text {Cancel} \
31+
-command [list destroy $w]
32+
pack $w.buttons.cancel -side right -padx 5
33+
pack $w.buttons -side bottom -fill x -pady 10 -padx 10
34+
35+
frame $w.rename
36+
label $w.rename.oldname_l -text {Branch:}
37+
eval tk_optionMenu $w.rename.oldname_m @oldname $all_heads
38+
39+
label $w.rename.newname_l -text {New Name:}
40+
entry $w.rename.newname_t \
41+
-borderwidth 1 \
42+
-relief sunken \
43+
-width 40 \
44+
-textvariable @newname \
45+
-validate key \
46+
-validatecommand {
47+
if {%d == 1 && [regexp {[~^:?*\[\0- ]} %S]} {return 0}
48+
return 1
49+
}
50+
51+
grid $w.rename.oldname_l $w.rename.oldname_m -sticky w -padx {0 5}
52+
grid $w.rename.newname_l $w.rename.newname_t -sticky we -padx {0 5}
53+
grid columnconfigure $w.rename 1 -weight 1
54+
pack $w.rename -anchor nw -fill x -pady 5 -padx 5
55+
56+
bind $w <Key-Return> [cb _rename]
57+
bind $w <Key-Escape> [list destroy $w]
58+
bind $w <Visibility> "
59+
grab $w
60+
$w.rename.newname_t icursor end
61+
focus $w.rename.newname_t
62+
"
63+
bind $w.header <Destroy> [list delete_this $this]
64+
tkwait window $w
65+
}
66+
67+
method _rename {} {
68+
global all_heads current_branch
69+
70+
if {$oldname eq {}} {
71+
tk_messageBox \
72+
-icon error \
73+
-type ok \
74+
-title [wm title $w] \
75+
-parent $w \
76+
-message "Please select a branch to rename."
77+
focus $w.rename.oldname_m
78+
return
79+
}
80+
if {$newname eq {}
81+
|| $newname eq [get_config gui.newbranchtemplate]} {
82+
tk_messageBox \
83+
-icon error \
84+
-type ok \
85+
-title [wm title $w] \
86+
-parent $w \
87+
-message "Please supply a branch name."
88+
focus $w.rename.newname_t
89+
return
90+
}
91+
if {![catch {git show-ref --verify -- "refs/heads/$newname"}]} {
92+
tk_messageBox \
93+
-icon error \
94+
-type ok \
95+
-title [wm title $w] \
96+
-parent $w \
97+
-message "Branch '$newname' already exists."
98+
focus $w.rename.newname_t
99+
return
100+
}
101+
if {[catch {git check-ref-format "heads/$newname"}]} {
102+
tk_messageBox \
103+
-icon error \
104+
-type ok \
105+
-title [wm title $w] \
106+
-parent $w \
107+
-message "We do not like '$newname' as a branch name."
108+
focus $w.rename.newname_t
109+
return
110+
}
111+
112+
if {[catch {git branch -m $oldname $newname} err]} {
113+
tk_messageBox \
114+
-icon error \
115+
-type ok \
116+
-title [wm title $w] \
117+
-parent $w \
118+
-message "Failed to rename '$oldname'.\n\n$err"
119+
return
120+
}
121+
122+
set oldidx [lsearch -exact -sorted $all_heads $oldname]
123+
if {$oldidx >= 0} {
124+
set all_heads [lreplace $all_heads $oldidx $oldidx]
125+
}
126+
lappend all_heads $newname
127+
set all_heads [lsort $all_heads]
128+
populate_branch_menu
129+
130+
if {$current_branch eq $oldname} {
131+
set current_branch $newname
132+
}
133+
134+
destroy $w
135+
}
136+
137+
}

0 commit comments

Comments
 (0)