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
21
22
23
24
25
# 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 = ""
    if Vagrant::Util::Platform.windows? then
      in_work_tree = %x(git rev-parse --is-inside-work-tree 2> $null).strip
    else
      in_work_tree = %x(git rev-parse --is-inside-work-tree 2> /dev/null).strip
    end
    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



60
61
62
63
64
65
66
67
68
# File 'lib/core/workspace.rb', line 60

def self.git_installed
  result = ""
  if Vagrant::Util::Platform.windows? then
    result = %x(where.exe git).strip
  else
    result = %x(which git).strip
  end
  not result.empty?
end

Instance Method Details

#index_clean?Boolean

Returns:

  • (Boolean)


44
45
46
47
48
49
50
# File 'lib/core/workspace.rb', line 44

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)


52
53
54
55
56
57
58
# File 'lib/core/workspace.rb', line 52

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)


28
29
30
31
32
33
34
35
# File 'lib/core/workspace.rb', line 28

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



37
38
39
40
41
42
# File 'lib/core/workspace.rb', line 37

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