Module: Git::Whence::CLI

Defined in:
lib/git/whence.rb

Class Method Summary collapse

Class Method Details

.run(argv) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/git/whence.rb', line 7

def run(argv)
  options = parse_options(argv)
  commit = argv[0]
  unless system("git rev-parse --git-dir 1>&2>/dev/null")
    puts "Not in a git directory"
    return 1
  end

  merge = find_merge(commit)
  if merge
    if options[:open] && (pr = merge[/Merge pull request #(\d+) from /, 1]) && (url = origin)
      repo = url[%r{(\w+/[-\w\.]+)}i, 1].to_s.sub(/\.git$/, "")
      exec %Q{open "https://github.com/#{repo}/pull/#{pr}"}
    else
      puts merge
    end
    0
  else
    $stderr.puts "Unable to find commit"
    1
  end
end