Reputation: 833
I have script which tags Azure DevOps repos.
I am having few issues while tagging repos -
If tag does not present still I get fatal: tag already exist and then script goes ahead and tags that repo
I have given tag in script. If I change the tag in script it tagges repo with 2 tags. previous and updated tags in the script
for example this is the command - git tag -a AzDo -m "{}"".format(details) if I change this to git tag -a AzDo_123 -m "{}"".format(details) and run the script. Its tagging repo with 2 tags AzDo_123, Azdo
def PushTags(org,token,project,repoName,user,email):
os.system("git config --global user.name \"{}\"".format(user))
os.system("git config --global user.email \"{}\"".format(email))
os.system("git remote set-url --push origin https://{User_Name}:
{PAT}@{Org}.visualstudio.com/{Project_Name}/_git/{Repo_Name}"\
.format(User_Name=user,PAT=token,Org=org,Project_Name=project,Repo_Name=repoName))
os.system("git tag -a AzDo -m \"{}\"".format(details))
os.system("git push --tags")
DO I need to make any changes in the script (git commands) to make sure its only tagging right tags to the repo ?
Upvotes: 0
Views: 550
Reputation: 30888
The commands in PushTags
are executed in a local repository, and it seems the repository is never changed. Changing origin's push url only updates the push route to the remote repository, and the local repository is still the original one. When PushTags
is called multiple times, it always tries to create the same tag on the same commit(HEAD
), so it complains that the tag already exists.
I can think of 2 solutions. One is fetching the branch and then creating the tag on the right commit. The other is to call Azure's restapi if it has any.
Suppose you want to create a tag AzDo
on the commit 123abc
which is on the branch foo
in the repository repoName
.
# fetch foo from repoName
git fetch ${url_to_repoName} foo
# as you run the commands in the same repository, remove the existing AzDo first
git tag -d AzDo
# create tag AzDo on 123abc
git tag -a AzDo -m <msg> 123abc
# push the new Azdo to repoName
git push ${url_to_repoName} refs/tags/Azdo:refs/tags/Azdo
As to the restapi, I'm not familiar with Azure DevOps. You could refer to its docs.
Upvotes: 0