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
325b397a
Commit
325b397a
authored
May 08, 2012
by
felix
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added in support for branches in git module (now takes optional "branch")
parent
b2485850
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
7 deletions
+53
-7
library/git
+53
-7
No files found.
library/git
View file @
325b397a
...
@@ -28,6 +28,7 @@ try:
...
@@ -28,6 +28,7 @@ try:
except
ImportError
:
except
ImportError
:
import
simplejson
as
json
import
simplejson
as
json
import
os
import
os
import
re
import
sys
import
sys
import
shlex
import
shlex
import
subprocess
import
subprocess
...
@@ -68,6 +69,7 @@ for x in items:
...
@@ -68,6 +69,7 @@ for x in items:
dest
=
params
[
'dest'
]
dest
=
params
[
'dest'
]
repo
=
params
[
'repo'
]
repo
=
params
[
'repo'
]
branch
=
params
.
get
(
'branch'
)
version
=
params
.
get
(
'version'
,
'HEAD'
)
version
=
params
.
get
(
'version'
,
'HEAD'
)
# ===========================================
# ===========================================
...
@@ -80,7 +82,7 @@ def get_version(dest):
...
@@ -80,7 +82,7 @@ def get_version(dest):
sha
=
sha
[
0
]
.
split
()[
1
]
sha
=
sha
[
0
]
.
split
()[
1
]
return
sha
return
sha
def
clone
(
repo
,
dest
):
def
clone
(
repo
,
dest
,
branch
):
''' makes a new git repo if it does not already exist '''
''' makes a new git repo if it does not already exist '''
try
:
try
:
os
.
makedirs
(
dest
)
os
.
makedirs
(
dest
)
...
@@ -88,6 +90,15 @@ def clone(repo, dest):
...
@@ -88,6 +90,15 @@ def clone(repo, dest):
pass
pass
cmd
=
"git clone
%
s
%
s"
%
(
repo
,
dest
)
cmd
=
"git clone
%
s
%
s"
%
(
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
)
(
out
,
err
)
=
cmd
.
communicate
()
rc
=
cmd
.
returncode
if
branch
is
None
or
rc
!=
0
:
return
(
out
,
err
)
os
.
chdir
(
dest
)
cmd
=
"git checkout -b
%
s origin/
%
s"
%
(
branch
,
branch
)
cmd
=
subprocess
.
Popen
(
cmd
,
shell
=
True
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
return
cmd
.
communicate
()
return
cmd
.
communicate
()
def
reset
(
dest
):
def
reset
(
dest
):
...
@@ -103,14 +114,48 @@ def reset(dest):
...
@@ -103,14 +114,48 @@ def reset(dest):
rc
=
cmd
.
returncode
rc
=
cmd
.
returncode
return
(
rc
,
out
,
err
)
return
(
rc
,
out
,
err
)
def
pull
(
repo
,
dest
):
def
switchLocalBranch
(
branch
):
cmd
=
"git checkout
%
s"
%
branch
cmd
=
subprocess
.
Popen
(
cmd
,
shell
=
True
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
return
cmd
.
communicate
()
def
pull
(
repo
,
dest
,
branch
):
''' updates repo from remote sources '''
''' updates repo from remote sources '''
os
.
chdir
(
dest
)
os
.
chdir
(
dest
)
cmd
=
"git pull -u origin"
cmd
=
"git branch -a"
cmd
=
subprocess
.
Popen
(
cmd
,
shell
=
True
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
(
gbranch_out
,
gbranch_err
)
=
cmd
.
communicate
()
try
:
m
=
re
.
search
(
'^
\
* (
\
S+|
\
(no branch
\
))$'
,
gbranch_out
,
flags
=
re
.
M
)
cur_branch
=
m
.
group
(
1
)
m
=
re
.
search
(
'
\
s+remotes/origin/HEAD -> origin/(
\
S+)'
,
gbranch_out
,
flags
=
re
.
M
)
default_branch
=
m
.
group
(
1
)
except
:
fail_json
(
msg
=
"could not determine branch data - received:
%
s"
%
gbranch_out
)
if
branch
is
None
:
if
cur_branch
!=
default_branch
:
(
out
,
err
)
=
switchLocalBranch
(
default_branch
)
cmd
=
"git pull -u origin"
elif
branch
==
cur_branch
:
cmd
=
"git pull -u origin"
else
:
m
=
re
.
search
(
'^
\
s+
%
s$'
%
branch
,
gbranch_out
,
flags
=
re
.
M
)
#see if we've already checked it out
if
m
is
None
:
cmd
=
"git checkout -b
%
s origin/
%
s"
%
(
branch
,
branch
)
else
:
(
out
,
err
)
=
switchLocalBranch
(
branch
)
cmd
=
"git pull -u origin"
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
switchver
(
version
,
dest
):
def
switchver
(
version
,
dest
,
branch
):
''' once pulled, switch to a particular SHA or tag '''
''' once pulled, switch to a particular SHA or tag '''
os
.
chdir
(
dest
)
os
.
chdir
(
dest
)
if
version
!=
'HEAD'
:
if
version
!=
'HEAD'
:
...
@@ -118,6 +163,7 @@ def switchver(version, dest):
...
@@ -118,6 +163,7 @@ def switchver(version, dest):
else
:
else
:
# is there a better way to do this?
# is there a better way to do this?
cmd
=
"git rebase origin"
cmd
=
"git rebase origin"
cmd
=
subprocess
.
Popen
(
cmd
,
shell
=
True
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
cmd
=
subprocess
.
Popen
(
cmd
,
shell
=
True
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
(
out
,
err
)
=
cmd
.
communicate
()
(
out
,
err
)
=
cmd
.
communicate
()
return
(
out
,
err
)
return
(
out
,
err
)
...
@@ -132,14 +178,14 @@ out, err, status = (None, None, None)
...
@@ -132,14 +178,14 @@ out, err, status = (None, None, None)
before
=
None
before
=
None
if
not
os
.
path
.
exists
(
gitconfig
):
if
not
os
.
path
.
exists
(
gitconfig
):
(
out
,
err
)
=
clone
(
repo
,
dest
)
(
out
,
err
)
=
clone
(
repo
,
dest
,
branch
)
else
:
else
:
# else do a pull
# else do a pull
before
=
get_version
(
dest
)
before
=
get_version
(
dest
)
(
rc
,
out
,
err
)
=
reset
(
dest
)
(
rc
,
out
,
err
)
=
reset
(
dest
)
if
rc
!=
0
:
if
rc
!=
0
:
fail_json
(
out
=
out
,
err
=
err
)
fail_json
(
out
=
out
,
err
=
err
)
(
out
,
err
)
=
pull
(
repo
,
dest
)
(
out
,
err
)
=
pull
(
repo
,
dest
,
branch
)
# handle errors from clone or pull
# handle errors from clone or pull
...
@@ -149,7 +195,7 @@ if out.find('error') != -1:
...
@@ -149,7 +195,7 @@ if out.find('error') != -1:
# switch to version specified regardless of whether
# switch to version specified regardless of whether
# we cloned or pulled
# we cloned or pulled
(
out
,
err
)
=
switchver
(
version
,
dest
)
(
out
,
err
)
=
switchver
(
version
,
dest
,
branch
)
if
err
.
find
(
'error'
)
!=
-
1
:
if
err
.
find
(
'error'
)
!=
-
1
:
fail_json
(
out
=
out
,
err
=
err
)
fail_json
(
out
=
out
,
err
=
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