Class: Fugit::MergeDialog

Inherits:
Dialog
  • Object
show all
Defined in:
lib/fugit/merge_dialog.rb

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ MergeDialog

Returns a new instance of MergeDialog.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/fugit/merge_dialog.rb', line 5

def initialize(parent)
  super(parent, ID_ANY, "Merge branches", :size => Size.new(250, 300))

  @branch_list = CheckListBox.new(self, ID_ANY)
  @log_check = CheckBox.new(self, ID_ANY)
  @log_check.set_label("Include commit &log")
  @log_check.set_tool_tip("Adds a log of commit summaries to the merge commit's message")
  @commit_check = CheckBox.new(self, ID_ANY)
  @commit_check.set_label("&Commit result")
  @commit_check.set_tool_tip("If there are no merge conficts, commit the results automatically.")
  @squash_check = CheckBox.new(self, ID_ANY)
  @squash_check.set_label("&Squash result")
  @squash_check.set_tool_tip("Instead of creating a merge commit, squash all of\nthe changes together and stage them for commit.\nThis will create the same changeset a normal\nmerge would, without creating a merge commit.")
  @noff_check = CheckBox.new(self, ID_ANY)
  @noff_check.set_label("&Fast-forward when possible")
  @noff_check.set_tool_tip("Do not generate a merge commit if the merge resolved as a fast-forward, only update the branch pointer.")

  butt_sizer = create_button_sizer(OK|CANCEL)
  butt_sizer.get_children.map {|s| s.get_window}.compact.each {|b| b.set_label("Merge") if b.get_label == "OK"}
  evt_button(get_affirmative_id, :on_ok)

  box = BoxSizer.new(VERTICAL)
  box.add(StaticText.new(self, ID_ANY, "Select branches:"), 0, EXPAND|ALL, 4)
  box.add(@branch_list, 1, EXPAND|LEFT|RIGHT|BOTTOM, 4)
  box.add(@log_check, 0, EXPAND|LEFT|RIGHT|BOTTOM, 4)
  box.add(@commit_check, 0, EXPAND|LEFT|RIGHT|BOTTOM, 4)
  box.add(@squash_check, 0, EXPAND|LEFT|RIGHT|BOTTOM, 4)
  box.add(@noff_check, 0, EXPAND|LEFT|RIGHT|BOTTOM, 4)
  box.add(butt_sizer, 0, EXPAND|BOTTOM, 4)

  self.set_sizer(box)
end

Instance Method Details

#on_okObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/fugit/merge_dialog.rb', line 51

def on_ok
  branches = @branch_list.get_checked_items.map {|i| @branch_list.get_string(i)}
  args = []
  args << "--log" if @log_check.is_checked
  args << "--no-commit" unless @commit_check.is_checked || @squash_check.is_checked
  args << "--squash" if @squash_check.is_checked
  args << "--no-ff" unless @noff_check.is_checked
  command = "git merge #{args.empty? ? "" : "#{args.join(" ")} "}#{branches.join(" ")}"

  self.end_modal(ID_OK)

  @log_dialog ||= LoggedDialog.new(self, "Merging branches")
  @log_dialog.show
  @log_dialog.run_command(command)
end

#showObject



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fugit/merge_dialog.rb', line 38

def show
  branches = `git branch -a --no-merged`
  branches = branches.split("\n").map {|b| b.strip}
  @branch_list.set(branches)

  @log_check.set_value(false)
  @commit_check.set_value(true)
  @squash_check.set_value(false)
  @noff_check.set_value(true)

  super
end