module RubyGitHooks::GitOps
Constants
- Hook
applypatch-msg, pre-applypatch, post-applypatch prepare-commit-msg, commit-msg pre-rebase, post-checkout, post-merge, update, post-update, pre-auto-gc, post-rewrite
Public Instance Methods
add_hook(repo_name, hook_name, contents)
click to toggle source
# File lib/ruby_git_hooks/git_ops.rb, line 23 def add_hook(repo_name, hook_name, contents) # We're adding to either a normal or bare directory. # Check for hooks directory. if File.exist? "#{repo_name}/.git/hooks" hooks_dir = "#{repo_name}/.git/hooks" elsif File.exist? "#{repo_name}/hooks" hooks_dir = "#{repo_name}/hooks" else raise "Can't locate hooks directory under #{repo_name.inspect}!" end filename = File.join(hooks_dir, hook_name) File.open(filename, "w") do |f| f.write(contents) end Hook.shell!("chmod +x #{filename}") end
clone_repo(parent_name = "parent_repo.git", child_name = "child_repo")
click to toggle source
# File lib/ruby_git_hooks/git_ops.rb, line 19 def clone_repo(parent_name = "parent_repo.git", child_name = "child_repo") Hook.shell! "git clone #{parent_name} #{child_name}" end
git_checkout(repo_name="child_repo", branch_name="master")
click to toggle source
# File lib/ruby_git_hooks/git_ops.rb, line 105 def git_checkout(repo_name="child_repo", branch_name="master") Hook.shell! "cd #{repo_name} && git checkout #{branch_name}" end
git_commit(repo_name = "child_repo", commit_message = "Generic commit message")
click to toggle source
# File lib/ruby_git_hooks/git_ops.rb, line 85 def git_commit(repo_name = "child_repo", commit_message = "Generic commit message") Hook.shell! "cd #{repo_name} && git commit -m \"#{commit_message}\"" end
git_create_and_checkout_branch(repo_name="child_repo", branch_name="B1")
click to toggle source
# File lib/ruby_git_hooks/git_ops.rb, line 109 def git_create_and_checkout_branch(repo_name="child_repo", branch_name="B1") Hook.shell! "cd #{repo_name} && git checkout -b #{branch_name}" end
git_delete(repo_name="child_repo", filename="file_to_delete")
click to toggle source
# File lib/ruby_git_hooks/git_ops.rb, line 71 def git_delete(repo_name="child_repo", filename="file_to_delete") # filename is a file that has already been added and commited to the repo Hook.shell! "cd #{repo_name} && git rm #{filename}" end
git_ff_merge(repo_name = "child_repo", branch = "B1", msg = "Merge branch
click to toggle source
# File lib/ruby_git_hooks/git_ops.rb, line 126 def git_ff_merge(repo_name = "child_repo", branch = "B1", msg = "Merge branch #{branch}") # better be sure there's not going to be a conflict Hook.shell!("cd #{repo_name} && git merge #{branch} --ff") end
git_merge(repo_name = "child_repo", branch = "B1", msg = "Merge branch
click to toggle source
# File lib/ruby_git_hooks/git_ops.rb, line 121 def git_merge(repo_name = "child_repo", branch = "B1", msg = "Merge branch #{branch}") # better be sure there's not going to be a conflict Hook.shell!("cd #{repo_name} && git merge #{branch} --no-ff -m '#{msg}'") end
git_push(repo_name = "child_repo", remote = "origin", branch = "master")
click to toggle source
# File lib/ruby_git_hooks/git_ops.rb, line 89 def git_push(repo_name = "child_repo", remote = "origin", branch = "master") Hook.shell! "cd #{repo_name} && git push #{remote} #{branch}" end
git_push_all(repo_name = "child_repo")
click to toggle source
# File lib/ruby_git_hooks/git_ops.rb, line 113 def git_push_all(repo_name = "child_repo") Hook.shell! "cd #{repo_name} && git push --all" end
git_rename(repo_name="child_repo", filename="file_to_rename", new_filename)
click to toggle source
# File lib/ruby_git_hooks/git_ops.rb, line 76 def git_rename(repo_name="child_repo", filename="file_to_rename", new_filename) # filename is a file that has already been added and commited to the repo Hook.shell! "cd #{repo_name} && git mv #{filename} #{new_filename}" end
git_revlist_all(repo_name = "child_repo")
click to toggle source
# File lib/ruby_git_hooks/git_ops.rb, line 117 def git_revlist_all(repo_name = "child_repo") Hook.shell!("cd #{repo_name} && git rev-list --all").split("\n") end
git_tag(repo_name="child_repo", tagname="0.1")
click to toggle source
# File lib/ruby_git_hooks/git_ops.rb, line 101 def git_tag(repo_name="child_repo", tagname="0.1") Hook.shell! "cd #{repo_name} && git tag -a #{tagname} -m 'test'" end
last_commit_message(repo_name = "child_repo")
click to toggle source
# File lib/ruby_git_hooks/git_ops.rb, line 97 def last_commit_message(repo_name = "child_repo") Hook.shell!("cd #{repo_name} && git log -1").chomp end
last_commit_sha(repo_name = "child_repo")
click to toggle source
# File lib/ruby_git_hooks/git_ops.rb, line 81 def last_commit_sha(repo_name = "child_repo") Hook.shell!("cd #{repo_name} && git log -n 1 --format=%H").chomp end
new_bare_repo(name = "parent_repo.git")
click to toggle source
# File lib/ruby_git_hooks/git_ops.rb, line 15 def new_bare_repo(name = "parent_repo.git") Hook.shell! "mkdir #{name} && cd #{name} && git init --bare" end
new_commit(repo_name, filename, contents = "Contents", commit_message = "Single-file commit of
click to toggle source
# File lib/ruby_git_hooks/git_ops.rb, line 41 def new_commit(repo_name, filename, contents = "Contents", commit_message = "Single-file commit of #{filename}") if !contents.nil? File.open(File.join(repo_name, filename), "w") do |f| f.write(contents) end end Hook.shell! "cd #{repo_name} && git add #{filename} && git commit -m \"#{commit_message}\"" end
new_multi_file_commit(num_files = 3, repo_name = "child_repo", commit_message = "multi-file commit", base_filename = "test", contents="Contents")
click to toggle source
# File lib/ruby_git_hooks/git_ops.rb, line 61 def new_multi_file_commit(num_files = 3, repo_name = "child_repo", commit_message = "multi-file commit", base_filename = "test", contents="Contents") (1..num_files).each do |num| File.open(File.join(repo_name, base_filename + num.to_s), "w") do |f| f.write(contents) end end Hook.shell! "cd #{repo_name} && git add . && git commit -m \"#{commit_message}\"" end
new_single_file_commit(repo_name = "child_repo", contents = "Single-file commit")
click to toggle source
# File lib/ruby_git_hooks/git_ops.rb, line 51 def new_single_file_commit(repo_name = "child_repo", contents = "Single-file commit") @single_file_counter ||= 1 filename = "test_file_#{@single_file_counter}" new_commit(repo_name, filename, contents) @single_file_counter += 1 end
rewind_one_commit(repo_name = "child_repo")
click to toggle source
# File lib/ruby_git_hooks/git_ops.rb, line 93 def rewind_one_commit(repo_name = "child_repo") Hook.shell! "cd #{repo_name} && git reset --hard HEAD~" end