]> asedeno.scripts.mit.edu Git - git.git/blobdiff - git-gui.sh
git-gui: Create new branches from a tag.
[git.git] / git-gui.sh
index 7ecb98b900576ed6abc8b4e4af4333a209769ba6..9ce5a3bdc3805ed0054ee1c3a7b1cd1d06a9e8c1 100755 (executable)
@@ -295,6 +295,38 @@ proc ask_popup {msg} {
                -message $msg]
 }
 
+######################################################################
+##
+## version check
+
+set req_maj 1
+set req_min 5
+
+if {[catch {set v [git --version]} err]} {
+       catch {wm withdraw .}
+       error_popup "Cannot determine Git version:
+
+$err
+
+[appname] requires Git $req_maj.$req_min or later."
+       exit 1
+}
+if {[regexp {^git version (\d+)\.(\d+)} $v _junk act_maj act_min]} {
+       if {$act_maj < $req_maj
+               || ($act_maj == $req_maj && $act_min < $req_min)} {
+               catch {wm withdraw .}
+               error_popup "[appname] requires Git $req_maj.$req_min or later.
+
+You are using $v."
+               exit 1
+       }
+} else {
+       catch {wm withdraw .}
+       error_popup "Cannot parse Git version string:\n\n$v"
+       exit 1
+}
+unset -nocomplain v _junk act_maj act_min req_maj req_min
+
 ######################################################################
 ##
 ## repository setup
@@ -1884,11 +1916,24 @@ proc all_tracking_branches {} {
        return [lsort -unique $all_trackings]
 }
 
+proc load_all_tags {} {
+       set all_tags [list]
+       set fd [open "| git for-each-ref --format=%(refname) refs/tags" r]
+       while {[gets $fd line] > 0} {
+               if {![regsub ^refs/tags/ $line {} name]} continue
+               lappend all_tags $name
+       }
+       close $fd
+
+       return [lsort $all_tags]
+}
+
 proc do_create_branch_action {w} {
        global all_heads null_sha1 repo_config
        global create_branch_checkout create_branch_revtype
        global create_branch_head create_branch_trackinghead
        global create_branch_name create_branch_revexp
+       global create_branch_tag
 
        set newbranch $create_branch_name
        if {$newbranch eq {}
@@ -1927,6 +1972,7 @@ proc do_create_branch_action {w} {
        switch -- $create_branch_revtype {
        head {set rev $create_branch_head}
        tracking {set rev $create_branch_trackinghead}
+       tag {set rev $create_branch_tag}
        expression {set rev $create_branch_revexp}
        }
        if {[catch {set cmt [git rev-parse --verify "${rev}^0"]}]} {
@@ -1972,6 +2018,8 @@ trace add variable create_branch_head write \
        [list radio_selector create_branch_revtype head]
 trace add variable create_branch_trackinghead write \
        [list radio_selector create_branch_revtype tracking]
+trace add variable create_branch_tag write \
+       [list radio_selector create_branch_revtype tag]
 
 trace add variable delete_branch_head write \
        [list radio_selector delete_branch_checktype head]
@@ -1983,6 +2031,7 @@ proc do_create_branch {} {
        global create_branch_checkout create_branch_revtype
        global create_branch_head create_branch_trackinghead
        global create_branch_name create_branch_revexp
+       global create_branch_tag
 
        set w .branch_editor
        toplevel $w
@@ -2046,6 +2095,19 @@ proc do_create_branch {} {
                        $all_trackings
                grid $w.from.tracking_r $w.from.tracking_m -sticky w
        }
+       set all_tags [load_all_tags]
+       if {$all_tags ne {}} {
+               set create_branch_tag [lindex $all_tags 0]
+               radiobutton $w.from.tag_r \
+                       -text {Tag:} \
+                       -value tag \
+                       -variable create_branch_revtype \
+                       -font font_ui
+               eval tk_optionMenu $w.from.tag_m \
+                       create_branch_tag \
+                       $all_tags
+               grid $w.from.tag_r $w.from.tag_m -sticky w
+       }
        radiobutton $w.from.exp_r \
                -text {Revision Expression:} \
                -value expression \
@@ -2884,14 +2946,16 @@ proc do_local_merge {} {
        pack $w.source -fill both -expand 1 -pady 5 -padx 5
 
        set cmd [list git for-each-ref]
-       lappend cmd {--format=%(objectname) %(refname)}
+       lappend cmd {--format=%(objectname) %(*objectname) %(refname)}
        lappend cmd refs/heads
        lappend cmd refs/remotes
+       lappend cmd refs/tags
        set fr_fd [open "| $cmd" r]
        fconfigure $fr_fd -translation binary
        while {[gets $fr_fd line] > 0} {
                set line [split $line { }]
-               set sha1([lindex $line 0]) [lindex $line 1]
+               set sha1([lindex $line 0]) [lindex $line 2]
+               set sha1([lindex $line 1]) [lindex $line 2]
        }
        close $fr_fd
 
@@ -2899,7 +2963,7 @@ proc do_local_merge {} {
        set fr_fd [open "| git rev-list --all --not HEAD"]
        while {[gets $fr_fd line] > 0} {
                if {[catch {set ref $sha1($line)}]} continue
-               regsub ^refs/(heads|remotes)/ $ref {} ref
+               regsub ^refs/(heads|remotes|tags)/ $ref {} ref
                lappend to_show $ref
        }
        close $fr_fd
@@ -4408,7 +4472,7 @@ proc do_about {} {
        pack $w.buttons -side bottom -fill x -pady 10 -padx 10
 
        label $w.desc \
-               -text "[appname] - a commit creation tool for Git.
+               -text "git-gui - a commit creation tool for Git.
 $copyright" \
                -padx 5 -pady 5 \
                -justify left \
@@ -4419,7 +4483,7 @@ $copyright" \
        pack $w.desc -side top -fill x -padx 5 -pady 5
 
        set v {}
-       append v "[appname] version $appvers\n"
+       append v "git-gui version $appvers\n"
        append v "[git version]\n"
        append v "\n"
        if {$tcl_patchLevel eq $tk_patchLevel} {
@@ -4479,7 +4543,7 @@ proc do_options {} {
        toplevel $w
        wm geometry $w "+[winfo rootx .]+[winfo rooty .]"
 
-       label $w.header -text "[appname] Options" \
+       label $w.header -text "Options" \
                -font font_uibold
        pack $w.header -side top -fill x
 
@@ -4953,6 +5017,8 @@ enable_option branch
 enable_option transport
 
 switch -- $subcommand {
+--version -
+version -
 blame {
        disable_option multicommit
        disable_option branch
@@ -5185,7 +5251,7 @@ if {[is_MacOSX]} {
        .mbar.apple add command -label "About [appname]" \
                -command do_about \
                -font font_ui
-       .mbar.apple add command -label "[appname] Options..." \
+       .mbar.apple add command -label "Options..." \
                -command do_options \
                -font font_ui
 } else {
@@ -5288,6 +5354,11 @@ bind all <$M1B-Key-W> {destroy [winfo toplevel %W]}
 # -- Not a normal commit type invocation?  Do that instead!
 #
 switch -- $subcommand {
+--version -
+version {
+       puts "git-gui version $appvers"
+       exit
+}
 blame {
        if {[llength $argv] != 2} {
                puts stderr "usage: $argv0 blame commit path"