Class: VagrantGitSyncModule::Core::Workspace

Inherits:
Object
  • Object
show all
Defined in:
lib/core/workspace.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ Workspace

Returns a new instance of Workspace.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/core/workspace.rb', line 9

def initialize(env)
  @env = env
  @vagrant_cwd = env[:env].cwd.to_s.strip.chomp('/')
  Dir.chdir(@vagrant_cwd) do
    in_work_tree = %x(git rev-parse --is-inside-work-tree 2> /dev/null).strip
    if in_work_tree == 'true' and Workspace.git_installed
      @unsupported_workspace = false
    else
      @unsupported_workspace = true
    end
  end
end

Instance Attribute Details

#unsupported_workspaceObject (readonly)

Returns the value of attribute unsupported_workspace.



7
8
9
# File 'lib/core/workspace.rb', line 7

def unsupported_workspace
  @unsupported_workspace
end

Class Method Details

.git_installedObject



55
56
57
# File 'lib/core/workspace.rb', line 55

def self.git_installed
  not %x(which git).strip.empty?
end

Instance Method Details

#index_clean?Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
45
# File 'lib/core/workspace.rb', line 39

def index_clean?
  support_check
  Dir.chdir(@vagrant_cwd) do
    result = %x(git status -s).strip
    return result.empty?
  end
end

#is_master?Boolean

Returns:

  • (Boolean)


47
48
49
50
51
52
53
# File 'lib/core/workspace.rb', line 47

def is_master?
  support_check
  Dir.chdir(@vagrant_cwd) do
    result = %x(git rev-parse --abbrev-ref HEAD).strip
    return result == 'master'
  end
end

#is_online?Boolean

If an internet connection is not available, we want to bail out, and not get in the way

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
# File 'lib/core/workspace.rb', line 23

def is_online?
  #Uses a SYN ping vs ICMP to avoid firewall issues.
  #Tries likely ports to determine if computer is up
  tls = Net::Ping::TCP.new(remote_repository, 443, 1)
  http = Net::Ping::TCP.new(remote_repository, 80, 1)
  ssh = Net::Ping::TCP.new(remote_repository, 22, 1)
  tls.ping or http.ping or ssh.ping
end

#updateObject



32
33
34
35
36
37
# File 'lib/core/workspace.rb', line 32

def update
  support_check
  Dir.chdir(@vagrant_cwd) do
    %x(git pull -X theirs -q)
  end
end