Class: Dependabot::Workspace::Git

Inherits:
Base
  • Object
show all
Defined in:
lib/dependabot/workspace/git.rb

Constant Summary collapse

USER =
"dependabot[bot]"
EMAIL =
"#{USER}@users.noreply.github.com".freeze

Instance Attribute Summary collapse

Attributes inherited from Base

#change_attempts, #path

Instance Method Summary collapse

Methods inherited from Base

#change, #changes, #failed_change_attempts

Constructor Details

#initialize(path) ⇒ Git

Returns a new instance of Git.



15
16
17
18
19
# File 'lib/dependabot/workspace/git.rb', line 15

def initialize(path)
  super(path)
  @initial_head_sha = head_sha
  configure_git
end

Instance Attribute Details

#initial_head_shaObject (readonly)

Returns the value of attribute initial_head_sha.



13
14
15
# File 'lib/dependabot/workspace/git.rb', line 13

def initial_head_sha
  @initial_head_sha
end

Instance Method Details

#changed?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/dependabot/workspace/git.rb', line 21

def changed?
  changes.any? || !changed_files.empty?
end

#reset!Object



29
30
31
32
33
34
35
36
# File 'lib/dependabot/workspace/git.rb', line 29

def reset!
  reset(initial_head_sha)
  clean
  run_shell_command("git stash clear")
  @change_attempts = []

  nil
end

#store_change(memo = nil) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/dependabot/workspace/git.rb', line 38

def store_change(memo = nil)
  return nil if changed_files.empty?

  debug("store_change - before: #{current_commit}")
  sha, diff = commit(memo)

  change_attempts << ChangeAttempt.new(self, id: sha, memo: memo, diff: diff)
ensure
  debug("store_change - after: #{current_commit}")
end

#to_patchObject



25
26
27
# File 'lib/dependabot/workspace/git.rb', line 25

def to_patch
  run_shell_command("git diff --patch #{@initial_head_sha}.. .")
end