Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # This script commits to SVN via Git-Svn dcommit. It also adds some checks to |
| 4 | # make sure you're not trying to commit from master, and warns about multiple |
| 5 | # commits, as they're not always intentional and could mean you're trying to |
| 6 | # commit from the wrong branch. |
| 7 | # |
| 8 | # The script will refresh your master and branches to make sure you have an |
| 9 | # up-to-date branch before committing, as that would mess up your local svn |
| 10 | # setup or would at least block your commit from going through. |
| 11 | |
| 12 | . llvm-common |
| 13 | |
| 14 | force=no |
| 15 | if [[ $1 = '-f' ]]; then |
| 16 | force=yes |
| 17 | fi |
| 18 | |
| 19 | branch=`get_branch` |
| 20 | if [[ $branch = 'master' ]]; then |
| 21 | echo " --- Can't commit master branch" |
| 22 | exit 1 |
| 23 | fi |
| 24 | revs=`git log --pretty=oneline --abbrev-commit --graph --decorate | grep -n master | head -1 | cut -d ":" -f 1` |
| 25 | revs=$((revs-1)) |
| 26 | if [[ $revs = 0 ]]; then |
| 27 | echo " --- No patches in current branch" |
| 28 | exit 1 |
| 29 | fi |
| 30 | if [[ $revs != 1 && $force != 'yes' ]]; then |
| 31 | echo " --- Too many patches in current branch, use -f to force commit" |
| 32 | exit 1 |
| 33 | fi |
| 34 | |
| 35 | # Prepare |
| 36 | safe_run git-refresh |
| 37 | safe_run git checkout $branch |
| 38 | safe_run git rebase master |
| 39 | |
| 40 | # Actuall SVN commit. Try to recover once. |
| 41 | git svn dcommit |
| 42 | if [[ $? != 0 ]]; then |
| 43 | echo " == SVN COMMIT ERROR ==" |
| 44 | # If we're in the base dir, try it again. |
| 45 | if [ -d .git/svn ]; then |
| 46 | echo "We're in base dir, cleaning SVN info and trying again" |
| 47 | rm -rf .git/svn |
| 48 | safe_run git svn rebase |
| 49 | safe_run git svn dcommit |
| 50 | else |
| 51 | echo "Not in base dir, won't try anything. But if you" |
| 52 | echo "saw the message 'resource out of date', remove" |
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame] | 53 | echo "the .git/svn directory and try again." |
Renato Golin | 94cc104 | 2016-04-26 11:02:23 +0100 | [diff] [blame] | 54 | exit 1 |
| 55 | fi |
| 56 | fi |
| 57 | |
| 58 | # Refresh / rebase to avoid future conflicts |
| 59 | safe_run git-refresh |
Diana Picus | 72189fd | 2016-05-23 19:32:46 +0300 | [diff] [blame] | 60 | safe_run git-rebase |