File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # A wrapper for colmena that prevents accidentally deploying changes without
2+ # having pulled.
3+ { colmena , runCommandNoCC } :
4+ runCommandNoCC "colmena-wrapper"
5+ {
6+ env = {
7+ colmena = "${ colmena } /bin/colmena" ;
8+ remote_name = "origin" ;
9+ upstream_branch = "main" ;
10+ } ;
11+ } ''
12+ mkdir -p $out
13+ ln -s ${ colmena } /share $out/share
14+ mkdir $out/bin
15+
16+ substituteAll ${ ./colmena-wrapper.sh.in } $out/bin/colmena
17+ chmod +x $out/bin/colmena
18+ ''
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ doChecks () {
4+ # creates refs in the refs/prefetch/remotes/origin namespace
5+ echo " Prefetching repo changes..." >&2
6+ git fetch --quiet --prefetch --no-write-fetch-head @remote_name@
7+
8+ diffs=$( git rev-list --left-right --count HEAD...refs/prefetch/remotes/@remote_name@/@upstream_branch@)
9+ only_in_local=$( echo " $diffs " | cut -f1)
10+ only_in_main=$( echo " $diffs " | cut -f2)
11+
12+ if [[ $only_in_main -gt 0 && ! -v $FOOTGUN_ME_UWU ]]; then
13+ echo >&2
14+ echo " Attempting to deploy when @upstream_branch@ has $only_in_main commits not in your branch!" >&2
15+ echo " This will probably revert someone's changes. Consider merging them." >&2
16+ echo " If you really mean it, set the environment variable FOOTGUN_ME_UWU" >&2
17+ exit 1
18+ fi
19+
20+ if [[ $only_in_local -gt 0 ]]; then
21+ echo " You have $only_in_local commits not yet pushed to @upstream_branch@. Reminder to push them after :)" >&2
22+ fi
23+ }
24+
25+ if [[ $1 == ' apply' ]]; then
26+ doChecks
27+ fi
28+
29+ exec @colmena@ " $@ "
You can’t perform that action at this time.
0 commit comments