# This script takes one input:# branch name# To archive a branch in this repo run: ./archive_branch.sh branch_name# capture the standard output of a command so it can be retrieved with ret
cap (){ tee /tmp/capture.out;}# return the output of the most recent command that was captured by cap
ret (){ cat /tmp/capture.out;}# checkout master to make sure not on the branch archiving
git checkout main
git pull
# redirect error message to stdout so can be captured
git tag archive/$1$12>/tmp/capture.out | cap
echo$(ret)if[[$(ret)== *"Failed to resolve"* ]];then# try checking out the branch first
git checkout $12>/tmp/capture.out | cap
echo$(ret)if[[$(ret)== *"did not match any file"* ]];thenecho"ERROR REASON: $1 branch doesn't exist"exit0fi
git checkout master
git tag archive/$1$12>/tmp/capture.out | cap
echo$(ret)if[[$(ret)== *"already exists"* ]];thenecho Tag already exists, specify new name:
read newTag
git tag archive/$newTag$12>/tmp/capture.out | cap
echo$(ret)if[[$(ret)== *"already exists"* ]];thenecho ERROR REASON: New tag name already exists
exit0fifielif[[$(ret)== *"already exists"* ]];thenecho Tag already exists, specify new name:
read newTag
git tag archive/$newTag$12>/tmp/capture.out | cap
echo$(ret)if[[$(ret)== *"already exists"* ]];thenecho ERROR REASON: New tag name already exists
exit0fielseecho tag archive/$1 created successfully
fi
git push origin --tags
git branch -d $1
git push -d origin $1