class Rlt::Utils::GitUtil
Constants
- NATIVE_COMMANDS
git help -a
Public Class Methods
add_all()
click to toggle source
# File lib/rlt/utils/git_util.rb, line 36 def self.add_all Shell.new.run 'git add -A' end
any_conflict?()
click to toggle source
# File lib/rlt/utils/git_util.rb, line 93 def self.any_conflict? !`git diff --name-only --diff-filter=U`.strip.empty? end
apply_stash(name, opts = {})
click to toggle source
# File lib/rlt/utils/git_util.rb, line 57 def self.apply_stash(name, opts = {}) Logger.info 'Applied stash' if opts[:print_info] Shell.new.run 'git stash apply', name, '--index' end
checkout(branch_name, opts = {})
click to toggle source
# File lib/rlt/utils/git_util.rb, line 67 def self.checkout(branch_name, opts = {}) Logger.info "Switching to `#{branch_name}`" if opts[:print_info] Shell.new.run 'git checkout', branch_name end
clean_untracked()
click to toggle source
# File lib/rlt/utils/git_util.rb, line 115 def self.clean_untracked Shell.new.run 'git clean -fd' end
commit_with_long_message(message)
click to toggle source
# File lib/rlt/utils/git_util.rb, line 80 def self.commit_with_long_message(message) Logger.verbose message if Rlt.debug commit_msg_file_path = "#{Dir.tmpdir}/.rlt.commit.msg.#{StringUtil.short_random_string}" File.write(commit_msg_file_path, message) Shell.new.run 'git commit -F', commit_msg_file_path File.delete(commit_msg_file_path) end
current_branch_name()
click to toggle source
# File lib/rlt/utils/git_util.rb, line 32 def self.current_branch_name `git rev-parse --abbrev-ref HEAD`.strip end
delete_branch(branch_name, opts = {})
click to toggle source
# File lib/rlt/utils/git_util.rb, line 97 def self.delete_branch(branch_name, opts = {}) Logger.info "Deleting `#{branch_name}`" if opts[:print_info] Shell.new.run 'git branch -d', branch_name end
drop_stash(name, opts = {})
click to toggle source
# File lib/rlt/utils/git_util.rb, line 62 def self.drop_stash(name, opts = {}) Logger.info 'Dropped stash' if opts[:print_info] Shell.new.run 'git stash drop', name end
execute_native_command(args)
click to toggle source
# File lib/rlt/utils/git_util.rb, line 28 def self.execute_native_command(args) Shell.new.run 'git', *args end
latest_stash_name(branch_name)
click to toggle source
# File lib/rlt/utils/git_util.rb, line 44 def self.latest_stash_name(branch_name) line = `git stash list`.strip.split("\n").find do |l| l.split(':')[1].strip == "On #{branch_name}" end return nil if line.nil? line.split(':').first end
merge_from(branch_name, opts = {})
click to toggle source
# File lib/rlt/utils/git_util.rb, line 88 def self.merge_from(branch_name, opts = {}) Logger.info "Merging from `#{branch_name}`" if opts[:print_info] Shell.new.run 'git merge', branch_name end
remotes()
click to toggle source
# File lib/rlt/utils/git_util.rb, line 102 def self.remotes `git remote`.strip.split('\n') end
reset_hard_head()
click to toggle source
# File lib/rlt/utils/git_util.rb, line 111 def self.reset_hard_head Shell.new.run 'git reset --hard HEAD' end
safely_delete_remote_branch(remote, branch_name, opts = {})
click to toggle source
# File lib/rlt/utils/git_util.rb, line 106 def self.safely_delete_remote_branch(remote, branch_name, opts = {}) Logger.info "Try deleting remote branch: #{remote}/#{branch_name}" if opts[:print_info] Shell.new.run_safely 'git push', remote, ":#{branch_name}" end
save_stash(message, opts = {})
click to toggle source
# File lib/rlt/utils/git_util.rb, line 52 def self.save_stash(message, opts = {}) Logger.info 'Saving stash' if opts[:print_info] Shell.new.run 'git stash save', '--include-untracked', message end
silently_create_and_checkout(branch_name)
click to toggle source
# File lib/rlt/utils/git_util.rb, line 76 def self.silently_create_and_checkout(branch_name) Shell.new(no_output: true).run 'git checkout -b', branch_name end
silently_try_checkout(branch_name)
click to toggle source
# File lib/rlt/utils/git_util.rb, line 72 def self.silently_try_checkout(branch_name) Shell.new(no_output: true).run_safely 'git checkout', branch_name end
uncommitted_change?()
click to toggle source
# File lib/rlt/utils/git_util.rb, line 40 def self.uncommitted_change? !`git status -s`.strip.empty? end