Module: RuVim::Git::Commit

Defined in:
lib/ruvim/git/commit.rb

Defined Under Namespace

Modules: HandlerMethods

Class Method Summary collapse

Class Method Details

.execute(root, message) ⇒ Object

Execute git commit with the given message. Returns [success, output_or_error].



39
40
41
42
43
44
45
46
# File 'lib/ruvim/git/commit.rb', line 39

def execute(root, message)
  out, err, status = Open3.capture3("git", "commit", "-m", message, chdir: root)
  if status.success?
    [true, out.strip]
  else
    [false, err.strip]
  end
end

.extract_message(lines) ⇒ Object

Extract commit message from buffer lines (skip # comment lines and trim).



30
31
32
33
34
35
# File 'lib/ruvim/git/commit.rb', line 30

def extract_message(lines)
  msg_lines = lines.reject { |l| l.start_with?("#") }
  # Strip trailing blank lines
  msg_lines.pop while msg_lines.last&.empty?
  msg_lines.join("\n")
end

.prepare(file_path) ⇒ Object

Build the initial content for the commit message buffer. Returns [lines, root, error_message].



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ruvim/git/commit.rb', line 12

def prepare(file_path)
  root, err = Git.repo_root(file_path)
  return [nil, nil, err] unless root

  status_out, err, status = Open3.capture3("git", "status", chdir: root)
  unless status.success?
    return [nil, nil, err.strip]
  end

  lines = [""]
  lines << "# Enter commit message above. Lines starting with '#' are ignored."
  lines << "# Close with :wq to commit, :q! to cancel."
  lines << "#"
  status_out.each_line(chomp: true) { |l| lines << "# #{l}" }
  [lines, root, nil]
end