983
global HEAD commit_type file_states ui_comm repo_config
984
global ui_status_value pch_error
985
986
- if {![lock_index update]} return
986
if {[committer_ident] eq {}} return
987
+ if {![lock_index update]} return
988
989
# -- Our in memory state should match the repository.
990
#
2591
tkwait window $w
2592
}
2593
2594
+######################################################################
2595
+##
2596
+## merge
2597
+
2598
+proc can_merge {} {
2599
+ global HEAD commit_type file_states
2600
+
2601
+ if {[string match amend* $commit_type]} {
2602
+ info_popup {Cannot merge while amending.
2603
+
2604
+You must finish amending this commit before
2605
+starting any type of merge.
2606
+}
2607
+ return 0
2608
+ }
2609
+
2610
+ if {[committer_ident] eq {}} {return 0}
2611
+ if {![lock_index merge]} {return 0}
2612
+
2613
+ # -- Our in memory state should match the repository.
2614
+ #
2615
+ repository_state curType curHEAD curMERGE_HEAD
2616
+ if {$commit_type ne $curType || $HEAD ne $curHEAD} {
2617
+ info_popup {Last scanned state does not match repository state.
2618
+
2619
+Another Git program has modified this repository
2620
+since the last scan. A rescan must be performed
2621
+before a merge can be performed.
2622
+
2623
+The rescan will be automatically started now.
2624
+}
2625
+ unlock_index
2626
+ rescan {set ui_status_value {Ready.}}
2627
+ return 0
2628
+ }
2629
+
2630
+ foreach path [array names file_states] {
2631
+ switch -glob -- [lindex $file_states($path) 0] {
2632
+ U? {
2633
+ error_popup "You are in the middle of a conflicted merge.
2634
+
2635
+File [short_path $path] has merge conflicts.
2636
+
2637
+You must resolve them, add the file, and commit to
2638
+complete the current merge. Only then can you
2639
+begin another merge.
2640
+"
2641
+ unlock_index
2642
+ return 0
2643
+ }
2644
+ }
2645
+ }
2646
+
2647
+ return 1
2648
+}
2649
+
2650
+proc visualize_local_merge {w} {
2651
+ set revs {}
2652
+ foreach i [$w.source.l curselection] {
2653
+ lappend revs [$w.source.l get $i]
2654
+ }
2655
+ if {$revs eq {}} return
2656
+ lappend revs --not HEAD
2657
+ do_gitk $revs
2658
+}
2659
+
2660
+proc start_local_merge_action {w} {
2661
+ global HEAD
2662
+
2663
+ set cmd [list git merge]
2664
+ set names {}
2665
+ set revcnt 0
2666
+ foreach i [$w.source.l curselection] {
2667
+ set b [$w.source.l get $i]
2668
+ lappend cmd $b
2669
+ lappend names $b
2670
+ incr revcnt
2671
+ }
2672
+
2673
+ if {$revcnt == 0} {
2674
+ return
2675
+ } elseif {$revcnt == 1} {
2676
+ set unit branch
2677
+ } elseif {$revcnt <= 15} {
2678
+ set unit branches
2679
+ } else {
2680
+ tk_messageBox \
2681
+ -icon error \
2682
+ -type ok \
2683
+ -title [wm title $w] \
2684
+ -parent $w \
2685
+ -message "Too many branches selected.
2686
+
2687
+You have requested to merge $revcnt branches
2688
+in an octopus merge. This exceeds Git's
2689
+internal limit of 15 branches per merge.
2690
+
2691
+Please select fewer branches. To merge more
2692
+than 15 branches, merge the branches in batches.
2693
+"
2694
+ return
2695
+ }
2696
+
2697
+ set cons [new_console "Merge" "Merging [join $names {, }]"]
2698
+ console_exec $cons $cmd finish_merge
2699
+ bind $w <Destroy> {}
2700
+ destroy $w
2701
+}
2702
+
2703
+proc finish_merge {w ok} {
2704
+ console_done $w $ok
2705
+ if {$ok} {
2706
+ set msg {Merge completed successfully.}
2707
+ } else {
2708
+ set msg {Merge failed. Conflict resolution is required.}
2709
+ }
2710
+ unlock_index
2711
+ rescan [list set ui_status_value $msg]
2712
+}
2713
+
2714
+proc do_local_merge {} {
2715
+ global current_branch
2716
+
2717
+ if {![can_merge]} return
2718
+
2719
+ set w .merge_setup
2720
+ toplevel $w
2721
+ wm geometry $w "+[winfo rootx .]+[winfo rooty .]"
2722
+
2723
+ label $w.header \
2724
+ -text "Merge Into $current_branch" \
2725
+ -font font_uibold
2726
+ pack $w.header -side top -fill x
2727
+
2728
+ frame $w.buttons
2729
+ button $w.buttons.visualize -text Visualize \
2730
+ -font font_ui \
2731
+ -command [list visualize_local_merge $w]
2732
+ pack $w.buttons.visualize -side left
2733
+ button $w.buttons.create -text Merge \
2734
+ -font font_ui \
2735
+ -command [list start_local_merge_action $w]
2736
+ pack $w.buttons.create -side right
2737
+ button $w.buttons.cancel -text {Cancel} \
2738
+ -font font_ui \
2739
+ -command [list destroy $w]
2740
+ pack $w.buttons.cancel -side right -padx 5
2741
+ pack $w.buttons -side bottom -fill x -pady 10 -padx 10
2742
+
2743
+ labelframe $w.source \
2744
+ -text {Source Branches} \
2745
+ -font font_ui
2746
+ listbox $w.source.l \
2747
+ -height 10 \
2748
+ -width 25 \
2749
+ -selectmode extended \
2750
+ -yscrollcommand [list $w.source.sby set] \
2751
+ -font font_ui
2752
+ scrollbar $w.source.sby -command [list $w.source.l yview]
2753
+ pack $w.source.sby -side right -fill y
2754
+ pack $w.source.l -side left -fill both -expand 1
2755
+ pack $w.source -fill both -expand 1 -pady 5 -padx 5
2756
+
2757
+ set cmd [list git for-each-ref]
2758
+ lappend cmd {--format=%(objectname) %(refname)}
2759
+ lappend cmd refs/heads
2760
+ lappend cmd refs/remotes
2761
+ set fr_fd [open "| $cmd" r]
2762
+ fconfigure $fr_fd -translation binary
2763
+ while {[gets $fr_fd line] > 0} {
2764
+ set line [split $line { }]
2765
+ set sha1([lindex $line 0]) [lindex $line 1]
2766
+ }
2767
+ close $fr_fd
2768
+
2769
+ set to_show {}
2770
+ set fr_fd [open "| git rev-list --all --not HEAD"]
2771
+ while {[gets $fr_fd line] > 0} {
2772
+ if {[catch {set ref $sha1($line)}]} continue
2773
+ regsub ^refs/(heads|remotes)/ $ref {} ref
2774
+ lappend to_show $ref
2775
+ }
2776
+ close $fr_fd
2777
+
2778
+ foreach ref [lsort -unique $to_show] {
2779
+ $w.source.l insert end $ref
2780
+ }
2781
+
2782
+ bind $w <Visibility> "grab $w"
2783
+ bind $w <Key-Escape> "unlock_index;destroy $w"
2784
+ bind $w <Destroy> unlock_index
2785
+ wm title $w "[appname] ([reponame]): Merge"
2786
+ tkwait window $w
2787
+}
2788
+
2789
######################################################################
2790
##
2791
## icons
4060
}
4061
.mbar add cascade -label Commit -menu .mbar.commit
4062
if {!$single_commit} {
4063
+ .mbar add cascade -label Merge -menu .mbar.merge
4064
.mbar add cascade -label Fetch -menu .mbar.fetch
4065
.mbar add cascade -label Push -menu .mbar.push
4066
}
4235
lappend disable_on_lock \
4236
[list .mbar.commit entryconf [.mbar.commit index last] -state]
4237
4042
-# -- Transport menus
4043
-#
4044
-if {!$single_commit} {
4045
- menu .mbar.fetch
4046
- menu .mbar.push
4047
-
4048
- .mbar.push add command -label {Push...} \
4049
- -command do_push_anywhere \
4050
- -font font_ui
4051
-}
4052
-
4238
if {[is_MacOSX]} {
4239
# -- Apple Menu (Mac OS X only)
4240
#
4315
pack .branch.cb -side left -fill x
4316
pack .branch -side top -fill x
4317
4318
+if {!$single_commit} {
4319
+ menu .mbar.merge
4320
+ .mbar.merge add command -label {Local Merge...} \
4321
+ -command do_local_merge \
4322
+ -font font_ui
4323
+ lappend disable_on_lock \
4324
+ [list .mbar.merge entryconf [.mbar.merge index last] -state]
4325
+
4326
+ menu .mbar.fetch
4327
+
4328
+ menu .mbar.push
4329
+ .mbar.push add command -label {Push...} \
4330
+ -command do_push_anywhere \
4331
+ -font font_ui
4332
+}
4333
+
4334
# -- Main Window Layout
4335
#
4336
panedwindow .vpane -orient vertical