class GitNuke
universal version tracking
Constants
- Help
- Version
Public Class Methods
new(test=false)
click to toggle source
# File lib/git-nuke.rb, line 15 def initialize(test=false) @pdelay = 0.01 # constant for arrow speed @testing = test @verify = !test end
Public Instance Methods
fire(args = [])
click to toggle source
# File lib/git-nuke.rb, line 21 def fire(args = []) opts = args.select {|a| a[0] == "-" } opts.each {|o| parse_opt o } exit 0 if (@testing || opts.first) parse_arg((args - opts).first) end
git_root()
click to toggle source
# File lib/git-nuke.rb, line 53 def git_root %x{git rev-parse --show-toplevel} end
no_repo?()
click to toggle source
# File lib/git-nuke.rb, line 48 def no_repo? `git status 2>&1`.split("\n").first == "fatal: Not a git repository (or any of the parent directories): .git" end
nuke(remote, root)
click to toggle source
overwrite the local copy of the repository with the remote one
# File lib/git-nuke.rb, line 108 def nuke(remote, root) # remove the git repo from this computer if !@testing tree = Dir.glob("*", File::FNM_DOTMATCH).select {|d| not ['.','..'].include? d } FileUtils.rmtree (tree) end cloner = "git clone \"#{remote}\" \"#{root}\"" puts "Recloned successfully.".green if system(cloner) end
parse_arg(a)
click to toggle source
# File lib/git-nuke.rb, line 44 def parse_arg(a) a.nil?? verify(remote) : verify(remote(a)) end
parse_opt(o)
click to toggle source
# File lib/git-nuke.rb, line 33 def parse_opt(o) case o when "--force", "-f" @verify = false when "--help", "-h" puts GitNuke::Help when "--version", "-v" puts GitNuke::Version end end
pexit(msg)
click to toggle source
# File lib/git-nuke.rb, line 28 def pexit(msg) puts msg exit 1 end
remote(search = /.*/)
click to toggle source
trying to parse out which remote should be the new source
# File lib/git-nuke.rb, line 73 def remote(search = /.*/) pexit "Not currently in a git repository.".yellow if no_repo? r = remotes.find { |gr| gr.match search } pexit "No remotes found in this repository.".yellow if remotes.nil? if r.nil? errmsg = "No remotes found that match #{search.to_s.red}. All remotes:\n" + remotes.join("\n") pexit errmsg return errmsg else return r end end
remotes()
click to toggle source
# File lib/git-nuke.rb, line 57 def remotes %x{git remote -v}.split("\n").map { |r| r.split[1] }.uniq end
slowp(x)
click to toggle source
# File lib/git-nuke.rb, line 67 def slowp(x) sleep @pdelay printf x end
verify(r)
click to toggle source
show remote to user and confirm location (unless using -f)
# File lib/git-nuke.rb, line 90 def verify(r) nukebanner puts "Remote source:\t".red << r puts "Local target:\t".red << git_root if @verify puts "Warning: this will completely overwrite the local copy.".yellow printf "Continue recloning local repo? [yN] ".yellow unless $stdin.gets.chomp.downcase[0] == "y" puts "Nuke aborted.".green return end end nuke remote, git_root.chomp unless @testing end