forked from ESCOMP/CTSM
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
ac3e6dd Bump to 0.6.2 612fa61 Merge pull request ESCOMP#13 from jedwards4b/add_fxhash cd74fd7 Merge pull request ESCOMP#14 from jedwards4b/fix/dir_path 459ee47 merge to main f456ca0 fix issue with sparse checkout dir path ad0a976 add support for fxhash variable in .gitmodules git-subtree-dir: .lib/git-fleximod git-subtree-split: ac3e6dd
- Loading branch information
1 parent
412e86c
commit 16ebb72
Showing
4 changed files
with
63 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,10 +63,12 @@ def commandline_arguments(args=None): | |
) | ||
|
||
|
||
def submodule_sparse_checkout(root_dir, name, url, path, sparsefile, tag="master"): | ||
def submodule_sparse_checkout( | ||
root_dir, name, url, path, sparsefile, tag="master", fxhash=None | ||
): | ||
# first create the module directory | ||
if not os.path.isdir(path): | ||
os.makedirs(path) | ||
if not os.path.isdir(os.path.join(root_dir,path)): | ||
os.makedirs(os.path.join(root_dir,path)) | ||
# Check first if the module is already defined | ||
# and the sparse-checkout file exists | ||
git = GitInterface(root_dir, logger) | ||
|
@@ -121,12 +123,19 @@ def submodule_sparse_checkout(root_dir, name, url, path, sparsefile, tag="master | |
shutil.copy(os.path.join(root_dir, path, sparsefile), gitsparse) | ||
|
||
# Finally checkout the repo | ||
sprepo_git.git_operation("fetch", "--depth=1", "origin", "--tags") | ||
sprepo_git.git_operation("checkout", tag) | ||
print(f"Successfully checked out {name}") | ||
if fxhash: | ||
sprepo_git.git_operation("fetch", "origin", "--tags") | ||
sprepo_git.git_operation("checkout", fxhash) | ||
print(f"Successfully checked out {name:>20} at {fxhash}") | ||
else: | ||
sprepo_git.git_operation("fetch", "--depth=1", "origin", "--tags") | ||
sprepo_git.git_operation("checkout", tag) | ||
print(f"Successfully checked out {name:>20} at {tag}") | ||
|
||
|
||
def single_submodule_checkout(root, name, path, url=None, tag=None, force=False): | ||
def single_submodule_checkout( | ||
root, name, path, url=None, tag=None, force=False, fxhash=None | ||
): | ||
git = GitInterface(root, logger) | ||
repodir = os.path.join(root, path) | ||
if os.path.exists(os.path.join(repodir, ".git")): | ||
|
@@ -146,9 +155,12 @@ def single_submodule_checkout(root, name, path, url=None, tag=None, force=False) | |
url = url.replace("[email protected]:", "https://github.com") | ||
git.git_operation("clone", url, path) | ||
smgit = GitInterface(repodir, logger) | ||
if not tag: | ||
if not tag and not fxhash: | ||
tag = smgit.git_operation("describe", "--tags", "--always").rstrip() | ||
smgit.git_operation("checkout", tag) | ||
if fxhash: | ||
smgit.git_operation("checkout", fxhash) | ||
else: | ||
smgit.git_operation("checkout", tag) | ||
# Now need to move the .git dir to the submodule location | ||
rootdotgit = os.path.join(root, ".git") | ||
if os.path.isfile(rootdotgit): | ||
|
@@ -190,6 +202,9 @@ def submodules_status(gitmodules, root_dir): | |
for name in gitmodules.sections(): | ||
path = gitmodules.get(name, "path") | ||
tag = gitmodules.get(name, "fxtag") | ||
fxhash = gitmodules.get(name, "fxhash") | ||
if tag and fxhash: | ||
utils.fatal_error(f"{name:>20} cannot have both fxtag and fxhash") | ||
if not path: | ||
utils.fatal_error("No path found in .gitmodules for {}".format(name)) | ||
newpath = os.path.join(root_dir, path) | ||
|
@@ -211,21 +226,44 @@ def submodules_status(gitmodules, root_dir): | |
f"e {name:>20} not checked out, out of sync at tag {atag}, expected tag is {tag}" | ||
) | ||
testfails += 1 | ||
elif fxhash: | ||
n = len(fxhash) | ||
smhash = rootgit.git_operation( | ||
"ls-tree", "--object-only", f"--abbrev={n}", "HEAD", path | ||
) | ||
if smhash == fxhash: | ||
print(f" {name:>20} not checked out, aligned at hash {fxhash}") | ||
else: | ||
print( | ||
f"s {name:>20} not checked out, out of sync at hash {smhash}, expected hash is {fxhash}" | ||
) | ||
testfails += 1 | ||
else: | ||
print(f"e {name:>20} has no fxtag defined in .gitmodules") | ||
print(f"e {name:>20} has no fxtag nor fxhash defined in .gitmodules") | ||
testfails += 1 | ||
else: | ||
with utils.pushd(newpath): | ||
git = GitInterface(newpath, logger) | ||
atag = git.git_operation("describe", "--tags", "--always").rstrip() | ||
ahash = git.git_operation("status").partition("\n")[0].split()[-1] | ||
if tag and atag != tag: | ||
print(f"s {name:>20} {atag} is out of sync with .gitmodules {tag}") | ||
testfails += 1 | ||
elif tag: | ||
print(f" {name:>20} at tag {tag}") | ||
elif fxhash: | ||
rootgit = GitInterface(root_dir, logger) | ||
n = len(fxhash) | ||
if ahash.startswith(fxhash): | ||
print(f" {name:>20} at hash {fxhash}") | ||
else: | ||
print( | ||
f"s {name:>20} {ahash} is out of sync with .gitmodules {fxhash}" | ||
) | ||
testfails += 1 | ||
else: | ||
print( | ||
f"e {name:>20} has no tag defined in .gitmodules, module at {atag}" | ||
f"e {name:>20} has no fxtag nor fxhash defined in .gitmodules, module at {atag}" | ||
) | ||
testfails += 1 | ||
|
||
|
@@ -247,6 +285,7 @@ def submodules_update(gitmodules, root_dir, force): | |
return | ||
for name in gitmodules.sections(): | ||
fxtag = gitmodules.get(name, "fxtag") | ||
fxhash = gitmodules.get(name, "fxhash") | ||
path = gitmodules.get(name, "path") | ||
url = gitmodules.get(name, "url") | ||
logger.info("name={} path={} url={} fxtag={}".format(name, path, url, fxtag)) | ||
|
@@ -276,12 +315,14 @@ def submodules_update(gitmodules, root_dir, force): | |
if fxtag and fxtag not in tags: | ||
git.git_operation("fetch", newremote, "--tags") | ||
atag = git.git_operation("describe", "--tags", "--always").rstrip() | ||
|
||
if fxtag and fxtag != atag: | ||
print(f"{name:>20} updated to {fxtag}") | ||
git.git_operation("checkout", fxtag) | ||
elif not fxtag: | ||
print(f"No fxtag found for submodule {name:>20}") | ||
elif fxhash: | ||
print(f"{name:>20} updated to {fxhash}") | ||
git.git_operation("checkout", fxhash) | ||
elif not (fxtag or fxhash): | ||
print(f"No fxtag nor fxhash found for submodule {name:>20}") | ||
else: | ||
print(f"{name:>20} up to date.") | ||
|
||
|
@@ -298,6 +339,7 @@ def submodules_checkout(gitmodules, root_dir, requiredlist, force=False): | |
fxrequired = gitmodules.get(name, "fxrequired") | ||
fxsparse = gitmodules.get(name, "fxsparse") | ||
fxtag = gitmodules.get(name, "fxtag") | ||
fxhash = gitmodules.get(name, "fxhash") | ||
path = gitmodules.get(name, "path") | ||
url = gitmodules.get(name, "url") | ||
|
||
|
@@ -312,14 +354,16 @@ def submodules_checkout(gitmodules, root_dir, requiredlist, force=False): | |
root_dir, name, url, path, fxsparse, fxtag | ||
) | ||
) | ||
submodule_sparse_checkout(root_dir, name, url, path, fxsparse, tag=fxtag) | ||
submodule_sparse_checkout( | ||
root_dir, name, url, path, fxsparse, tag=fxtag, fxhash=fxhash | ||
) | ||
else: | ||
logger.debug( | ||
"Calling submodule_checkout({},{},{})".format(root_dir, name, path) | ||
) | ||
|
||
single_submodule_checkout( | ||
root_dir, name, path, url=url, tag=fxtag, force=force | ||
root_dir, name, path, url=url, tag=fxtag, force=force, fxhash=fxhash | ||
) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "git-fleximod" | ||
version = "0.6.1" | ||
version = "0.6.2" | ||
description = "Extended support for git-submodule and git-sparse-checkout" | ||
authors = ["Jim Edwards <[email protected]>"] | ||
maintainers = ["Jim Edwards <[email protected]>"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters