Class: Danger::GitRepo

Inherits:
Object
  • Object
show all
Defined in:
lib/danger/scm_source/git_repo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#diffObject

Returns the value of attribute diff.



7
8
9
# File 'lib/danger/scm_source/git_repo.rb', line 7

def diff
  @diff
end

#logObject

Returns the value of attribute log.



7
8
9
# File 'lib/danger/scm_source/git_repo.rb', line 7

def log
  @log
end

Instance Method Details

#diff_for_folder(folder, from: "master", to: "HEAD") ⇒ Object



9
10
11
12
13
14
15
# File 'lib/danger/scm_source/git_repo.rb', line 9

def diff_for_folder(folder, from: "master", to: "HEAD")
  repo = Git.open folder

  merge_base = repo.merge_base(from, to)
  self.diff = repo.diff(merge_base.to_s, to)
  self.log = repo.log.between(from, to)
end

#exec(string) ⇒ Object



17
18
19
# File 'lib/danger/scm_source/git_repo.rb', line 17

def exec(string)
  `git #{string}`.strip
end

#head_commitObject



21
22
23
# File 'lib/danger/scm_source/git_repo.rb', line 21

def head_commit
  exec "rev-parse HEAD"
end

#originsObject



25
26
27
# File 'lib/danger/scm_source/git_repo.rb', line 25

def origins
  exec("remote show origin -n").lines.grep(/Fetch URL/)[0].split(": ", 2)[1].chomp
end