-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgit-lazy-merge
executable file
·54 lines (41 loc) · 1.33 KB
/
git-lazy-merge
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
#!/bin/sh
#
# Copyright (c) 2016
# Author: Victor Arribas <[email protected]>
# License: GPLv3 <http://www.gnu.org/licenses/gpl-3.0.html>
#
# Usage: git-lazy-merge <base> <branch-name>
set -e
usage(){
cat<<EOF
git-lazy-merge
Copyright (c) 2016, Victor Arribas <[email protected]>
Provides feature merge workflow when branch creation was forgotten.
It does not require to create temporary branches nor other refs.
Warning: allow merge with untracked files, be careful.
Usage: git lazy-merge <base-id> <branch-name>
base-id - identificator (ref or hash) of where merge must begin.
note: the previous commit to feature begin
branch-name - name of artifical branch when mergin
note: avoid spaces, just use same naming as:
'git branch name' or 'git checkout -b name'
EOF
}
if [ $# -lt 2 ]
then
usage
exit 1
fi
set -u
base_id=$1
base_name=$(git rev-parse --abbrev-ref HEAD)
feature_name=$2
feature_id=$(git rev-parse HEAD)
if test -n "$(git status --short --porcelain --untracked-files=no)"
then
echo "Error: lazy-merge can only be applied over clean workspace. Commit changes first." >&2
exit 1
fi
git reset --hard $base_id \
&& git merge --no-ff --edit --message "Merge branch '$feature_name' into $base_name" $feature_id \
|| git reset --hard $feature_id # rollback on fail