-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-change-request-DEV-CLOSE
More file actions
executable file
·77 lines (25 loc) · 1.35 KB
/
Copy pathgit-change-request-DEV-CLOSE
File metadata and controls
executable file
·77 lines (25 loc) · 1.35 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/sh
# Bash "strict mode": http://redsymbol.net/articles/unofficial-bash-strict-mode/. But note that /bin/sh is used above,
# as sh have less features, so it is simpler;)
set -eu
#set -euo pipefail
IFS=$(printf '\n\t')
## Environment variables
# export DEBUG=true to echo all commands and add some additional messages
[ "${DEBUG:-false}" = true ] && set -x
## Command line parameters
[ -n "${1:-}" ] || (echo "Please provide merge requests' target branch (typically main) as first parameter" >&2 && exit 1)
TARGET_BRANCH=${1}
# Rest of the parameters are added to git push below via "$@"
shift
## Helper variables
# Some older way: git symbolic-ref --short HEAD, this also probably works: git name-rev --name-only HEAD
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
# Using `|| true` to ignore exit code, because of set -e
#
# TODO: this does not handle for example remote.pushDefault. There must be some other command to figure this out?
TARGET_REMOTE_OR_NULL=$(git config --get branch."$CURRENT_BRANCH".remote || true)
TARGET_REMOTE=${TARGET_REMOTE_OR_NULL:-origin}
# Deleting the branch will close the merge request
git rev-list "$TARGET_REMOTE"/"$TARGET_BRANCH"..HEAD --reverse --no-commit-header --date=format:%FT%H%M%S --pretty=format::refs/heads/cr/"$CURRENT_BRANCH"/%ad |
xargs git push "$@" "$TARGET_REMOTE"