Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion libtft.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,35 @@ def repo_create(path):
config = repo_default_config()
config.write(f)

return repo
return repo

def take_parent_dir(path):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the recursive solution suggested by the guide. You also mentioned this is not working for all paths.
Readability >>>

for i in range(len(path) -1, -1, -1):
if path[i] == "/":
break

if i == 0:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is "i" present after the for loops? It seems not. How is this working?

if path == "/":
return None
# when we have "/*"
return "/"

return path[:i]

def repo_find(path = ".", force=True):
if path == ".":
path = os.path.realpath(path)

if os.path.isdir(path + "/.git"):
return GitRepository(path)

parent = take_parent_dir(path)

if parent:
# parent exists
return repo_find(parent, force)

if force:
raise Exception("No git directory.")

return None