| #!/usr/bin/env bash |
| |
| # This script commits to SVN via Git-Svn dcommit. It also adds some checks to |
| # make sure you're not trying to commit from master, and warns about multiple |
| # commits, as they're not always intentional and could mean you're trying to |
| # commit from the wrong branch. |
| # |
| # The script will refresh your master and branches to make sure you have an |
| # up-to-date branch before committing, as that would mess up your local svn |
| # setup or would at least block your commit from going through. |
| |
| . llvm-common |
| |
| force=no |
| if [[ $1 = '-f' ]]; then |
| force=yes |
| fi |
| |
| branch=`get_branch` |
| if [[ $branch = 'master' ]]; then |
| echo " --- Can't commit master branch" |
| exit 1 |
| fi |
| revs=`git log --pretty=oneline --abbrev-commit --graph --decorate | grep -n master | head -1 | cut -d ":" -f 1` |
| revs=$((revs-1)) |
| if [[ $revs = 0 ]]; then |
| echo " --- No patches in current branch" |
| exit 1 |
| fi |
| if [[ $revs != 1 && $force != 'yes' ]]; then |
| echo " --- Too many patches in current branch, use -f to force commit" |
| exit 1 |
| fi |
| |
| # Prepare |
| safe_run git-refresh |
| safe_run git checkout $branch |
| safe_run git rebase master |
| |
| # Actuall SVN commit. Try to recover once. |
| git svn dcommit |
| if [[ $? != 0 ]]; then |
| echo " == SVN COMMIT ERROR ==" |
| # If we're in the base dir, try it again. |
| if [ -d .git/svn ]; then |
| echo "We're in base dir, cleaning SVN info and trying again" |
| rm -rf .git/svn |
| safe_run git svn rebase |
| safe_run git svn dcommit |
| else |
| echo "Not in base dir, won't try anything. But if you" |
| echo "saw the message 'resource out of date', remove" |
| echo "the .git/svn directory and try again." |
| exit 1 |
| fi |
| fi |
| |
| # Refresh / rebase to avoid future conflicts |
| safe_run git-refresh |
| safe_run git-rebase |