Class: Fugit::Commit
- Inherits:
-
Panel
- Object
- Panel
- Fugit::Commit
- Defined in:
- lib/fugit/commit.rb
Instance Method Summary collapse
- #has_staged_changes? ⇒ Boolean
-
#initialize(parent) ⇒ Commit
constructor
A new instance of Commit.
- #on_commit_clicked ⇒ Object
- #on_commit_saved ⇒ Object
- #on_push_clicked ⇒ Object
Constructor Details
#initialize(parent) ⇒ Commit
Returns a new instance of Commit.
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fugit/commit.rb', line 6 def initialize(parent) super(parent, ID_ANY) @input = TextCtrl.new(self, ID_ANY, nil, nil, nil, TE_MULTILINE|TE_DONTWRAP) @author = TextCtrl.new(self, ID_ANY) @committer = TextCtrl.new(self, ID_ANY) @committer.disable @toolbar = ToolBar.new(self, ID_ANY) @toolbar.set_tool_bitmap_size(Size.new(16,16)) @toolbar.add_tool(101, "Commit", get_icon("disk.png"), "Commit") @toolbar.add_tool(102, "Sign off", get_icon("text_signature.png"), "Sign off") @toolbar.add_separator @toolbar.add_tool(103, "Push", get_icon("page_up.gif"), "Push") #~ @toolbar.add_tool(104, "Pull", get_icon("page_down.gif"), "Pull") @toolbar.realize box = BoxSizer.new(HORIZONTAL) box.add(@committer, 1, EXPAND) box.add(@author, 1, EXPAND) flex = FlexGridSizer.new(2,2,0,0) flex.add(StaticText.new(self, ID_ANY, "Committer/Author:"), 0, EXPAND) flex.add(box, 0, EXPAND) flex.add(StaticText.new(self, ID_ANY, "Commit message:"), 0, EXPAND) flex.add(@input, 0, EXPAND) flex.add_growable_row(1) flex.add_growable_col(1) box = BoxSizer.new(VERTICAL) box.add(@toolbar, 0, EXPAND) box.add_spacer(4) box.add(flex, 1, EXPAND) self.set_sizer(box) evt_tool(101, :on_commit_clicked) evt_tool(103, :on_push_clicked) (:save_clicked, :on_commit_clicked) (:commit_saved, :on_commit_saved) (:refresh, :update) name = `git config user.name` email = `git config user.email` @committer.set_value("#{name.chomp} <#{email.chomp}>") @author.set_value("#{name.chomp} <#{email.chomp}>") end |
Instance Method Details
#has_staged_changes? ⇒ Boolean
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/fugit/commit.rb', line 78 def has_staged_changes? staged = `git ls-files --stage` last_commit = `git ls-tree -r HEAD` committed = {} last_commit.split("\n").map do |line| (info, file) = line.split("\t") sha = info.match(/[a-f0-9]{40}/)[0] committed[file] = sha end staged = staged.split("\n").map do |line| (info, file) = line.split("\t") sha = info.match(/[a-f0-9]{40}/)[0] [file, sha] end staged.reject! {|file, sha| committed[file] == sha} !staged.empty? end |
#on_commit_clicked ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/fugit/commit.rb', line 54 def on_commit_clicked msg = @input.get_value if !has_staged_changes? @nothing_to_commit_error ||= MessageDialog.new(self, "No changes are staged to commit.", "Commit error", OK|ICON_ERROR) @nothing_to_commit_error.show_modal elsif msg.empty? @no_msg_error ||= MessageDialog.new(self, "Please enter a commit message.", "Commit error", OK|ICON_ERROR) @no_msg_error.show_modal else commit_file = File.join(Dir.pwd, ".git", "fugit_commit.txt") File.open(commit_file, "w") {|f| f << msg} `git commit --file=.git/fugit_commit.txt --author="#{@author.get_value}"` File.delete(commit_file) (:commit_saved) end end |
#on_commit_saved ⇒ Object
71 72 73 74 75 76 |
# File 'lib/fugit/commit.rb', line 71 def on_commit_saved name = `git config user.name` email = `git config user.email` @author.set_value("#{name.chomp} <#{email.chomp}>") @input.set_value("") end |
#on_push_clicked ⇒ Object
98 99 100 101 |
# File 'lib/fugit/commit.rb', line 98 def on_push_clicked @push_dialog ||= PushDialog .new(self) @push_dialog.show end |