-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatchset-parse
More file actions
executable file
·60 lines (49 loc) · 1.41 KB
/
Copy pathpatchset-parse
File metadata and controls
executable file
·60 lines (49 loc) · 1.41 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
#!/usr/bin/env bash
function fatal() {
echo
echo -e '[ERROR]>>' "$*" >&2
exit 1
}
if [[ "$1" =~ ^(--help|-h)$ ]]; then
# TODO: add help dialog
fatal 'Not implemented'
fi
if ! [[ "$(git branch --show-current)" =~ change-.* ]]; then
fatal 'You need to be checked out on a change branch to use this command'
elif [[ $# -le 1 ]]; then
fatal 'No arguments given, just use the standard git command'
fi
# Parse 'cherry picked from' footer
git show --pretty=%b -s |
sed '/^\s*$/d' |
tac |
grep -P '(?<=\s)[0-9a-f]{40}(?=\)$)' --only-matching |
head -n 1 |
xargs -I{} git rev-parse --verify {}~1 >"$(git rev-parse --git-dir)/BASE"
trap 'rm -rf "$(git rev-parse --git-dir)/BASE"' EXIT
patchset_regex="^(\^)?([1-9][0-9]*)((~|\^)[0-9]*)?(:.*)?$"
declare -i current_patchset
current_patchset=$(git rev-list --count HEAD ^BASE)
if [[ $current_patchset -le 0 ]]; then
fatal 'Current_patchset parsed as non positive\n' \
"Current patchset: $current_patchset"
fi
command="$1"
shift
declare -a args
while [[ $# -gt 0 ]]; do
if grep -Eq "$patchset_regex" <<<"$1"; then
declare -i patchset
patchset="$(sed -E "s/$patchset_regex/\2/" <<<"$1")"
patchset_ref="$(git rev-parse --verify HEAD~$((current_patchset - patchset)))"
rev="$(sed -E "s/$patchset_regex/\1$patchset_ref\3\5/" <<<"$1")"
args+=("$rev")
elif [[ "$1" == "-n" ]]; then
args+=("$1" "$2")
shift
else
args+=("$1")
fi
shift
done
git "$command" "${args[@]}"