Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
H
Hdlmake
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
15
Issues
15
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
Hdlmake
Commits
81f8c750
Commit
81f8c750
authored
Mar 08, 2017
by
Javier D. Garcia-Lasheras
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Read the commit id from the Git submodule if available
parent
3427cf5f
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
34 deletions
+54
-34
git.py
hdlmake/fetch/git.py
+54
-34
No files found.
hdlmake/fetch/git.py
View file @
81f8c750
...
...
@@ -25,7 +25,7 @@ from __future__ import absolute_import
import
os
from
hdlmake.util
import
path
as
path_utils
import
logging
from
subprocess
import
Popen
,
PIPE
from
subprocess
import
Popen
,
PIPE
,
CalledProcessError
from
.constants
import
GIT
from
.fetcher
import
Fetcher
...
...
@@ -39,21 +39,45 @@ class Git(Fetcher):
pass
@
staticmethod
def
get_git_toplevel
(
module
):
def
get_git_toplevel
():
"""Get the top level for the Git repository"""
cur_dir
=
module
.
pool
.
top_module
.
path
try
:
os
.
chdir
(
path_utils
.
rel2abs
(
module
.
path
))
if
not
os
.
path
.
exists
(
".gitmodules"
):
return
None
tree_root_cmd
=
Popen
(
"git rev-parse --show-toplevel"
,
stdout
=
PIPE
,
stdin
=
PIPE
,
close_fds
=
not
path_utils
.
check_windows
(),
shell
=
True
)
tree_root_line
=
tree_root_cmd
.
stdout
.
readlines
()[
0
]
.
strip
()
return
tree_root_line
finally
:
os
.
chdir
(
cur_dir
)
except
CalledProcessError
as
e
:
print
e
.
output
logging
.
error
(
"Cannot get the top level!"
)
quit
()
@
staticmethod
def
get_submodule_commit
(
submodule_dir
):
"""Get the commit for a repository if defined in Git submodules"""
try
:
command_tmp
=
"git submodule status
%
s"
%
submodule_dir
status_cmd
=
Popen
(
command_tmp
,
stdout
=
PIPE
,
stdin
=
PIPE
,
stderr
=
PIPE
,
close_fds
=
not
path_utils
.
check_windows
(),
shell
=
True
)
status_output
=
status_cmd
.
stdout
.
readlines
()
if
len
(
status_output
)
==
1
:
status_line
=
status_output
[
0
]
.
split
()
if
len
(
status_line
)
==
2
:
return
status_line
[
0
][
1
:]
else
:
return
None
else
:
return
None
except
CalledProcessError
as
e
:
print
e
.
output
logging
.
error
(
"Cannot get the submodule status!"
)
quit
()
def
fetch
(
self
,
module
):
"""Get the code from the remote Git repository"""
...
...
@@ -62,41 +86,37 @@ class Git(Fetcher):
raise
ValueError
(
"This backend should get git modules only."
)
if
not
os
.
path
.
exists
(
fetchto
):
os
.
mkdir
(
fetchto
)
cur_dir
=
module
.
pool
.
top_module
.
path
if
module
.
branch
is
None
:
module
.
branch
=
"master"
basename
=
path_utils
.
url_basename
(
module
.
url
)
mod_path
=
os
.
path
.
join
(
fetchto
,
basename
)
logging
.
info
(
"Fetching git module:
%
s"
,
mod_path
)
if
basename
.
endswith
(
".git"
):
basename
=
basename
[:
-
4
]
# remove trailing .git
if
module
.
isfetched
:
update_only
=
True
if
not
module
.
isfetched
:
logging
.
info
(
"Fetching git module
%
s"
,
mod_path
)
cmd
=
"(cd {0} && git clone {1})"
cmd
=
cmd
.
format
(
fetchto
,
module
.
url
)
if
os
.
system
(
cmd
)
!=
0
:
return
False
else
:
update_only
=
False
if
update_only
:
logging
.
info
(
"Updating module
%
s"
,
mod_path
)
cmd
=
"(cd {0} && git checkout {1})"
cmd
=
cmd
.
format
(
mod_path
,
module
.
branch
)
logging
.
info
(
"Updating git module
%
s"
,
mod_path
)
checkout_id
=
None
if
module
.
branch
is
not
None
:
checkout_id
=
module
.
branch
logging
.
debug
(
"Git branch requested:
%
s"
,
checkout_id
)
elif
module
.
revision
is
not
None
:
checkout_id
=
module
.
revision
logging
.
debug
(
"Git commit requested:
%
s"
,
checkout_id
)
else
:
logging
.
info
(
"Cloning module
%
s"
,
mod_path
)
cmd
=
"(cd {0} && git clone -b {2} {1})"
cmd
=
cmd
.
format
(
fetchto
,
module
.
url
,
module
.
branch
)
success
=
True
logging
.
debug
(
"Running
%
s"
,
cmd
)
if
os
.
system
(
cmd
)
!=
0
:
success
=
False
if
module
.
revision
is
not
None
and
success
is
True
:
logging
.
debug
(
"cd
%
s"
,
mod_path
)
os
.
chdir
(
mod_path
)
cmd
=
"git checkout "
+
module
.
revision
logging
.
debug
(
"Running
%
s"
,
cmd
)
checkout_id
=
self
.
get_submodule_commit
(
module
.
path
)
logging
.
debug
(
"Git submodule commit:
%
s"
,
checkout_id
)
if
checkout_id
is
not
None
:
logging
.
info
(
"Checking out version
%
s"
,
checkout_id
)
cmd
=
"(cd {0} && git checkout {1})"
cmd
=
cmd
.
format
(
mod_path
,
checkout_id
)
if
os
.
system
(
cmd
)
!=
0
:
success
=
False
os
.
chdir
(
cur_dir
)
return
False
module
.
isfetched
=
True
module
.
path
=
mod_path
return
success
return
True
@
staticmethod
def
check_git_commit
(
path
):
...
...
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