Class: GitWrapper::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/git_wrapper/repository.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location) ⇒ Repository

Returns a new instance of Repository.



7
8
9
10
11
# File 'lib/git_wrapper/repository.rb', line 7

def initialize(location)
  @location = location
  @log_output = []
  @log_error = []
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



3
4
5
# File 'lib/git_wrapper/repository.rb', line 3

def location
  @location
end

#log_errorObject (readonly)

Returns the value of attribute log_error.



5
6
7
# File 'lib/git_wrapper/repository.rb', line 5

def log_error
  @log_error
end

#log_outputObject (readonly)

Returns the value of attribute log_output.



4
5
6
# File 'lib/git_wrapper/repository.rb', line 4

def log_output
  @log_output
end

Instance Method Details

#add(file_name) ⇒ Object



38
39
40
# File 'lib/git_wrapper/repository.rb', line 38

def add(file_name)
  execute(Commands::Add.new(@location).file(file_name))
end

#add_allObject



42
43
44
# File 'lib/git_wrapper/repository.rb', line 42

def add_all
  execute(Commands::Add.new(@location).all)
end

#add_remote(name, url) ⇒ Object



60
61
62
# File 'lib/git_wrapper/repository.rb', line 60

def add_remote(name, url)
  execute(Commands::Remote.new(@location).name(name).add(url))
end

#bare?Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
# File 'lib/git_wrapper/repository.rb', line 27

def bare?
  Dir.exist?("#{@location}/hooks") &&
      Dir.exist?("#{@location}/info") &&
      Dir.exist?("#{@location}/objects") &&
      Dir.exist?("#{@location}/refs")
end

#branch(name, commit = nil) ⇒ Object



131
132
133
134
135
136
137
# File 'lib/git_wrapper/repository.rb', line 131

def branch(name, commit=nil)
  if commit.nil?
    execute(Commands::Branch.new(@location).create(name))
  else
    execute(Commands::Branch.new(@location).create(name).from(commit))
  end
end

#branchesObject



122
123
124
# File 'lib/git_wrapper/repository.rb', line 122

def branches
  execute(Commands::Branch.new(@location).list)
end

#checkout(commit, new_branch = nil) ⇒ Object



147
148
149
150
151
152
153
# File 'lib/git_wrapper/repository.rb', line 147

def checkout(commit, new_branch=nil)
  if commit.nil?
    execute(Commands::Checkout.new(@location).commit(commit))
  else
    execute(Commands::Checkout.new(@location).commit(commit).into(new_branch))
  end
end

#commit(message, options = {}) ⇒ Object



46
47
48
49
50
# File 'lib/git_wrapper/repository.rb', line 46

def commit(message, options={})
  command = Commands::Commit.new(@location).message(message)
  command.author(options[:author_name], options[:author_email]) if options[:author_name] && options[:author_email]
  execute(command)
end

#config(key = nil, value = nil) ⇒ Object



210
211
212
213
214
215
# File 'lib/git_wrapper/repository.rb', line 210

def config(key=nil, value=nil)
  command = Commands::Config.new(@location)
  command.key(key) if key
  command.value(value) if value
  execute(command)
end

#current_branchObject



126
127
128
129
# File 'lib/git_wrapper/repository.rb', line 126

def current_branch
  branch = execute(Commands::Branch.new(@location).current)
  branch.nil? ? 'master' : branch
end

#diff(commit) ⇒ Object



183
184
185
# File 'lib/git_wrapper/repository.rb', line 183

def diff(commit)
  execute(Commands::Diff.new(@location).with(commit))
end

#diff_reverse(commit) ⇒ Object



187
188
189
# File 'lib/git_wrapper/repository.rb', line 187

def diff_reverse(commit)
  execute(Commands::Diff.new(@location).with(commit).reverse)
end

#diff_tree(commit) ⇒ Object



191
192
193
# File 'lib/git_wrapper/repository.rb', line 191

def diff_tree(commit)
  execute(Commands::DiffTree.new(@location).commit(commit))
end

#fetch(remote = nil) ⇒ Object



175
176
177
178
179
180
181
# File 'lib/git_wrapper/repository.rb', line 175

def fetch(remote=nil)
  if remote.nil?
    execute(Commands::Fetch.new(@location).all)
  else
    execute(Commands::Fetch.new(@location).remote(remote))
  end
end

#initObject



13
14
15
16
# File 'lib/git_wrapper/repository.rb', line 13

def init
  FileUtils.mkpath(@location) unless Dir.exist?(@location)
  execute(Commands::Init.new(@location))
end

#init_bareObject



18
19
20
21
# File 'lib/git_wrapper/repository.rb', line 18

def init_bare
  FileUtils.mkpath(@location) unless Dir.exist?(@location)
  execute(Commands::Init.new(@location).bare)
end

#initialized?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/git_wrapper/repository.rb', line 23

def initialized?
  Dir.exist?("#{@location}/.git") || bare?
end

#log(options = {}) ⇒ Object



98
99
100
101
102
103
104
# File 'lib/git_wrapper/repository.rb', line 98

