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"
4 changes: 0 additions & 4 deletions Utilities/GitSetup/SetupGitAliases.sh

This file was deleted.

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

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

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


if [[ $# -lt 1 ]]; then
if type python3 >/dev/null 2>&1 && 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" \
| python3 -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; then
topic="$(git symbolic-ref HEAD | sed -e 's|^refs/heads/||')"
pushurl="$(git config --get remote."$remote".pushurl)"
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
147 changes: 0 additions & 147 deletions Utilities/GitSetup/setup-gerrit

This file was deleted.

16 changes: 16 additions & 0 deletions Utilities/GitSetup/setup-git-aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

# Alias to checkout a pull request by its numerical id
git config alias.pr "!bash Utilities/GitSetup/git-pr"
# Remove previously checked out pull request
git config alias.pr-clean '!git checkout master ; git for-each-ref refs/heads/pr/* --format="%(refname)" | while read ref ; do branch=${ref#refs/heads/} ; git branch -D $branch ; done'

# Alias to push the current topic branch to GitHub
git config alias.review-push "!bash Utilities/GitSetup/git-review-push"

git config alias.gerrit-push \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this gerrit alias still necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to help transition for folks with old documentation or habits.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.

"!bash -c 'echo \\\"git gerrit-push\\\" is deprecated. Please use \\\"git review-push\\\" instead.'"

# Useful alias to see what commits are on the current branch with respect to
# upstream/master
git config alias.prepush 'log --graph --stat upstream/master..'
Loading