Subversion Repositories MK-Marlin

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 ron 1
#!/usr/bin/env bash
2
#
3
# mfup
4
#
5
# - Fetch latest upstream and replace the PR Target branch with
6
# - Rebase the (current or specified) branch on the PR Target
7
# - Force-push the branch to 'origin'
8
#
9
 
10
[[ $# < 3 && $1 != "-h" && $1 != "--help" ]] || { echo "Usage: `basename $0` [1|2] [branch]" 1>&2 ; exit 1; }
11
 
12
MFINFO=$(mfinfo "$@") || exit 1
13
IFS=' ' read -a INFO <<< "$MFINFO"
14
ORG=${INFO[0]}
15
FORK=${INFO[1]}
16
REPO=${INFO[2]}
17
TARG=${INFO[3]}
18
BRANCH=${INFO[4]}
19
CURR=${INFO[5]}
20
 
21
set -e
22
 
23
# Prevent accidental loss of current changes
24
[[ $(git stash) != "No local "* ]] && HAS_STASH=1
25
 
26
echo "Fetching upstream ($ORG/$REPO)..."
27
git fetch upstream
28
 
29
if [[ $BRANCH != $TARG ]]; then
30
  echo ; echo "Rebasing $BRANCH on $TARG..."
31
  if [[ $BRANCH == $CURR ]] || git checkout $BRANCH; then
32
    if git rebase upstream/$TARG; then
33
      git push -f
34
    else
35
      echo "Looks like merge conflicts. Stopping here."
36
      exit
37
    fi
38
  else
39
    echo "No such branch!"
40
  fi
41
else
42
  git reset --hard upstream/$TARG
43
fi
44
 
45
echo
46
[[ $BRANCH != $CURR ]] && git checkout $CURR
47
 
48
[[ $HAS_STASH == 1 ]] && git stash pop