Skip to content

Commit 4ec3dac

Browse files
authored
fix(penify_hook): handle git ancestor detection (#28)
* 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. * chore: Increment version number in setup.py
1 parent 644f7ae commit 4ec3dac

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

penify_hook/main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import urllib.parse
1111
from threading import Thread
1212

13+
from penify_hook.utils import find_git_parent
14+
1315
from .commit_analyzer import CommitDocGenHook
1416
from .folder_analyzer import FolderAnalyzerGenHook
1517
from .file_analyzer import FileAnalyzerGenHook
@@ -287,6 +289,7 @@ def main():
287289
print("Error: API token is required. Please provide it using -t option, PENIFY_API_TOKEN environment variable, or log in first.")
288290
sys.exit(1)
289291
open_terminal = args.terminal.lower() == "true"
292+
args.git_folder_path = find_git_parent(args.git_folder_path)
290293
commit_code(args.git_folder_path, token, args.message, open_terminal)
291294
elif args.subcommand == "login":
292295
login()

penify_hook/utils.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import os
2+
3+
class GitRepoNotFoundError(Exception):
4+
pass
5+
6+
def find_git_parent(path):
7+
current_dir = os.path.abspath(path)
8+
9+
while current_dir != os.path.dirname(current_dir): # Traverse up to the root directory
10+
if os.path.isdir(os.path.join(current_dir, ".git")):
11+
return current_dir # Return the parent folder containing the .git directory
12+
current_dir = os.path.dirname(current_dir)
13+
14+
raise GitRepoNotFoundError(f"No Git repository found in the path or any of its parent directories: {path}")

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name="penify-cli",
5-
version="0.1.4", # Increment the version number
5+
version="0.1.5", # Increment the version number
66
packages=['penify_hook'], # Explicitly include the penify_hook package
77
install_requires=[
88
"requests",

0 commit comments

Comments
 (0)