def log(options={})
  command = Commands::Log.new(@location)
  options.each do |option, value|
    command.send option, value if value && !value.to_s.strip.empty?
  end
  execute(command)
end

#merge(commit) ⇒ Object



171
172
173
# File 'lib/git_wrapper/repository.rb', line 171

def merge(commit)
  execute(Commands::Merge.new(@location).commit(commit))
end

#pull(remote = 'origin', branch = 'master') ⇒ Object



68
69
70
# File 'lib/git_wrapper/repository.rb', line 68

def pull(remote='origin', branch='master')
  execute(Commands::Pull.new(@location).remote(remote).branch(branch))
end

#push(remote = 'origin', branch = 'master') ⇒ Object



72
73
74
# File 'lib/git_wrapper/repository.rb', line 72

def push(remote='origin', branch='master')
  execute(Commands::Push.new(@location).remote(remote).branch(branch))
end

#push_tags(remote = 'origin') ⇒ Object



76
77
78
# File 'lib/git_wrapper/repository.rb', line 76

def push_tags(remote='origin')
  execute(Commands::Push.new(@location).remote(remote).tags)
end

#remotesObject



56
57
58
# File 'lib/git_wrapper/repository.rb', line 56

def remotes
  execute(Commands::Remote.new(@location).list)
end

#remove(file_name) ⇒ Object



52
53
54
# File 'lib/git_wrapper/repository.rb', line 52

def remove(file_name)
  execute(Commands::Remove.new(@location).file(file_name))
end

#remove_branch(name, remote = nil) ⇒ Object



139
140
141
142
143
144
145
# File 'lib/git_wrapper/repository.rb', line 139

def remove_branch(name, remote=nil)
  if remote.nil?
    execute(Commands::Branch.new(@location).remove(name))
  else
    execute(Commands::Branch.new(@location).remove(name).remote(remote))
  end
end

#remove_remote(name) ⇒ Object



64
65
66
# File 'lib/git_wrapper/repository.rb', line 64

def remove_remote(name)
  execute(Commands::Remote.new(@location).name(name).remove)
end

#remove_tag(name) ⇒ Object



167
168
169
# File 'lib/git_wrapper/repository.rb', line 167

def remove_tag(name)
  execute(Commands::Tag.new(@location).remove(name))
end

#reset(options = {}) ⇒ Object



203
204
205
206
207
208
# File 'lib/git_wrapper/repository.rb', line 203

def reset(options={})
  command = Commands::Reset.new(@location)
  command.commit(options[:commit]) if options[:commit]
  command.send(options[:mode]) if options[:mode]
  execute(command)
end

#rev_list(options = {}) ⇒ Object



106
107
108
109
110
111
112
# File 'lib/git_wrapper/repository.rb', line 106

def rev_list(options={})
  command = Commands::RevList.new(@location)
  options.each do |option, value|
    command.send option, value if value && !value.to_s.strip.empty?
  end
  execute(command)
end

#rev_list_count(options = {}) ⇒ Object



114
115
116
117
118
119
120
# File 'lib/git_wrapper/repository.rb', line 114

def rev_list_count(options={})
  command = Commands::RevList.new(@location).count
  options.each do |option, value|
    command.send option, value if value && !value.to_s.strip.empty?
  end
  execute(command)
end

#revert(commit) ⇒ Object



195
196
197
198
199
200
201
# File 'lib/git_wrapper/repository.rb', line 195

def revert(commit)
  if log(:commit => commit).merge?
    execute(Commands::Revert.new(@location).merge(commit))
  else
    execute(Commands::Revert.new(@location).commit(commit))
  end
end

#show(file_name, commit = nil) ⇒ Object



80
81
82
83
84
# File 'lib/git_wrapper/repository.rb', line 80

def show(file_name, commit=nil)
  command = Commands::Show.new(@location).file(file_name)
  command.commit(commit) unless commit.nil?
  execute(command)
end

#show_base(file_name) ⇒ Object



86
87
88
# File 'lib/git_wrapper/repository.rb', line 86

def show_base(file_name)
  execute(Commands::Show.new(@location).file(file_name).base)
end

#show_mine(file_name) ⇒ Object



90
91
92
# File 'lib/git_wrapper/repository.rb', line 90

def show_mine(file_name)
  execute(Commands::Show.new(@location).file(file_name).mine)
end

#show_theirs(file_name) ⇒ Object



94
95
96
# File 'lib/git_wrapper/repository.rb', line 94

def show_theirs(file_name)
  execute(Commands::Show.new(@location).file(file_name).theirs)
end

#statusObject



34
35
36
# File 'lib/git_wrapper/repository.rb', line 34

def status
  execute(Commands::Status.new(@location))
end

#tag(name, commit = nil) ⇒ Object



159
160
161
162
163
164
165
# File 'lib/git_wrapper/repository.rb', line 159

def tag(name, commit=nil)
  if commit.nil?
    execute(Commands::Tag.new(@location).create(name))
  else
    execute(Commands::Tag.new(@location).create(name).from(commit))
  end
end

#tagsObject



155
156
157
# File 'lib/git_wrapper/repository.rb', line 155

def tags
  execute(Commands::Tag.new(@location).list)
end