Class: Jiragit::Git::Repository

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Repository

Returns a new instance of Repository.



112
113
114
# File 'lib/jiragit/git/repository.rb', line 112

def initialize(path)
  self.path = path
end

Class Method Details

.create(path) ⇒ Object



106
107
108
109
110
# File 'lib/jiragit/git/repository.rb', line 106

def self.create(path)
  Dir.mkdir(path) unless Dir.exists?(path)
  `cd #{path}; git init .` unless File.exists?("#{path}/.git")
  repo = self.new(path)
end

Instance Method Details

#add(filename) ⇒ Object



132
133
134
# File 'lib/jiragit/git/repository.rb', line 132

def add(filename)
  run_command("git add #{filename}")
end

#checkout_branch(branch, &block) ⇒ Object



124
125
126
# File 'lib/jiragit/git/repository.rb', line 124

def checkout_branch(branch, &block)
  run_command("git checkout #{branch}", &block)
end

#checkout_new_branch(branch, &block) ⇒ Object



120
121
122
# File 'lib/jiragit/git/repository.rb', line 120

def checkout_new_branch(branch, &block)
  run_command("git checkout -b #{branch}", &block)
end

#commit(message, &block) ⇒ Object



144
145
146
147
148
149
150
# File 'lib/jiragit/git/repository.rb', line 144

def commit(message, &block)
  number = rand(100)
  run_command("echo '#{message}' > .git_commit_body")
  output = run_command({env: "export GIT_EDITOR=$PWD/spec/git_editor.rb", command:"git commit"}, &block)
  run_command("rm .git_commit_body")
  CommitResponse.new(output)
end

#create(filename, message) ⇒ Object



128
129
130
# File 'lib/jiragit/git/repository.rb', line 128

def create(filename, message)
  run_command("echo '#{message}' > #{filename}")
end

#current_commit(&block) ⇒ Object



180
181
182
# File 'lib/jiragit/git/repository.rb', line 180

def current_commit(&block)
  run_command("git log -1 --format=%H", &block)
end

#log(&block) ⇒ Object



164
165
166
# File 'lib/jiragit/git/repository.rb', line 164

def log(&block)
  run_command("git log", &block)
end

#log_for_one_commit(sha, &block) ⇒ Object



168
169
170
# File 'lib/jiragit/git/repository.rb', line 168

def log_for_one_commit(sha, &block)
  run_command("git log -n 1 #{sha}", &block)
end

#make_a_command_line_commit(&block) ⇒ Object



158
159
160
161
162
# File 'lib/jiragit/git/repository.rb', line 158

def make_a_command_line_commit(&block)
  number = rand(100)
  output = run_command("echo \"#{number}\" > README.md; git add README.md; git commit -m 'command line specified commit message #{number}'", &block)
  CommitResponse.new(output)
end

#make_a_commit(&block) ⇒ Object



152
153
154
155
156
# File 'lib/jiragit/git/repository.rb', line 152

def make_a_commit(&block)
  number = rand(100)
  output = run_command({env: "export GIT_EDITOR=$PWD/spec/git_editor.rb", command:"echo \"#{number}\" > README.md; git add README.md; git commit"}, &block)
  CommitResponse.new(output)
end

#merge(branch, message = "", &block) ⇒ Object



136
137
138
139
140
141
142
# File 'lib/jiragit/git/repository.rb', line 136

def merge(branch, message="", &block)
  number = rand(100)
  run_command("echo '#{message}' > .git_commit_body")
  output = run_command({env: "export GIT_EDITOR=$PWD/spec/git_editor.rb", command:"git merge #{branch}"}, &block)
  run_command("rm .git_commit_body")
  CommitResponse.new(output)
end

#one_line_log(&block) ⇒ Object



172
173
174
# File 'lib/jiragit/git/repository.rb', line 172

def one_line_log(&block)
  run_command("git log --format=oneline", &block)
end

#oneline_log_for_one_commit(sha, &block) ⇒ Object



176
177
178
# File 'lib/jiragit/git/repository.rb', line 176

def oneline_log_for_one_commit(sha, &block)
  run_command("git log --format=oneline -n 1 #{sha}", &block)
end

#originObject



188
189
190
# File 'lib/jiragit/git/repository.rb', line 188

def origin
  run_command("git remote -v")
end

#origin=(path) ⇒ Object



192
193
194
# File 'lib/jiragit/git/repository.rb', line 192

def origin=(path)
  run_command("git remote add origin #{path}")
end

#removeObject



116
117
118
# File 'lib/jiragit/git/repository.rb', line 116

def remove
  `rm -rf #{path}` if Dir.exists?(path)
end

#rootObject



184
185
186
# File 'lib/jiragit/git/repository.rb', line 184

def root
  @path
end