-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathquimby.sh
executable file
·130 lines (116 loc) · 3.7 KB
/
quimby.sh
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash
# Author: nasamuffin
#
# Usage:
#
# quimby <base-branch> <topic-branch> [-C <path>] [args-to-format-patch...]
#
# When you invoke 'quimby' against your topic, it does the following things:
#
# 1) Pushes (by force if necessary) <topic-branch> and <base-branch> to your
# fork of Git on Github.
# 2) Calls 'git-format-patch' with the provided flags, plus --cover-letter if
# more than one commit will exist.
#
# quimby must be run from inside a repo, or a repo must be specified with -C.
#
# You must set a Git config "quimby.fork" to contain the name of your fork of
# Git. This can take the form either of a previously configured remote, or a
# URL, as it will be passed directly to 'git push'.
#
#
# Some notes:
#
# - Actions will only be run if <base-branch>..<topic-branch> contains
# dd/ci-swap-azure-pipelines-with-github-actions. That topic was merged to
# 'master' on April 29, 2020 (8cb514d1cb), but an older version of 'master'
# may not run tests. Use an earlier commit of 'quimby' to get the GitGitGadget
# PR workflow instead if your <base-branch> is that old.
# - <topic-branch> will be force-pushed to your own fork. If you're using quimby
# because your usual workflow doesn't use Github at all, that shouldn't bother
# you.
# Positional parameters
PARAMS=()
git_dir=
version=
mail_dir=
# We gather the configs first, so that we can override them from the command
# line if necessary.
# Check if we have a remote set up.
remote="$(git ${git_dir} config quimby.fork)"
while [[ -z "${remote}" ]]; do
git ${git_dir} remote -v
echo "quimby.fork is not configured. Please provide a remote name or URL:"
read remote
git ${git_dir} config quimby.fork "${remote}"
done
# Check if we have a maildir set up.
mail_dir="$(git ${git_dir} config quimby.maildir)"
if [[ "${mail_dir}" ]]; then mail_dir="-o ${mail_dir/#\~/$HOME}"; fi
# Check for args
while (( "$#" )); do
case "$1" in
-C)
git_dir="-C '$2'"
shift 2
;;
-o)
mail_dir="-o $2"
shift 2
;;
-v*)
# take everything but the dash
version="${1#-v}"
shift
;;
*)
PARAMS+=("$1")
shift
;;
esac
done
# Infer the relevant branches if not specified
if [[ "${#PARAMS[@]}" -lt 2 ]];
then
base_branch="$(git ${git_dir} rev-parse --abbrev-ref HEAD@{u})"
topic_branch="$(git ${git_dir} rev-parse --abbrev-ref HEAD)"
exit
else
base_branch="${PARAMS[0]}"
topic_branch="${PARAMS[1]}"
PARAMS=(${PARAMS[@]:2})
fi
# Save a copy.
# Since this isn't ML-visible, explicitly note v1 (this will help our math for
# v2)
save_branch="QUIMBY--${topic_branch}--v${version:-1}"
git branch --force ${save_branch} ${topic_branch}
echo "Saved mailed state into '${save_branch}'"
# Generate an interdiff if we had a copy of n-1
rangediff_flag=
prev_branch="QUIMBY--${topic_branch}--v$((${version}-1))"
if [[ "$(git show-ref "${prev_branch}")" ]];
then
rangediff_flag="--range-diff=${prev_branch}"
echo "including a range-diff from ${prev_branch}"
fi
# Force push to start an Actions run:
git ${git_dir} push "${remote}" "${base_branch}" +"${topic_branch}"
echo "Check the Actions tab on your fork to monitor the CI run."
echo "Maybe at https://github.com/${remote}/git/actions?query=branch%3A${topic_branch}++"
# Determine whether a cover letter is needed
cover_letter_flag=
if [[ "$(git rev-list --count "${base_branch}..${topic_branch}")" -gt 1 ]];
then
cover_letter_flag="--cover-letter"
fi
# Break out version flag; it should be excluded if v1.
version_flag=
if [[ "${version}" ]];
then
version_flag="-v${version}"
fi
git format-patch ${cover_letter_flag} ${rangediff_flag} \
${mail_dir}/${topic_branch}/v${version:-1} \
${version_flag} "${PARAMS[@]}" \
"${base_branch}..${topic_branch}"