Class: Herdsman::GitRepo
- Inherits:
-
Object
- Object
- Herdsman::GitRepo
- Defined in:
- lib/herdsman/git_repo.rb
Defined Under Namespace
Classes: StatusParser
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #current_head ⇒ Object
- #fetch! ⇒ Object
- #git_dir ⇒ Object
- #has_modified_files? ⇒ Boolean
- #has_unpulled_commits? ⇒ Boolean
- #has_unpushed_commits? ⇒ Boolean
- #has_untracked_files? ⇒ Boolean
-
#initialize(env, path) ⇒ GitRepo
constructor
A new instance of GitRepo.
- #initialized? ⇒ Boolean
- #last_fetched ⇒ Object
- #revision?(revision) ⇒ Boolean
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
#path ⇒ Object (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_head ⇒ Object
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_dir ⇒ Object
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
32 33 34 |
# File 'lib/herdsman/git_repo.rb', line 32 def has_modified_files? status.modified_files.any? end |
#has_unpulled_commits? ⇒ 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
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
28 29 30 |
# File 'lib/herdsman/git_repo.rb', line 28 def has_untracked_files? status.untracked_files.any? end |
#initialized? ⇒ Boolean
11 12 13 |
# File 'lib/herdsman/git_repo.rb', line 11 def initialized? !git_dir.empty? && File.exist?(path + '/' + git_dir) end |
#last_fetched ⇒ Object
50 51 52 53 54 |
# File 'lib/herdsman/git_repo.rb', line 50 def last_fetched File.mtime(File.join(File.(path, Dir.pwd), '.git/FETCH_HEAD')) rescue Time.at(0) end |
#revision?(revision) ⇒ 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 |