summaryrefslogtreecommitdiff
path: root/.local
diff options
context:
space:
mode:
Diffstat (limited to '.local')
-rwxr-xr-x.local/bin/git-fetch-pr42
-rwxr-xr-x.local/bin/git-prune-merged-branches6
-rwxr-xr-x.local/bin/git-prune-pushed-branches6
-rw-r--r--.local/bin/unzlib.go34
4 files changed, 88 insertions, 0 deletions
diff --git a/.local/bin/git-fetch-pr b/.local/bin/git-fetch-pr
new file mode 100755
index 0000000..ba9fa2d
--- /dev/null
+++ b/.local/bin/git-fetch-pr
@@ -0,0 +1,42 @@
+#!/bin/bash
+set -euE
+
+is_int() {
+ local re='^[0-9]+$'
+ [[ $1 =~ $re ]]
+}
+
+errusage() {
+ if [[ $# != 0 ]]; then
+ echo >&2 "${0##*/}: error: $*"
+ fi
+ echo >&2 "Usage: ${0##*/} [REMOTE] PR_NUMS..."
+ return 2
+}
+
+main() {
+ if [[ $# == 0 ]]; then
+ errusage 'require 1 or more PR numbers'
+ fi
+ local remote=origin
+ if ! is_int "$1"; then
+ remote=$1
+ shift
+ if [[ $# == 0 ]]; then
+ errusage 'require 1 or more PR numbers'
+ fi
+ fi
+ local refspecs=()
+ for pr in "$@"; do
+ if ! is_int "$pr"; then
+ errusage "not a number: ${pr@Q}"
+ fi
+ refspecs+=(
+ "refs/pull/${pr}/head:refs/pull/${pr}/head"
+ #"refs/pull/${pr}/merge:refs/pull/${pr}/merge"
+ )
+ done
+ git fetch --force "$remote" "${refspecs[@]}"
+}
+
+main "$@"
diff --git a/.local/bin/git-prune-merged-branches b/.local/bin/git-prune-merged-branches
new file mode 100755
index 0000000..772b4ad
--- /dev/null
+++ b/.local/bin/git-prune-merged-branches
@@ -0,0 +1,6 @@
+#!/bin/bash
+git for-each-ref --format='%(refname)' refs/heads/ |while read -r ref; do
+ if git merge-base --is-ancestor "$ref" HEAD; then
+ echo "${ref#refs/heads/}"
+ fi
+done | xargs -r git branch -d
diff --git a/.local/bin/git-prune-pushed-branches b/.local/bin/git-prune-pushed-branches
new file mode 100755
index 0000000..e711560
--- /dev/null
+++ b/.local/bin/git-prune-pushed-branches
@@ -0,0 +1,6 @@
+#!/bin/bash
+git for-each-ref --format='%(refname)' refs/heads/ |while read -r ref; do
+ if git merge-base --is-ancestor "$ref" "refs/remotes/origin/${ref#refs/heads/}"; then
+ echo "${ref#refs/heads/}"
+ fi
+done | xargs -r git branch -D
diff --git a/.local/bin/unzlib.go b/.local/bin/unzlib.go
new file mode 100644
index 0000000..764449d
--- /dev/null
+++ b/.local/bin/unzlib.go
@@ -0,0 +1,34 @@
+package main
+
+import (
+ "compress/zlib"
+ "fmt"
+ "io"
+ "os"
+)
+
+func main() {
+ if err := Main(os.Stdin, os.Stdout); err != nil {
+ fmt.Fprintf(os.Stderr, "%s: error: %v\n", os.Args[0], err)
+ os.Exit(1)
+ }
+}
+
+func Main(zin io.Reader, out io.Writer) (err error) {
+ maybeSetErr := func(_err error) {
+ if err == nil && _err != nil {
+ err = _err
+ }
+ }
+ in, err := zlib.NewReader(zin)
+ if err != nil {
+ return err
+ }
+ defer func() {
+ maybeSetErr(in.Close())
+ }()
+ if _, err := io.Copy(out, in); err != nil {
+ return err
+ }
+ return nil
+}