mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Add git reset --hard support to git module
Resets working tree to what is in HEAD and discards any uncommitted changes.
This commit is contained in:
parent
40dbd9b3d7
commit
887d293a3b
1 changed files with 16 additions and 0 deletions
16
library/git
16
library/git
|
@ -90,6 +90,19 @@ def clone(repo, dest):
|
||||||
cmd = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
cmd = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
return cmd.communicate()
|
return cmd.communicate()
|
||||||
|
|
||||||
|
def reset(dest):
|
||||||
|
'''
|
||||||
|
Resets the index and working tree to HEAD.
|
||||||
|
Discards any changes to tracked files in working
|
||||||
|
tree since that commit.
|
||||||
|
'''
|
||||||
|
os.chdir(dest)
|
||||||
|
cmd = "git reset --hard HEAD"
|
||||||
|
cmd = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
|
(out, err) = cmd.communicate()
|
||||||
|
rc = cmd.returncode
|
||||||
|
return (rc, out, err)
|
||||||
|
|
||||||
def pull(repo, dest):
|
def pull(repo, dest):
|
||||||
''' updates repo from remote sources '''
|
''' updates repo from remote sources '''
|
||||||
os.chdir(dest)
|
os.chdir(dest)
|
||||||
|
@ -123,6 +136,9 @@ if not os.path.exists(gitconfig):
|
||||||
else:
|
else:
|
||||||
# else do a pull
|
# else do a pull
|
||||||
before = get_version(dest)
|
before = get_version(dest)
|
||||||
|
(rc, out, err) = reset(dest)
|
||||||
|
if rc != 0:
|
||||||
|
fail_json(out=out, err=err)
|
||||||
(out, err) = pull(repo, dest)
|
(out, err) = pull(repo, dest)
|
||||||
|
|
||||||
# handle errors from clone or pull
|
# handle errors from clone or pull
|
||||||
|
|
Loading…
Reference in a new issue