File: git-merge-into

package info (click to toggle)
git-extras 6.1.0-1
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 1,720 kB
  • sloc: sh: 3,480; makefile: 126
file content (34 lines) | stat: -rwxr-xr-x 757 bytes parent folder | download | duplicates (3)
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
#!/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)
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