Class: Reflection::Repository

Inherits:
Object
Defined in:
lib/reflection/repository.rb

Attribute Summary

Method Summary

Constructor Details

- (Repository) initialize(new_url, path = nil)

A new instance of Repository

Returns:



27
28
29
30
# File 'lib/reflection/repository.rb', line 27

def initialize(new_url, path = nil)
  self.url = new_url
  self.path = path
end

Attribute Details

- (Object) path

Returns the value of attribute path



8
9
10
# File 'lib/reflection/repository.rb', line 8

def path
  @path
end

- (Object) url

Returns the value of attribute url



7
8
9
# File 'lib/reflection/repository.rb', line 7

def url
  @url
end

Method Details

+ (Object) exists?(path)



19
20
21
22
23
24
25
# File 'lib/reflection/repository.rb', line 19

def self.exists?(path)
  begin
    Git.open(path)
  rescue ArgumentError
    return false
  end      
end

+ (Object) new_from_path(path)



10
11
12
13
14
15
16
17
# File 'lib/reflection/repository.rb', line 10

def self.new_from_path(path)
  unless self.exists?(path)
    raise "'#{path}' is not a valid Git repository"
  end
  
  repo = Git.open(path)
  self.new(repo.remote.url, path)
end

- (Object) clone(path)



47
48
49
# File 'lib/reflection/repository.rb', line 47

def clone(path)
  Git.clone(self.url, path)
end

- (Object) commit_all_new_files



51
52
53
54
55
56
# File 'lib/reflection/repository.rb', line 51

def commit_all_new_files
  repo = Git.open(self.path)
  Reflection.log.debug "Committing all changes.."
  Reflection.log.debug(repo.add)
  Reflection.log.debug(repo.commit_all("Updated stash.")) rescue true
end

- (Object) identifier



32
33
34
# File 'lib/reflection/repository.rb', line 32

def identifier
  Digest::MD5.hexdigest(self.url)
end

- (Object) pull



64
65
66
67
68
# File 'lib/reflection/repository.rb', line 64

def pull
  repo = Git.open(self.path)
  Reflection.log.debug "Pulling.."
  Reflection.log.debug(repo.pull)
end

- (Object) push



58
59
60
61
62
# File 'lib/reflection/repository.rb', line 58

def push
  repo = Git.open(self.path)
  Reflection.log.debug "Pushing commit.."
  Reflection.log.debug(repo.push)
end

- (Object) reset!



41
42
43
44
45
# File 'lib/reflection/repository.rb', line 41

def reset!
  Reflection.log.debug "Resetting target to HEAD"
  repo = Git.open(self.path)
  repo.reset_hard
end

- (Object) same_in_path?(path)



36
37
38
39
# File 'lib/reflection/repository.rb', line 36

def same_in_path?(path)
  git_repo = Git.open(path)
  (git_repo.remote && git_repo.remote.url == self.url) || false
end