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



117
118
119
120
121
122
123
# File 'lib/git_wrapper/repository.rb', line 117

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



108
109
110
# File 'lib/git_wrapper/repository.rb', line 108

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

#checkout(commit, new_branch = nil) ⇒ Object



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

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



192
193
194
195
196
197
# File 'lib/git_wrapper/repository.rb', line 192

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



112
113
114
115
# File 'lib/git_wrapper/repository.rb', line 112

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

#diff(commit) ⇒ Object



169
170
171
# File 'lib/git_wrapper/repository.rb', line 169

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

#diff_reverse(commit) ⇒ Object



173
174
175
# File 'lib/git_wrapper/repository.rb', line 173

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

#fetch(remote = nil) ⇒ Object



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

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
105
106
# File 'lib/git_wrapper/repository.rb', line 98

def log(options={})
  if options[:file_name]
    execute(Commands::Log.new(@location).file(options[:file_name]))
  elsif options[:commit]
    execute(Commands::Log.new(@location).commit(options[:commit]))
  else
    execute(Commands::Log.new(@location))
  end
end

#merge(commit) ⇒ Object



157
158
159
# File 'lib/git_wrapper/repository.rb', line 157

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



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

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



153
154
155
# File 'lib/git_wrapper/repository.rb', line 153

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

#reset(options = {}) ⇒ Object



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

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

#revert(commit) ⇒ Object



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

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



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

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



141
142
143
# File 'lib/git_wrapper/repository.rb', line 141

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