Module: RuVim::Git::Log::HandlerMethods

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

Overview

Command handler methods

Instance Method Summary collapse

Instance Method Details

#git_log(ctx, argv: []) ⇒ Object



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
# File 'lib/ruvim/git/log.rb', line 8

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

  root, err = Git.repo_root(file_path)
  unless root
    ctx.editor.echo_error("git log: #{err}")
    return
  end

  filetype = argv.include?("-p") ? "diff" : nil
  buf = ctx.editor.add_virtual_buffer(
    kind: :git_log,
    name: "[Git Log]",
    lines: [""],
    filetype: filetype,
    readonly: true,
    modifiable: false
  )
  buf.options["git_repo_root"] = root
  ctx.editor.switch_to_buffer(buf.id)
  bind_git_buffer_keys(ctx.editor, buf.id)
  ctx.editor.echo("[Git Log] loading...")

  cmd = ["git", "log", *argv]
  ctx.editor.git_stream_handler&.call(buf.id, cmd, root)
end