From c0c5a68653fa66eabd431ef2b8ec1b2624dfe0f6 Mon Sep 17 00:00:00 2001 From: Hugh Sorby Date: Wed, 8 Nov 2023 14:05:07 +1300 Subject: [PATCH] Add to provenance to get remote location from source directory. --- src/mapclient/core/provenance.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/mapclient/core/provenance.py b/src/mapclient/core/provenance.py index 59a98c1..c327081 100644 --- a/src/mapclient/core/provenance.py +++ b/src/mapclient/core/provenance.py @@ -35,13 +35,31 @@ def _strip_pip_list_output(output_stream): return output -def describe_tag(src_dir, check_parent=True): +def _determine_git_repo(src_dir, check_parent=True): git_repo = None if os.path.isdir(os.path.join(src_dir, ".git")): git_repo = src_dir elif check_parent and os.path.isdir(os.path.join(src_dir, "..", ".git")): git_repo = os.path.join(src_dir, "..") + return git_repo + + +def remote_locations(src_dir): + git_repo = _determine_git_repo(src_dir, False) + + if git_repo is None: + return "&&&&&&" + + with dulwich.porcelain.open_repo_closing(git_repo) as r: + remote_repo_info = dulwich.porcelain.get_remote_repo(r) + + return remote_repo_info[1] + + +def describe_tag(src_dir, check_parent=True): + git_repo = _determine_git_repo(src_dir, check_parent) + if git_repo is None: return "******"