From fe3f22427bc1f8a5ba763b745c4b9874fd9e559f Mon Sep 17 00:00:00 2001 From: sumansaurabh Date: Mon, 21 Oct 2024 08:32:09 +0530 Subject: [PATCH 1/2] fix(penify_hook): handle git ancestor detection This update introduces a fix for the issue where the application would throw an error if the selected folder did not contain a .git directory, but its ancestor did. The `find_git_parent` function has been added to the `utils.py` module to traverse up the directory tree and locate the nearest .git folder. This enhancement ensures that the application can correctly identify the Git repository in parent directories, improving usability and preventing runtime errors related to Git operations. --- penify_hook/main.py | 3 +++ penify_hook/utils.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 penify_hook/utils.py diff --git a/penify_hook/main.py b/penify_hook/main.py index b8903d5..8395757 100644 --- a/penify_hook/main.py +++ b/penify_hook/main.py @@ -10,6 +10,8 @@ import urllib.parse from threading import Thread +from penify_hook.utils import find_git_parent + from .commit_analyzer import CommitDocGenHook from .folder_analyzer import FolderAnalyzerGenHook from .file_analyzer import FileAnalyzerGenHook @@ -287,6 +289,7 @@ def main(): print("Error: API token is required. Please provide it using -t option, PENIFY_API_TOKEN environment variable, or log in first.") sys.exit(1) open_terminal = args.terminal.lower() == "true" + args.git_folder_path = find_git_parent(args.git_folder_path) commit_code(args.git_folder_path, token, args.message, open_terminal) elif args.subcommand == "login": login() diff --git a/penify_hook/utils.py b/penify_hook/utils.py new file mode 100644 index 0000000..2263f1e --- /dev/null +++ b/penify_hook/utils.py @@ -0,0 +1,14 @@ +import os + +class GitRepoNotFoundError(Exception): + pass + +def find_git_parent(path): + current_dir = os.path.abspath(path) + + while current_dir != os.path.dirname(current_dir): # Traverse up to the root directory + if os.path.isdir(os.path.join(current_dir, ".git")): + return current_dir # Return the parent folder containing the .git directory + current_dir = os.path.dirname(current_dir) + + raise GitRepoNotFoundError(f"No Git repository found in the path or any of its parent directories: {path}") From e5f76eeef49d041253e3fbbb0839cc8e19342e86 Mon Sep 17 00:00:00 2001 From: sumansaurabh Date: Mon, 21 Oct 2024 08:35:04 +0530 Subject: [PATCH 2/2] chore: Increment version number in setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 88725f6..b586b09 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name="penify-cli", - version="0.1.4", # Increment the version number + version="0.1.5", # Increment the version number packages=['penify_hook'], # Explicitly include the penify_hook package install_requires=[ "requests",