Class: Herdsman::GitRepo

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

Defined Under Namespace

Classes: StatusParser

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env, path) ⇒ GitRepo

Returns a new instance of GitRepo.



6
7
8
9
# File 'lib/herdsman/git_repo.rb', line 6

def initialize(env, path)
  @env  = env
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/herdsman/git_repo.rb', line 5

def path
  @path
end

Instance Method Details

#current_headObject



24
25
26
# File 'lib/herdsman/git_repo.rb', line 24

def current_head
  current_branch_name || current_tag_name || abbreviated_commit_ref
end

#fetch!Object



19
20
21
22
# File 'lib/herdsman/git_repo.rb', line 19

def fetch!
  _, _, proc_status = git_command('fetch --all')
  raise 'Fetch failed' unless proc_status.exitstatus.zero?
end

#git_dirObject



15
16
17
# File 'lib/herdsman/git_repo.rb', line 15

def git_dir
  git_output('rev-parse --git-dir')
end

#has_modified_files?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/herdsman/git_repo.rb', line 32

def has_modified_files?
  status.modified_files.any?
end

#has_unpulled_commits?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/herdsman/git_repo.rb', line 40

def has_unpulled_commits?
  git_output('log --oneline ..@{u}').lines.any?
end

#has_unpushed_commits?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/herdsman/git_repo.rb', line 36

def has_unpushed_commits?
  git_output('log --oneline @{u}..').lines.any?
end

#has_untracked_files?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/herdsman/git_repo.rb', line 28

def has_untracked_files?
  status.untracked_files.any?
end

#initialized?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/herdsman/git_repo.rb', line 11

def initialized?
  !git_dir.empty? && File.exist?(path + '/' + git_dir)
end

#last_fetchedObject



50
51
52
53
54
# File 'lib/herdsman/git_repo.rb', line 50

def last_fetched
  File.mtime(File.join(File.expand_path(path, Dir.pwd), '.git/FETCH_HEAD'))
rescue
  Time.at(0)
end

#revision?(revision) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
47
48
# File 'lib/herdsman/git_repo.rb', line 44

def revision?(revision)
  [current_branch_name, current_tag_name, abbreviated_commit_ref].include?(
    revision,
  )
end