Module: RuVim::Git::Commit::HandlerMethods

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

Overview

Command handler methods

Instance Method Summary collapse

Instance Method Details

#git_commit(ctx) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ruvim/git/commit.rb', line 50

def git_commit(ctx, **)
  file_path = git_resolve_path(ctx)
  unless file_path
    ctx.editor.echo_error("No file or directory to resolve git repo")
    return
  end

  lines, root, err = Commit.prepare(file_path)
  unless lines
    ctx.editor.echo_error("git commit: #{err}")
    return
  end

  buf = ctx.editor.add_virtual_buffer(
    kind: :git_commit,
    name: "[Commit Message]",
    lines: lines,
    readonly: false,
    modifiable: true
  )
  buf.options["git_repo_root"] = root
  ctx.editor.switch_to_buffer(buf.id)
  ctx.editor.enter_insert_mode
  ctx.editor.echo("[Commit Message] :wq to commit, :q! to cancel")
end

#git_commit_execute(ctx) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/ruvim/git/commit.rb', line 76

def git_commit_execute(ctx, **)
  buf = ctx.buffer
  unless buf.kind == :git_commit
    ctx.editor.echo_error("Not a git commit buffer")
    return
  end

  message = Commit.extract_message(buf.lines)
  if message.empty?
    ctx.editor.echo_error("Empty commit message, aborting")
    return
  end

  root = buf.options["git_repo_root"]
  success, output = Commit.execute(root, message)
  ctx.editor.delete_buffer(buf.id)

  if success
    ctx.editor.echo(output)
  else
    ctx.editor.echo_error("git commit: #{output}")
  end
end