Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .hooks-config.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#==========================================================================
#
# Copyright Insight Software Consortium
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#==========================================================================*/

# Loaded by .git/hooks/(pre-commit|commit-msg|prepare-commit-msg)
# during git commit after local hooks have been installed.

hooks_chain_pre_commit="Utilities/Hooks/pre-commit"
hooks_chain_commit_msg="Utilities/Hooks/commit-msg"
hooks_chain_prepare_commit_msg="Utilities/Hooks/prepare-commit-msg"
#hooks_chain_post_commit="Utilities/Hooks/post-commit"
10 changes: 0 additions & 10 deletions Utilities/GitSetup/SetupGitAliases.sh

This file was deleted.

12 changes: 7 additions & 5 deletions Utilities/GitSetup/config
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[hooks]
url = https://itk.org/ITK.git
[gerrit]
project = ITKExamples
site = http://review.source.kitware.com
pushurl = $username@review.source.kitware.com:ITKExamples
url = http://public.kitware.com/GitSetup.git
[upstream]
url = https://github.com/InsightSoftwareConsortium/ITKExamples.git
remote = upstream
[github]
organization-name = InsightSoftwareConsortium
repo-name = ITKExamples
52 changes: 52 additions & 0 deletions Utilities/GitSetup/git-pr
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash

usage() {
echo "git pr <pull-request-number>"
}

egrep-q() {
egrep "$@" >/dev/null 2>/dev/null
}

if [[ "$1" = "-h" || "$1" = "--help" ]] ; then
usage
exit 0
fi

have_python3=false
python_exe=python
if type python3 >/dev/null 2>&1; then
have_python3=true
python_exe=python3
elif type python >/dev/null 2>&1; then
if echo $(python --version 2>&1) | egrep-q 'Python 3'; then
have_python3=true
python_exe=python
fi
fi
if [[ $# -lt 1 ]]; then
if $have_python3 && type curl >/dev/null 2>&1; then
config="${BASH_SOURCE%/*}/config" &&
host=$(git config -f "$config" --get github.host || echo "github.com")
organization_name=$(git config -f "$config" --get github.organization-name)
repo_name=$(git config -f "$config" --get github.repo-name)
url="https://api.$host/repos/$organization_name/$repo_name/pulls?sort=updated;direction=desc"
pr_prompt=$(curl -s "https://api.$host/repos/$organization_name/$repo_name/pulls?sort=updated;direction=desc" \
| $python_exe -c "import sys, json; res = json.load(sys.stdin); [print(str(pr['number']) + ': ' + pr['title']) for pr in res];")
echo "$pr_prompt"
echo ""
pr_number=$(echo "$pr_prompt" | sed -n -e "s/\([[:alnum:]]\+\).*/\1/p" | tail -n1)
read -ep "Pull request number? [$pr_number]: " ans &&
if [ -n "$ans" ]; then
pr_number="$ans"
fi
else
usage
exit 1
fi
else
pr_number=$1
fi

git fetch -fu ${2:-upstream} refs/pull/$pr_number/head:pr/$pr_number && \
git checkout pr/$pr_number;
97 changes: 97 additions & 0 deletions Utilities/GitSetup/git-review-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/usr/bin/env bash
#=============================================================================
# Copyright 2010-2012 Kitware, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================

USAGE="[<remote>] [--no-topic] [--dry-run] [--]"
OPTIONS_SPEC=
SUBDIRECTORY_OK=Yes
. "$(git --exec-path)/git-sh-setup"

# Load the project configuration.
config="${BASH_SOURCE%/*}/config" &&
upstream_remote=$(git config -f "$config" --get upstream.remote) &&
host=$(git config -f "$config" --get github.host || echo "github.com") &&
organization_name=$(git config -f "$config" --get github.organization-name) &&
repo_name=$(git config -f "$config" --get github.repo-name)
github_remote=$(git config --get github.fork.remote)
#-----------------------------------------------------------------------------

remote="$github_remote"
refspecs=''
no_topic=''
dry_run=''
force=''

# Parse the command line options.
while test $# != 0; do
case "$1" in
--no-topic) no_topic=1 ;;
--force) force=--force ;;
--dry-run) dry_run=--dry-run ;;
--) shift; break ;;
-*) usage ;;
*) test -z "$remote" || usage ; remote="$1" ;;
esac
shift
done
test $# = 0 || usage

# Default remote.
test -n "$remote" || remote="origin"

if test -z "$no_topic"; then
# Identify and validate the topic branch name.
topic="$(git symbolic-ref HEAD | sed -e 's|^refs/heads/||')"
if test "$topic" = "master"; then
die 'Please name your topic:
git checkout -b descriptive-name'
fi
refspecs="HEAD:$topic"
fi

# Exit early if we have nothing to push.
if test -z "$refspecs"; then
echo "Nothing to push!"
exit 0
fi

# Fetch the current upstream master branch head.
# This helps the computation of a minimal pack to push.
if test -z "$upstream_remote"; then
echo "Fetching $upstream_remote master"
fetch_out=$(git fetch "$upstream_remote" master 2>&1) || die "$fetch_out"
fi

# Push. Save output and exit code.
echo "Pushing to $remote"
push_stdout=$(git push --porcelain $force $dry_run "$remote" $refspecs); push_exit=$?
echo "$push_stdout"

if test $push_exit -eq 0; then
topic="$(git symbolic-ref HEAD | sed -e 's|^refs/heads/||')"
pushurl="$(git config --get remote."$remote".pushurl || git config --get remote."$remote".url)"
username=$(echo $pushurl | sed -n -e "s/git@$host:\([[:alnum:]]\+\).*/\1/p")
if test -n "$username"; then
echo '
Preview the pull request by visiting:

https://'"$host"'/'"$organization_name"'/'"$repo_name"'/compare/master...'"$username"':'"$topic"'
'
fi
fi

# Reproduce the push exit code.
exit $push_exit
51 changes: 51 additions & 0 deletions Utilities/GitSetup/github-tips
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bash
#=============================================================================
# Copyright 2017-2018 Kitware, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================

# This script makes optional suggestions for working with GitHub.

# Suggest pr alias
echo '
This repository was configured with a `git pr` alias. The alias is useful when
checking out pull requests locally for review. Fetch and check out a pull
request by number with:

git pr <pull-request-number>

If curl and python3 are available, the pull request number can be omitted, and
a list of open pull requests will be presented.
'

# Suggest hub
if ! type hub >/dev/null 2>&1; then
echo '
`hub` is a useful command line tool for working with GitHub. For installation
and usage instructions, see:

https://hub.github.com/
'
fi

# Suggest git series
if ! git series -h >/dev/null 2>&1; then
echo '
When working on an open source project, multiple revisions of a change are
common and the change evolves through the code review process. For `git series`
and usage instructions, see:

https://github.com/git-series/git-series
'
fi
Loading