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
ae351b71
Commit
ae351b71
authored
Oct 22, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1414 from sfromm/issue1412
Help git module work when working in 'no branch' scenario
parents
109632e3
769bd912
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
4 deletions
+29
-4
library/git
+29
-4
No files found.
library/git
View file @
ae351b71
...
...
@@ -146,7 +146,27 @@ def is_current_branch(module, dest, branch):
else
:
return
True
def
pull
(
module
,
repo
,
dest
,
version
):
def
is_not_a_branch
(
module
,
dest
):
branches
=
get_branches
(
module
,
dest
)
for
b
in
branches
:
if
b
.
startswith
(
'* '
)
and
'no branch'
in
b
:
return
True
return
False
def
get_head_branch
(
module
,
dest
,
remote
):
os
.
chdir
(
dest
)
head
=
''
cmd
=
"git remote show
%
s"
%
remote
cmd
=
subprocess
.
Popen
(
cmd
,
shell
=
True
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
out
,
err
=
cmd
.
communicate
()
if
cmd
.
returncode
!=
0
:
module
.
fail_json
(
msg
=
"Could not determine HEAD branch via git remote show"
)
for
line
in
out
.
split
(
'
\n
'
):
if
'HEAD branch'
in
line
:
head
=
line
.
split
()[
-
1
]
.
strip
()
return
head
def
pull
(
module
,
repo
,
dest
,
version
,
remote
):
''' updates repo from remote sources '''
os
.
chdir
(
dest
)
branches
=
get_branches
(
module
,
dest
)
...
...
@@ -158,8 +178,13 @@ def pull(module, repo, dest, version):
(
rc
,
out
,
err
)
=
switch_version
(
module
,
dest
,
remote
,
version
)
if
rc
!=
0
:
module
.
fail_json
(
msg
=
err
)
if
is_not_a_branch
(
module
,
dest
):
head_branch
=
get_head_branch
(
module
,
dest
,
remote
)
(
rc
,
out
,
err
)
=
switch_version
(
module
,
dest
,
remote
,
head_branch
)
if
rc
!=
0
:
module
.
fail_json
(
msg
=
err
)
cmd
=
"git pull -u
origin"
cmd
=
"git pull -u
%
s"
%
remote
cmd
=
subprocess
.
Popen
(
cmd
,
shell
=
True
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
out
,
err
=
cmd
.
communicate
()
rc
=
cmd
.
returncode
...
...
@@ -176,7 +201,7 @@ def switch_version(module, dest, remote, version):
cmd
=
"git checkout --force
%
s"
%
version
else
:
# is there a better way to do this?
cmd
=
"git rebase
origin"
cmd
=
"git rebase
%
s"
%
remote
cmd
=
subprocess
.
Popen
(
cmd
,
shell
=
True
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
(
out
,
err
)
=
cmd
.
communicate
()
rc
=
cmd
.
returncode
...
...
@@ -220,7 +245,7 @@ def main():
(
rc
,
out
,
err
)
=
reset
(
module
,
dest
,
force
)
if
rc
!=
0
:
module
.
fail_json
(
msg
=
err
)
(
rc
,
out
,
err
)
=
pull
(
module
,
repo
,
dest
,
version
)
(
rc
,
out
,
err
)
=
pull
(
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