blob: f27bb7781d559897fc7ac8155ff57a880e0cc451 [file] [log] [blame]
Renato Golin94cc1042016-04-26 11:02:23 +01001#!/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
14force=no
15if [[ $1 = '-f' ]]; then
16 force=yes
17fi
18
19branch=`get_branch`
20if [[ $branch = 'master' ]]; then
21 echo " --- Can't commit master branch"
22 exit 1
23fi
24revs=`git log --pretty=oneline --abbrev-commit --graph --decorate | grep -n master | head -1 | cut -d ":" -f 1`
25revs=$((revs-1))
26if [[ $revs = 0 ]]; then
27 echo " --- No patches in current branch"
28 exit 1
29fi
30if [[ $revs != 1 && $force != 'yes' ]]; then
31 echo " --- Too many patches in current branch, use -f to force commit"
32 exit 1
33fi
34
35# Prepare
36safe_run git-refresh
37safe_run git checkout $branch
38safe_run git rebase master
39
40# Actuall SVN commit. Try to recover once.
41git svn dcommit
42if [[ $? != 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 Picus72189fd2016-05-23 19:32:46 +030053 echo "the .git/svn directory and try again."
Renato Golin94cc1042016-04-26 11:02:23 +010054 exit 1
55 fi
56fi
57
58# Refresh / rebase to avoid future conflicts
59safe_run git-refresh
Diana Picus72189fd2016-05-23 19:32:46 +030060safe_run git-rebase