Class: VagrantPlugins::Orchestrate::RepoStatus
- Inherits:
-
Object
- Object
- VagrantPlugins::Orchestrate::RepoStatus
- Defined in:
- lib/vagrant-orchestrate/repo_status.rb
Instance Attribute Summary collapse
-
#last_sync ⇒ Object
readonly
Returns the value of attribute last_sync.
-
#local_path ⇒ Object
Returns the value of attribute local_path.
Class Method Summary collapse
- .clean? ⇒ Boolean
- .committed? ⇒ Boolean
-
.untracked? ⇒ Boolean
Return whether there are any untracked files in the git repo.
Instance Method Summary collapse
-
#initialize ⇒ RepoStatus
constructor
A new instance of RepoStatus.
- #ref ⇒ Object
- #remote_origin_url ⇒ Object
-
#remote_path(communicator) ⇒ Object
The path to where this should be stored on a remote machine, inclusive of the file name.
- #repo ⇒ Object
- #to_json ⇒ Object
- #user ⇒ Object
- #write(tmp_path) ⇒ Object
Constructor Details
#initialize ⇒ RepoStatus
Returns a new instance of RepoStatus.
9 10 11 12 |
# File 'lib/vagrant-orchestrate/repo_status.rb', line 9 def initialize @last_sync = Time.now.utc # Managed servers could be in different timezones @local_path = nil end |
Instance Attribute Details
#last_sync ⇒ Object (readonly)
Returns the value of attribute last_sync.
6 7 8 |
# File 'lib/vagrant-orchestrate/repo_status.rb', line 6 def last_sync @last_sync end |
#local_path ⇒ Object
Returns the value of attribute local_path.
7 8 9 |
# File 'lib/vagrant-orchestrate/repo_status.rb', line 7 def local_path @local_path end |
Class Method Details
.clean? ⇒ Boolean
67 68 69 70 |
# File 'lib/vagrant-orchestrate/repo_status.rb', line 67 def self.clean? `git diff --exit-code 2>&1` $CHILD_STATUS == 0 end |
.committed? ⇒ Boolean
72 73 74 75 |
# File 'lib/vagrant-orchestrate/repo_status.rb', line 72 def self.committed? `git diff-index --quiet --cached HEAD 2>&1` $CHILD_STATUS == 0 end |
.untracked? ⇒ Boolean
Return whether there are any untracked files in the git repo
78 79 80 81 82 |
# File 'lib/vagrant-orchestrate/repo_status.rb', line 78 def self.untracked? output = `git ls-files --other --exclude-standard --directory --no-empty-directory 2>&1` # This command lists untracked files. There are untracked files if the ouput is not empty. !output.empty? end |
Instance Method Details
#ref ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/vagrant-orchestrate/repo_status.rb', line 14 def ref # Env vars are here only for testing, since vagrant-spec is executed from # a temp directory and can't use git to get repository information @ref ||= ENV["VAGRANT_ORCHESTRATE_STATUS_TEST_REF"] @ref ||= `git log --pretty=format:'%H' --abbrev-commit -1` @ref end |
#remote_origin_url ⇒ Object
22 23 24 25 26 |
# File 'lib/vagrant-orchestrate/repo_status.rb', line 22 def remote_origin_url @remote_origin_url ||= ENV["VAGRANT_ORCHESTRATE_STATUS_TEST_REMOTE_ORIGIN_URL"] @remote_origin_url ||= `git config --get remote.origin.url`.chomp @remote_origin_url end |
#remote_path(communicator) ⇒ Object
The path to where this should be stored on a remote machine, inclusive of the file name.
59 60 61 62 63 64 65 |
# File 'lib/vagrant-orchestrate/repo_status.rb', line 59 def remote_path(communicator) if communicator == :winrm File.join("c:", "programdata", "vagrant_orchestrate", repo) else File.join("/var", "state", "vagrant_orchestrate", repo) end end |
#repo ⇒ Object
28 29 30 31 |
# File 'lib/vagrant-orchestrate/repo_status.rb', line 28 def repo @repo ||= File.basename(remote_origin_url, ".git") @repo end |
#to_json ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/vagrant-orchestrate/repo_status.rb', line 41 def to_json contents = { repo: repo, remote_url: remote_origin_url, ref: ref, user: user, last_sync: last_sync } JSON.pretty_generate(contents) end |
#user ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/vagrant-orchestrate/repo_status.rb', line 33 def user user = ENV["USER"] || ENV["USERNAME"] || "unknown" user = ENV["USERDOMAIN"] + "\\" + user if ENV["USERDOMAIN"] @user ||= user @user end |
#write(tmp_path) ⇒ Object
52 53 54 55 |
# File 'lib/vagrant-orchestrate/repo_status.rb', line 52 def write(tmp_path) @local_path = File.join(tmp_path, "vagrant_orchestrate_status") File.write(@local_path, to_json) end |