From 3de109db9f3821120f7be7a91ae1a74a403ba7ea Mon Sep 17 00:00:00 2001 From: Matthew Rothenberg Date: Tue, 26 May 2015 12:42:42 -0400 Subject: [PATCH] initial port from khan-dotfiles essentially a straight copy, with repository metadata added. the goal here is just to have these live somewhere that makes sense conceptually and is easy to maintain, rather than being bundled as part of our dotfiles setup. --- .arclint | 9 +++++++++ .editorconfig | 15 +++++++++++++++ LICENSE | 21 +++++++++++++++++++++ README.md | 24 +++++++++++++++++++++++ bin/git-deploy-branch | 32 +++++++++++++++++++++++++++++++ bin/git-recursive-grep | 19 +++++++++++++++++++ bin/git-review-branch | 43 ++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 163 insertions(+) create mode 100644 .arclint create mode 100644 .editorconfig create mode 100644 LICENSE create mode 100644 README.md create mode 100755 bin/git-deploy-branch create mode 100755 bin/git-recursive-grep create mode 100755 bin/git-review-branch diff --git a/.arclint b/.arclint new file mode 100644 index 0000000..44015ab --- /dev/null +++ b/.arclint @@ -0,0 +1,9 @@ +{ + "linters": { + "khan-linter": { + "type": "script-and-regex", + "script-and-regex.script": "ka-lint --always-exit-0 --blacklist=yes --propose-arc-fixes", + "script-and-regex.regex": "\/^((?P[^:]*):(?P\\d+):((?P\\d+):)? (?P((?PE)|(?PW))\\S+) (?P[^\\x00]*)(\\x00(?P[^\\x00]*)\\x00(?P[^\\x00]*)\\x00)?)|(?PSKIPPING.*)$\/m" + } + } +} diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..2239cf4 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +# http://editorconfig.org + +# All rules in this file are based on our style guides: +# https://github.com/Khan/style-guides + +# This is the top-most EditorConfig file. +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +max_line_length = 79 +insert_final_newline = true diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..50842bb --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2015 Khan Academy + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..0ea4fdf --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# khan academy git-workflow + +Collection of scripts in order to enable the [git workflow][git-at-ka] +at Khan Academy. (see also: [arcanist]) + +[git-at-ka]: https://khanacademy.org/r/git-at-ka +[arcanist]: https://github.com/khan/arcanist + +## Tools + +#### git deploy-branch +Creates a remote deploy branch for use with GitHub-style deploys. + +For GitHub-style deploys, all work must branch off a deploy branch. + +#### git review-branch +Creates a new local branch ensuring that it's not based off master. +Such a branch is called a 'review branch'. + +All review branches should be based off a deploy branch. + +#### git recursive-grep +Runs git grep recursively through submodules, showing file paths +relative to cwd. diff --git a/bin/git-deploy-branch b/bin/git-deploy-branch new file mode 100755 index 0000000..d0719ea --- /dev/null +++ b/bin/git-deploy-branch @@ -0,0 +1,32 @@ +#!/bin/sh -e + +USAGE=`cat< [parent -- defaults to origin/master] + + Creates a remote deploy branch for use with GitHub-style deploys. + + For GitHub-style deploys, all work must branch off a deploy branch. + See git review-branch. + + See also Git workflow at KA: + https://khanacademy.org/r/git-at-ka +EOF` + +[ -n "$1" ] || { + echo "$USAGE" + exit 1 +} + + +git fetch origin +if git show-ref --quiet --verify refs/remotes/origin/$1; then + # The branch already exists. + # Switch to it and make sure it's tracking the remote + git co --track origin/$1 + echo "WARNING: using already existing branch origin/$1" +else + # Create a new branch tracking the remote one + git branch --no-track $1 ${2-origin/master} + git co $1 + git push --set-upstream origin $1 +fi diff --git a/bin/git-recursive-grep b/bin/git-recursive-grep new file mode 100755 index 0000000..7ea4004 --- /dev/null +++ b/bin/git-recursive-grep @@ -0,0 +1,19 @@ +#!/bin/bash + +USAGE=`cat< + + Runs git grep recursively through submodules, showing full file paths. +EOF` + +[ -n "$1" ] || { + echo "$USAGE" + exit 1 +} + +{ + git rev-parse --show-toplevel + git submodule -q foreach --recursive "pwd" +} | while read p; do + cd "$p" && git grep --full-name "$@" | sed "s,^,$p/," +done diff --git a/bin/git-review-branch b/bin/git-review-branch new file mode 100755 index 0000000..c5fb288 --- /dev/null +++ b/bin/git-review-branch @@ -0,0 +1,43 @@ +#!/bin/sh -e + +USAGE=`cat< [parent -- defaults to branch.review-parent-default] + + Creates a new local branch ensuring that it's not based off master. + This is useful as part of GitHub-style deploys. Such a branch is called + a 'review branch'. + + All review branches should be based off a deploy branch. + See git deploy-branch. + + If you've run 'git config --add branch.review-parent-default XXX', + then when you run 'git review-branch foo' it will base foo off of + the XXX branch. You can override this behavior via + git review-branch foo other-deploy-branch + + See also Git workflow at KA: + https://khanacademy.org/r/git-at-ka +EOF` + +[ -n "$1" ] || { + echo "$USAGE" + exit 1 +} + + +# If the second argument is provided, switch to it +if [ -n "$2" ]; then + git co $2 +elif [ -n "`git config --get branch.review-parent-default`" ]; then + # If they have a default parent branch, switch to *that* + git co "`git config --get branch.review-parent-default`" +fi + +# Stop people from landing directly to master +if [ "`git rev-parse --abbrev-ref HEAD`" = "master" ]; then + echo "Review branches must not be based off master"; + exit 1 +fi + +# Apart from that check, this command just creates a local branch +git co --track -b $1