File: git-merge-into

package info (click to toggle)
git-extras 7.4.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 2,120 kB
  • sloc: sh: 4,312; python: 994; makefile: 146
file content (48 lines) | stat: -rwxr-xr-x 944 bytes parent folder | download
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
#!/usr/bin/env bash

current_branch() {
    git rev-parse --abbrev-ref HEAD
}

usage() {
    echo "Usage: git merge-into [src] dest [--ff-only]"
}

cur_branch=$(current_branch)

stashed=0
if [ -n "$(git status --porcelain)" ];
then
    echo "Local modifications detected, stashing"
    stashed=1
    git stash
fi

if [ "${!#}" = '--ff-only' ]; then
    case $# in
        2 ) # dest --ff
            git push "$(git rev-parse --show-toplevel)" "$cur_branch":"$1";;
        3 )
            git push "$(git rev-parse --show-toplevel)" "$1":"$2";;
        * )
            usage
    esac
else
    case $# in
        1 )
            git checkout "$1"
            git merge "$cur_branch" "$1" && git checkout "$cur_branch"
            ;;
        2 )
            git checkout "$2"
            git merge "$1" "$2" && git checkout "$cur_branch"
            ;;
        * )
            usage
    esac
fi

if [ $stashed -eq 1 ];
then
    git stash pop;
fi