Page MenuHomeDevCentral
Paste P383

bin/arc-delete-remote-branch
ActivePublic

Authored by dereckson on Sat, Feb 14, 12:25.
Referenced Files
F24358074: bin/arc-delete-remote-branch
Sun, Feb 15, 11:40
F24330878: bin/arc-delete-remote-ops-branch
Sat, Feb 14, 12:25
Subscribers
None
#!/bin/sh
#
# Usage: arc-delete-remote-branch [branch]
# Default value: master
#
set -e
# -------------------------------------------------------------
# Parse arguments
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if [ "$#" -gt 0 ]; then
branch=$1
shift
else
branch=master
fi
# Assumes origin is the Arcanist clone
remote=origin
# -------------------------------------------------------------
# Find repository code on Phabricator instance
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
REPO_PATH=$(git rev-parse --show-toplevel)
REPO_RETCODE=$?
if [ $REPO_RETCODE -ne 0 ]; then
exit $REPO_RETCODE
fi;
ARC_CONFIG=$REPO_PATH/.arcconfig
if [ ! -f $ARC_CONFIG ]; then
echo "Can't find Arcanist configuration: $ARC_CONFIG" >&2
exit 2
fi
repo_callsign=$(cat $ARC_CONFIG | jq -r '.["repository.callsign"]')
jq -n --arg callsign "$repo_callsign" '{
transactions: [
{
type: "allowDangerousChanges",
value: true
}
],
objectIdentifier: ("r" + $callsign)
}' | arc call-conduit -- diffusion.repository.edit
git push $remote --delete $branch
jq -n --arg callsign "$repo_callsign" '{
transactions: [
{
type: "allowDangerousChanges",
value: false
}
],
objectIdentifier: ("r" + $callsign)
}' | arc call-conduit -- diffusion.repository.edit

Event Timeline

Known issues:

  • assumes origin points to the right instance, e.g. DevCentral
  • if the branch doesn't exit, git push will fail and so allowDangerousChanges will stay at true
dereckson changed the title of this paste from bin/arc-delete-remote-ops-branch to bin/arc-delete-remote-branch.Sat, Feb 14, 12:36
dereckson updated the paste's language from autodetect to bash.

The default branch is master, as that was one of the main use of my remote delete script when we switched repositories to main branch.