Hi guys, I met a pretty weird staff when running the following code to
update tags.
Code:
#!/usr/bin/env python
from concurrent import futures
import sh
executor = futures.ThreadPoolExecutor(
max_workers=20, thread_name_prefix="update-tags"
)
tag_list = [ f"tag-test-{i}" for i in range(1,100)]
def update_tag(tag_name):
current_commit_id = sh.git("rev-parse", "HEAD").strip()
print("fetch remote tags")
try:
sh.git("fetch", "--all", "--tags", "--force","--atomic")
except Exception:
pass
output=sh.git("rev-list","-n","1",tag_name)
if output.strip("\n") == current_commit_id:
return
print(f"{tag_name}: commit id before update is {output}")
# sh.git("tag","-d",tag_name)
print(f"{tag_name}: create tag with current commit {current_commit_id}")
sh.git("tag","--force", "-a","-m","test",tag_name)
print(f"{tag_name}: push to remote")
sh.git("push", "origin", tag_name, "--force")
output=sh.git("rev-list","-n","1",tag_name)
print(f"{tag_name}: commit id after update is {output}")
threadpool_results = executor.map(update_tag, tag_list)
current_commit_id = sh.git("rev-parse", "HEAD").strip()
print(f"current repo commit is {current_commit_id}")
print(list(threadpool_results))
for tag_name in tag_list:
output=sh.git("rev-list","-n","1",tag_name)
if output.strip("\n") != current_commit_id:
print(f"{tag_name}: Failed to update tag {tag_name}")
In the code above, when we update a tag, we fetch the remote tags first,
then compare the tag with current local commit to decide whether we should
update or not.
When we run this process concurrently, we find some of the tags failed to
update. Moreover, the command does not fail. That's so weird.
taking tag-test-98 as an example, the commit id of this tag was changed
after running git tag. However, the tag is unchanged after the whole thread
pool is finished.
tag-test-98: commit id before the update is
75e3f1b922a4673baa73fe4312928088d10a620c
tag-test-98: create tag with current commit
4dc6859c15f0a25b532f050ddc9f75a1a25d3860
tag-test-98: push to remote
tag-test-98: commit id after update is
75e3f1b922a4673baa73fe4312928088d10a620c
tag-test-98: Failed to update tag tag-test-98
Is it a bug or something?
--
You received this message because you are subscribed to the Google Groups "Git
for human beings" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/git-users/b2f77dec-b1c7-4d25-81ee-f9c46906216an%40googlegroups.com.