Class: Piston::Git::WorkingCopy

Inherits:
WorkingCopy show all
Defined in:
lib/piston/git/working_copy.rb

Instance Attribute Summary

Attributes inherited from WorkingCopy

#path

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from WorkingCopy

add_handler, #after_remember, #copy_from, guess, handlers, #import, #info, #initialize, #logger, logger, #pistonized?, #recall, #remember, #temp_dir_name, #to_s, #update, #validate!

Constructor Details

This class inherits a constructor from Piston::WorkingCopy

Class Method Details

.clientObject



36
37
38
# File 'lib/piston/git/working_copy.rb', line 36

def client
  @@client ||= Piston::Git::Client.instance
end

.git(*args) ⇒ Object



40
41
42
# File 'lib/piston/git/working_copy.rb', line 40

def git(*args)
  client.git(*args)
end

.understands_dir?(dir) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/piston/git/working_copy.rb', line 11

def understands_dir?(dir)
  path = dir
  begin
    begin
      logger.debug {"git status on #{path}"}
      Dir.chdir(path) do
        response = git(:status)
        return true if response =~ /# On branch /
      end
    rescue Errno::ENOENT
      # NOP, we assume this is simply because the folder hasn't been created yet
      path = path.parent
      retry unless path.to_s == "/"
      return false
    end
  rescue Piston::Git::Client::BadCommand
    # NOP, as we return false below
  rescue Piston::Git::Client::CommandError
    # This is certainly not a Git repository
    false
  end

  false
end

Instance Method Details

#createObject



49
50
51
# File 'lib/piston/git/working_copy.rb', line 49

def create
  path.mkpath rescue nil
end

#exist?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/piston/git/working_copy.rb', line 53

def exist?
  path.directory?
end

#finalizeObject



57
58
59
# File 'lib/piston/git/working_copy.rb', line 57

def finalize
  Dir.chdir(path) { git(:add, ".") }
end

#git(*args) ⇒ Object



45
46
47
# File 'lib/piston/git/working_copy.rb', line 45

def git(*args)
  self.class.git(*args)
end