aboutsummaryrefslogtreecommitdiff
path: root/helpers/git-svn-commit
blob: 49cb0d3bdd7c73be01cb25cd839fe5d3b17af4d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/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 trying again."
    exit 1
  fi
fi

# Refresh / rebase to avoid future conflicts
safe_run git-refresh
safe_run git-rebase-all