Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script add # symbol to Azure DevOps task number in the end of commit messages in working branch
#!/bin/bash
currentBranchName=$(git rev-parse --abbrev-ref HEAD)
add_hash() {
echo ""
git filter-repo -f --refs develop..$currentBranchName --message-callback '
lastWord = message.split()[-1]
def RepresentsInt(s):
try:
int(s)
return True
except ValueError:
return False
if RepresentsInt(lastWord):
return message.replace(lastWord, b"#" + lastWord)
else:
return message'
}
echo ""
echo "You want to add # character to task numbers to last $(git rev-list --count master..$currentBranchName) commits."
# https://stackoverflow.com/questions/226703/how-do-i-prompt-for-yes-no-cancel-input-in-a-linux-shell-script
while true; do
read -p "Do you want to continue [y/n]? " yn
case $yn in
[Yy]* ) add_hash $1; break;;
[Nn]* ) exit;;
* ) echo "Please answer yes [y] or no [n].";;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment