Class: JIRADiff::Git

Inherits:
Object
  • Object
show all
Defined in:
lib/jira_diff/git.rb

Instance Method Summary collapse

Constructor Details

#initialize(dir = '.') ⇒ Git

Returns a new instance of Git.

Raises:

  • (StandardError)


6
7
8
9
10
11
# File 'lib/jira_diff/git.rb', line 6

def initialize(dir = '.')
  raise StandardError, "Directory '#{dir}' is not valid" unless Dir.exist?(dir)
  raise RuntimeError, "Doesn't look like '#{dir}' is a Git repository" unless Dir.exist?(File.join(dir, '.git'))

  @working_dir = dir
end

Instance Method Details

#branch_valid?(branch) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/jira_diff/git.rb', line 18

def branch_valid?(branch)
  run_command("\\git branch --list #{branch}")[0] =~ /#{branch}/
end

#log(branch) ⇒ Object

Raises:

  • (RuntimeError)


13
14
15
16
# File 'lib/jira_diff/git.rb', line 13

def log(branch)
  raise RuntimeError, "Invalid branch: #{branch}" unless branch_valid? branch
  run_command("\\git --no-pager log --no-merges --pretty='%H|%s' #{branch}")
end