Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
d7a2ac2c
Commit
d7a2ac2c
authored
Mar 17, 2013
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2401 from sfromm/git-check-mode
Add check mode to git module
parents
921cdaec
73772a41
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
1 deletions
+26
-1
library/git
+26
-1
No files found.
library/git
View file @
d7a2ac2c
...
...
@@ -103,6 +103,17 @@ def reset(module,dest,force):
module
.
fail_json
(
msg
=
"Local modifications exist in repository (force=no)."
)
return
module
.
run_command
(
"git reset --hard HEAD"
,
check_rc
=
True
)
def
get_remote_head
(
module
,
dest
,
version
,
remote
):
if
version
==
'HEAD'
:
version
=
get_head_branch
(
module
,
dest
,
remote
)
os
.
chdir
(
dest
)
cmd
=
"git ls-remote
%
s -h refs/heads/
%
s"
%
(
remote
,
version
)
(
rc
,
out
,
err
)
=
module
.
run_command
(
cmd
,
check_rc
=
True
)
if
len
(
out
)
<
1
:
module
.
fail_json
(
msg
=
"Could not determine remote revision for
%
s"
%
version
)
rev
=
out
.
split
()[
0
]
return
rev
def
get_branches
(
module
,
dest
):
os
.
chdir
(
dest
)
branches
=
[]
...
...
@@ -224,7 +235,8 @@ def main():
version
=
dict
(
default
=
'HEAD'
),
remote
=
dict
(
default
=
'origin'
),
force
=
dict
(
default
=
'yes'
,
type
=
'bool'
)
)
),
supports_check_mode
=
True
)
dest
=
os
.
path
.
abspath
(
os
.
path
.
expanduser
(
module
.
params
[
'dest'
]))
...
...
@@ -242,14 +254,27 @@ def main():
before
=
None
local_mods
=
False
if
not
os
.
path
.
exists
(
gitconfig
):
if
module
.
check_mode
:
module
.
exit_json
(
changed
=
True
)
(
rc
,
out
,
err
)
=
clone
(
module
,
repo
,
dest
,
remote
)
else
:
# else do a pull
local_mods
=
has_local_mods
(
dest
)
before
=
get_version
(
dest
)
# if force, do a reset
if
local_mods
and
module
.
check_mode
:
module
.
exit_json
(
changed
=
True
,
msg
=
'Local modifications exist'
)
(
rc
,
out
,
err
)
=
reset
(
module
,
dest
,
force
)
if
rc
!=
0
:
module
.
fail_json
(
msg
=
err
)
# check or get changes from remote
remote_head
=
get_remote_head
(
module
,
dest
,
version
,
remote
)
if
module
.
check_mode
:
remote_head
=
remote_head
[
0
:
7
]
if
before
!=
remote_head
:
module
.
exit_json
(
changed
=
True
,
before
=
before
,
after
=
remote_head
)
else
:
module
.
exit_json
(
changed
=
False
,
before
=
before
,
after
=
remote_head
)
(
rc
,
out
,
err
)
=
fetch
(
module
,
repo
,
dest
,
version
,
remote
)
if
rc
!=
0
:
module
.
fail_json
(
msg
=
err
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment