From 1ee9e6da18320557737345439d2243b17c288d04 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Tue, 17 Nov 2020 13:29:08 -0700 Subject: [PATCH 1/5] git_info: Use absolute path for .git root #125 --- ldcoolp/git_info.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ldcoolp/git_info.py b/ldcoolp/git_info.py index 8feb11cf..61bddf9f 100644 --- a/ldcoolp/git_info.py +++ b/ldcoolp/git_info.py @@ -1,7 +1,11 @@ from pathlib import Path +from os.path import dirname, basename +# Get git root +git_root = dirname(__file__.replace(f'/{basename(__file__)}', '')) -def get_active_branch_name(input_path="."): + +def get_active_branch_name(input_path=git_root): head_dir = Path(input_path) / ".git" / "HEAD" with head_dir.open("r") as f: @@ -12,7 +16,7 @@ def get_active_branch_name(input_path="."): return line.partition("refs/heads/")[2] -def get_latest_commit(input_path="."): +def get_latest_commit(input_path=git_root): head_dir = Path(input_path) / ".git" / "HEAD" with head_dir.open("r") as f: From e2a147373a79651504cba8bce31df9ee67b6036c Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Tue, 17 Nov 2020 13:46:42 -0700 Subject: [PATCH 2/5] git_info: Handling when .git does not exists #125 - Handle when in detached state - Fix missing full path in `get_latest_commit` --- ldcoolp/git_info.py | 46 ++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/ldcoolp/git_info.py b/ldcoolp/git_info.py index 61bddf9f..ec9ddf6e 100644 --- a/ldcoolp/git_info.py +++ b/ldcoolp/git_info.py @@ -1,31 +1,39 @@ from pathlib import Path -from os.path import dirname, basename +from os.path import dirname, basename, exists, join # Get git root git_root = dirname(__file__.replace(f'/{basename(__file__)}', '')) def get_active_branch_name(input_path=git_root): + if exists(join(input_path, ".git", "HEAD")): + head_dir = Path(input_path) / ".git" / "HEAD" + with head_dir.open("r") as f: + content = f.read().splitlines() - head_dir = Path(input_path) / ".git" / "HEAD" - with head_dir.open("r") as f: - content = f.read().splitlines() - - for line in content: - if line[0:4] == "ref:": - return line.partition("refs/heads/")[2] + for line in content: + if line[0:4] == "ref:": + return line.partition("refs/heads/")[2] + else: + return f"HEAD detached : {content}" + else: + return '.git structure does not exist' def get_latest_commit(input_path=git_root): - head_dir = Path(input_path) / ".git" / "HEAD" - with head_dir.open("r") as f: - content = f.read().splitlines() - - for line in content: - if line[0:4] == "ref:": - head_path = Path(f".git/{line.partition(' ')[2]}") - with head_path.open('r') as g: - commit = g.read().splitlines() - - return commit[0], commit[0][:7] # full and short hash + if exists(join(input_path, ".git", "HEAD")): + head_dir = Path(input_path) / ".git" / "HEAD" + with head_dir.open("r") as f: + content = f.read().splitlines() + + for line in content: + if line[0:4] == "ref:": + head_path = Path(join(input_path, f".git/{line.partition(' ')[2]}")) + with head_path.open('r') as g: + commit = g.read().splitlines() + else: + commit = content[0] + return commit[0], commit[0][:7] # full and short hash + else: + return '.git structure does not exist', '' From 65987fac57aedf2ff2d5e27e498accd19d5aa47d Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Tue, 17 Nov 2020 13:49:56 -0700 Subject: [PATCH 3/5] git_info: Minor fix for HEAD detach case #125 --- ldcoolp/git_info.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ldcoolp/git_info.py b/ldcoolp/git_info.py index ec9ddf6e..afc992d4 100644 --- a/ldcoolp/git_info.py +++ b/ldcoolp/git_info.py @@ -15,7 +15,7 @@ def get_active_branch_name(input_path=git_root): if line[0:4] == "ref:": return line.partition("refs/heads/")[2] else: - return f"HEAD detached : {content}" + return f"HEAD detached : {content[0]}" else: return '.git structure does not exist' @@ -33,7 +33,7 @@ def get_latest_commit(input_path=git_root): with head_path.open('r') as g: commit = g.read().splitlines() else: - commit = content[0] + commit = content return commit[0], commit[0][:7] # full and short hash else: return '.git structure does not exist', '' From f055dcb74aefabe35d2d67027039351eda6961de Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Tue, 17 Nov 2020 13:53:23 -0700 Subject: [PATCH 4/5] Bump version: v0.16.1 -> v0.16.2 #125 --- README.md | 2 +- ldcoolp/__init__.py | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3f810327..267abead 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ You can confirm installation via `conda list` (curation) $ conda list ldcoolp ``` -You should see that the version is `0.16.1`. +You should see that the version is `0.16.2`. ### Configuration Settings diff --git a/ldcoolp/__init__.py b/ldcoolp/__init__.py index 01d3d31f..dd021bca 100644 --- a/ldcoolp/__init__.py +++ b/ldcoolp/__init__.py @@ -1,6 +1,6 @@ from os import path -__version__ = "0.16.1" +__version__ = "0.16.2" co_path = path.dirname(__file__) diff --git a/setup.py b/setup.py index 01451c7d..f69e23c3 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setup( name='ldcoolp', - version='v0.16.1', + version='v0.16.2', packages=['ldcoolp'], url='https://github.com/ualibraries/LD_Cool_P', license='MIT License', From 71851a9b77b9acfa05e3421f1a28752af79a0dbc Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Tue, 17 Nov 2020 13:53:43 -0700 Subject: [PATCH 5/5] Update README.md changelog #125 --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 267abead..53771e5b 100644 --- a/README.md +++ b/README.md @@ -221,7 +221,8 @@ following a `git tag` version. A list of released features and their issue number(s). List is sorted from moderate to minor revisions for reach release. -v0.16.0 - v0.16.1: +v0.16.0 - v0.16.2: + * Improved handling of .git set-up in `git_info` #124, #125 * `update` method for `ReadmeClass` to enable updating README.txt file #73, #122 * `update_readme` script to enable easy revision #73 * Scripts are executable #110