Skip to content

Instantly share code, notes, and snippets.

@ddbeck
Created April 22, 2013 19:42
Show Gist options
  • Save ddbeck/5437873 to your computer and use it in GitHub Desktop.
Save ddbeck/5437873 to your computer and use it in GitHub Desktop.
A shell script and alias to avoid making dumb mistakes with git-svn.
[alias]
ci = commit
co = checkout
st = status
wdiff = diff --color-words
svnci = !$HOME/src/dotfiles/git-svn-safe.sh dcommit
svnre = !$HOME/src/dotfiles/git-svn-safe.sh rebase
#!/usr/bin/env bash
branch=$(git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3)
if [[ $branch = "master" ]]; then
output=$(git svn "$@" 2>&1 | tee /dev/tty)
count=$(echo -e "$output" | grep -c "^Committed")
if [[ $count > 0 ]]; then
echo -e "\nLog of $count commits:"
git svn log --reverse --oneline -n"$count" | \
sed -E 's/^(r[0-9]+) [|]/\1:/'
fi
else
echo Avoid runing git svn "$@" on a branch other than master.
fi
@ddbeck
Copy link
Author

ddbeck commented Apr 22, 2013

Consider this untested for platforms other than Mac OS 10.6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment