Do not undo tags when git state is dirty

When using `tito tag --undo` in a repository with a dirty
`git` state, no action should be taken.

Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
This commit is contained in:
Steve Kuznetsov 2017-01-28 16:50:53 -05:00
parent 26219abfde
commit ce7cb5b3c7
No known key found for this signature in database
GPG key ID: 366E054B30FC03A2

View file

@ -544,12 +544,30 @@ def undo_tag(tag):
commit. Assumes you have taken necessary precautions to ensure this is
what you want to do.
"""
if not is_git_state_clean():
error_out("Cannot undo a tag when the current git state is not clean!")
# Using --merge here as it appears to undo the changes in the commit,
# but preserve any modified files:
output = run_command("git tag -d %s && git reset --merge HEAD^1" % tag)
print(output)
def is_git_state_clean():
"""
Determines if the state of the current git repository is clean or not.
"""
(status, _) = getstatusoutput("git diff-index --quiet HEAD")
if status != 0:
return False
(status, output) = getstatusoutput("git ls-files --exclude-standard --others")
if len(output) > 0 or status > 0:
return False
return True
def get_remote_tag_sha1(tag):
"""
Get the SHA1 referenced by this git tag in the remote git repo.