Created
March 17, 2024 23:34
-
-
Save chicken-suop/f05699504e533273a4d33f88fea2b4ab to your computer and use it in GitHub Desktop.
# Stashes svn files (tracked & untracked)
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
#!/bin/bash | |
rootDir=~/code/svn-stash | |
function stash { | |
today=$(date +"%Y-%m-%d-%H-%M-%S") | |
patchName=$rootDir/$today.patch | |
newFiles=$(svn status --no-ignore | grep -E '(^\?)|(^\I)' | sed -e 's/^. *//') | |
echo 'Include unversioned files?' | |
select yn in "Yes" "No"; do | |
case $yn in | |
Yes ) includeUnversioned=1; break;; | |
No ) includeUnversioned=0; break;; | |
esac | |
done | |
if [ $includeUnversioned -eq 1 ]; then | |
xargs -r -d '\n' svn add <<< $newFiles | |
fi | |
svn diff > $patchName | |
svn revert -R . | |
if [ $includeUnversioned -eq 1 ]; then | |
xargs -r -d '\n' svn rm --force <<< $newFiles | |
fi | |
echo "Patch saved as $patchName" | |
} | |
function apply { | |
echo 'Select patch to apply:' | |
select patch in $(list); do | |
patch -p0 < $rootDir/$patch | |
break | |
done | |
echo 'Remove patch?' | |
select yn in "Yes" "No"; do | |
case $yn in | |
Yes ) rm $rootDir/$patch; break;; | |
No ) break;; | |
esac | |
done | |
} | |
function list { | |
find $rootDir -type f -name "*.patch" -exec basename {} \; | |
} | |
function help { | |
echo "svn_stash stash" | |
echo "svn_stash apply" | |
echo "svn_stash list" | |
} | |
case $1 in | |
"stash") | |
stash | |
;; | |
"apply") | |
apply | |
;; | |
"list") | |
list | |
;; | |
"help") | |
help | |
;; | |
*) | |
help | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment