Created
August 28, 2020 13:40
-
-
Save klausmeyer/bc1eb2da6acc530e76136dd94216931b to your computer and use it in GitHub Desktop.
My small helper to update / cleanup local git working copies.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'yaml' | |
require 'open3' | |
# require 'byebug' | |
COLOUR_RED = 31 | |
COLOUR_GREEN = 32 | |
COLOUR_YELLOW = 33 | |
projects = YAML.load_file(File.join(File.dirname(File.expand_path(__FILE__)), "gc.yaml")) | |
def colour(string, code) | |
puts "\e[#{code}m#{string}\e[0m" | |
end | |
projects.each do |key, config| | |
colour "Project: #{key}", COLOUR_YELLOW | |
path = config['path'] | |
remote = config['remote'] | |
branch = config['branch'] | |
shell = -> (cmd) do | |
puts "[+] #{cmd}" | |
output, status = Open3.capture2e(cmd, chdir: File.expand_path(path)) | |
puts output if output.length > 0 | |
if status.success? | |
status_colour = COLOUR_GREEN | |
else | |
status_colour = COLOUR_YELLOW | |
end | |
colour "[i] Status: #{status}", status_colour | |
output | |
end | |
shell.call "git fetch --all --prune" | |
shell.call "git checkout -B #{branch}" | |
shell.call "git reset --hard #{remote}/#{branch}" | |
shell.call "git branch" | |
shell.call "git branch | grep --invert-match #{branch} | xargs git branch --delete --force" | |
puts '-' * 80 | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
bar: | |
branch: develop | |
path: ~/Code/github.com/foo/bar | |
remote: origin | |
baz: | |
branch: develop | |
path: ~/Code/github.com/foo/baz | |
remote: origin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment