Skip to content

Instantly share code, notes, and snippets.

@viktor-evdokimov
Forked from righi/git-reup
Created May 24, 2017 01:08
Show Gist options
  • Save viktor-evdokimov/d3b225c6bd91c57bc3b60565ffe1d4d0 to your computer and use it in GitHub Desktop.
Save viktor-evdokimov/d3b225c6bd91c57bc3b60565ffe1d4d0 to your computer and use it in GitHub Desktop.
git-reup
#!/usr/bin/env ruby
#
# Usage: git-up
# git-reup
#
# Like git-pull but show a short and sexy log of changes
# immediately after merging (git-up) or rebasing (git-reup).
#
# Inspired by Kyle Neath's `git up' alias:
# http://gist.github.com/249223
#
# Stolen from Ryan Tomayko
# http://github.com/rtomayko/dotfiles/blob/rtomayko/bin/git-up
# and then Zach Holman
# https://github.com/holman/dotfiles/blob/master/bin/git-up
# and then Barijaona Ramaholimihaso
# https://gist.github.com/barijaona/3194807
require 'shellwords'
pull_args = ARGV.to_a
rebase = File.basename($0) == 'git-reup'
stashed = false
old_head = `git rev-parse HEAD`.chomp
exit($?.to_i) unless $? == 0
if rebase
pull_args.push '--rebase'
msg = `git stash save "Auto-stash by #{File.basename($0)} script"`
stashed = msg !~ /^No local changes to save$/
end
system "git pull #{pull_args.shelljoin}"
updated = (old_head != `git rev-parse HEAD`.chomp)
system "git stash pop --quiet" if stashed && rebase
if updated
if rebase
puts "Diffstat:"
system "git --no-pager diff --color --stat #{old_head}.. | sed 's/^/ /'"
end
puts "Log:"
system "git log --color --pretty=oneline --abbrev-commit #{old_head}.. | sed 's/^/ /'"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment