OILS / devtools / git.sh View on Github | oilshell.org

77 lines, 49 significant
1#!/usr/bin/env bash
2#
3# Usage:
4# ./git.sh <function name>
5
6set -o nounset
7set -o pipefail
8set -o errexit
9
10# To run pull requests on my machine.
11#
12# From
13# https://help.github.com/en/articles/checking-out-pull-requests-locally
14
15pull-pr() {
16 local pr_id=$1
17 git fetch origin pull/$pr_id/head:pr/$pr_id
18}
19
20log-staging() {
21 ### log: for working with the merge bot
22 git log soil-staging..
23}
24
25diff-staging() {
26 ### diff: for working with the merge bot
27 git diff soil-staging..
28}
29
30rebase-staging() {
31 git rebase -i soil-staging
32}
33
34merge-to-staging() {
35 local do_push=${1:-T} # pass F to disable
36
37 local branch=$(git rev-parse --abbrev-ref HEAD)
38
39 if test "$do_push" = T; then
40 git checkout soil-staging &&
41 git merge $branch &&
42 git push &&
43 git checkout $branch
44 else
45 git checkout soil-staging &&
46 git merge $branch &&
47 git checkout $branch
48 fi
49}
50
51fetch-staging-and-master() {
52 git fetch origin soil-staging:soil-staging master:master
53}
54
55# https://stackoverflow.com/questions/11021287/git-detect-if-there-are-untracked-files-quickly
56
57untracked() {
58 local count
59 git ls-files --other --directory --exclude-standard
60}
61
62error-if-untracked() {
63 local count
64 count=$(untracked | tee _tmp/untracked | wc -l)
65 if test $count -ne 0; then
66 echo 'Clean up untracked files first:'
67 echo
68
69 cat _tmp/untracked
70 return 1
71 fi
72
73 echo 'OK: no untracked files'
74 return 0
75}
76
77"$@"