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
9ad4e7d1
Commit
9ad4e7d1
authored
May 02, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #300 from sfromm/git
Updates for git module
parents
5fe67764
887d293a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
34 deletions
+34
-34
library/git
+34
-34
No files found.
library/git
View file @
9ad4e7d1
...
...
@@ -33,34 +33,33 @@ import shlex
import
subprocess
# ===========================================
# Basic support methods
def
exit_json
(
rc
=
0
,
**
kwargs
):
print
json
.
dumps
(
kwargs
)
sys
.
exit
(
rc
)
def
fail_json
(
**
kwargs
):
kwargs
[
'failed'
]
=
True
exit_json
(
rc
=
1
,
**
kwargs
)
# ===========================================
# convert arguments of form a=b c=d
# to a dictionary
# FIXME: make more idiomatic
if
len
(
sys
.
argv
)
==
1
:
print
json
.
dumps
({
"failed"
:
True
,
"msg"
:
"the command module requires arguments (-a)"
})
sys
.
exit
(
1
)
fail_json
(
msg
=
"the command module requires arguments (-a)"
)
argfile
=
sys
.
argv
[
1
]
if
not
os
.
path
.
exists
(
argfile
):
print
json
.
dumps
({
"failed"
:
True
,
"msg"
:
"Argument file not found"
})
sys
.
exit
(
1
)
fail_json
(
msg
=
"Argument file not found"
)
args
=
open
(
argfile
,
'r'
)
.
read
()
items
=
shlex
.
split
(
args
)
if
not
len
(
items
):
print
json
.
dumps
({
"failed"
:
True
,
"msg"
:
"the command module requires arguments (-a)"
})
sys
.
exit
(
1
)
fail_json
(
msg
=
"the command module requires arguments (-a)"
)
params
=
{}
for
x
in
items
:
...
...
@@ -69,7 +68,7 @@ for x in items:
dest
=
params
[
'dest'
]
repo
=
params
[
'repo'
]
version
=
params
[
'version'
]
version
=
params
.
get
(
'version'
,
'HEAD'
)
# ===========================================
...
...
@@ -91,6 +90,19 @@ def clone(repo, dest):
cmd
=
subprocess
.
Popen
(
cmd
,
shell
=
True
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
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
):
''' updates repo from remote sources '''
os
.
chdir
(
dest
)
...
...
@@ -124,29 +136,22 @@ if not os.path.exists(gitconfig):
else
:
# else do a pull
before
=
get_version
(
dest
)
(
rc
,
out
,
err
)
=
reset
(
dest
)
if
rc
!=
0
:
fail_json
(
out
=
out
,
err
=
err
)
(
out
,
err
)
=
pull
(
repo
,
dest
)
# handle errors from clone or pull
if
out
.
find
(
'error'
)
!=
-
1
:
print
json
.
dumps
({
"failed"
:
True
,
"out"
:
out
,
"err"
:
err
})
sys
.
exit
(
1
)
fail_json
(
out
=
out
,
err
=
err
)
# switch to version specified regardless of whether
# we cloned or pulled
(
out
,
err
)
=
switchver
(
version
,
dest
)
if
err
.
find
(
'error'
)
!=
-
1
:
print
json
.
dumps
({
"failed"
:
True
,
"out"
:
out
,
"err"
:
err
})
sys
.
exit
(
1
)
fail_json
(
out
=
out
,
err
=
err
)
# determine if we changed anything
...
...
@@ -156,9 +161,4 @@ changed = False
if
before
!=
after
:
changed
=
True
print
json
.
dumps
({
"changed"
:
changed
,
"before"
:
before
,
"after"
:
after
})
exit_json
(
changed
=
changed
,
before
=
before
,
after
=
after
)
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