Created
December 7, 2016 15:15
-
-
Save royvandam/0a5811b2e8024dd4b6cfafc73350e46b to your computer and use it in GitHub Desktop.
Hackish Git like SVN stash drop in shell function
This file contains 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
svn() { | |
local svn_cmd='/usr/bin/env svn' | |
case $1 in | |
stash) | |
case $2 in | |
"") | |
if ! $svn_cmd status | grep -q '^M'; then | |
echo "No outstanding changes" | |
return | |
fi | |
echo "Stashing changes..." | |
$svn_cmd diff > .svn/.stash_$(date +%s).patch | |
$svn_cmd revert -R . | |
;; | |
list) | |
for entry in .svn/.stash_*.patch; do | |
local entry_ts="$(echo $entry | egrep -o '[0-9]+')" | |
echo $entry_ts | |
done | |
;; | |
pop) | |
shopt -s nullglob | |
stash_ts=0 | |
for entry in .svn/.stash_*.patch; do | |
local entry_ts="$(echo $entry | egrep -o '[0-9]+')" | |
if (( stash_ts < entry_ts )); then | |
stash_file=$entry | |
stash_ts=$entry_ts | |
fi | |
done | |
if (( stash_ts == 0 )); then | |
echo "No stashes available" | |
return | |
fi | |
echo "Popping changes stashed on #${stash_ts}..." | |
if ! patch -p0 < ${stash_file}; then | |
echo "Patch not fully applied, will not remove patch file" | |
return | |
fi | |
rm ${stash_file} | |
;; | |
esac | |
;; | |
*) | |
$svn_cmd $@ | |
;; | |
esac | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment