Debian Codegraph @

contrib/phab-refresh-stack.sh

raw
1 #!/bin/bash
2 set -eu
3
4 if [[ "$PHABRICATOR_TOKEN" == "NO-PHAB" ]]; then
5 echo 'Skipping Phabricator Step' >&2
6 exit 0
7 fi
8
9 revision_in_stack=`hg log \
10 --rev '.#stack and ::. and topic()' \
11 -T '\nONE-REV\n' \
12 | grep 'ONE-REV' | wc -l`
13 revision_on_phab=`hg log \
14 --rev '.#stack and ::. and topic() and desc("re:\nDifferential Revision: [^\n]+D\d+$")'\
15 -T '\nONE-REV\n' \
16 | grep 'ONE-REV' | wc -l`
17
18 if [[ $revision_in_stack -eq 0 ]]; then
19 echo "stack is empty" >&2
20 exit 0
21 fi
22
23 if [[ $revision_on_phab -eq 0 ]]; then
24 echo "no tracked diff in this stack" >&2
25 exit 0
26 fi
27
28 if [[ $revision_on_phab -lt $revision_in_stack ]]; then
29 echo "not all stack changesets (${revision_in_stack}) have matching Phabricator Diff (${revision_on_phab})" >&2
30 exit 2
31 fi
32
33 if [[ "$PHABRICATOR_TOKEN" == "" ]]; then
34 echo 'missing $PHABRICATOR_TOKEN variable' >&2
35 echo '(use PHABRICATOR_TOKEN="NO-PHAB" to disable this step)' >&2
36 exit 2
37 fi
38
39 hg \
40 --config extensions.phabricator= \
41 --config phabricator.url=https://phab.mercurial-scm.org/ \
42 --config phabricator.callsign=HG \
43 --config auth.phabricator.schemes=https \
44 --config auth.phabricator.prefix=phab.mercurial-scm.org \
45 --config auth.phabricator.phabtoken=$PHABRICATOR_TOKEN \
46 phabsend --rev '.#stack and ::. and topic()' \
47 "$@"