Skip to content

Commit

Permalink
ENH: Update ApplyScriptToRemotes.sh for Github auth token protocol
Browse files Browse the repository at this point in the history
Fixes:
- Fetch repo with https instead of git protocol
- Push repo with git username and auth token instead of
  username/password combination

Quality updates:
- Allow switch into already-existing branch to mitigate rerun effort
- Confirm remote path before each push to minimize accidental push
  to wrong remote
  • Loading branch information
tbirdso authored and dzenanz committed Jun 7, 2022
1 parent a2e5248 commit 9e9ee8a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions Utilities/Maintenance/ApplyScriptToRemotes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ remote_modules_path='../../Modules/Remote'
# Ask for GitHub username and password once
echo "Please provide your GitHub (https://github.com)"
read -p "username: " username
read -p "password: " -s password

remotes=()

Expand Down Expand Up @@ -122,7 +121,7 @@ function list_candidate_remotes() {

# Get the latest git commit hash of the remote module.
# Remotes will usually not be tagged.
latest_commit=$(git ls-remote git://github.com/$repository refs/heads/master)
latest_commit=$(git ls-remote https://github.com/$repository refs/heads/master)
latest_commit=${latest_commit/[[:space:]]refs\/heads\/master/}

# Skip remotes whose current commit in ITK differs from the latest
Expand Down Expand Up @@ -171,8 +170,8 @@ function apply_script_and_push_remotes() {

repository_basename=$(basename -s .git `git config --get remote.origin.url`)

git checkout master
git checkout -b $feature_branch origin/master
git checkout main || git checkout master
git checkout -b $feature_branch origin/main || git checkout -b $feature_branch origin/master || git checkout $feature_branch
$script

# Add the files, adding filters if necessary, and redirecting stdout and
Expand All @@ -192,7 +191,11 @@ function apply_script_and_push_remotes() {

# Commit and push to the feature branch
git commit -m "$commit_message"
git push --quiet https://$username:$password@github.com/$username/$repository_basename $feature_branch

read -ep "Push $feature_branch changes to git@github.com:$username/$repository_basename.git? [y/n]" dopush
if [ $dopush = 'y' ]; then
git push --quiet git@github.com:$username/$repository_basename.git $feature_branch
fi

cd ..
done
Expand Down

0 comments on commit 9e9ee8a

Please sign in to comment.