Skip to content

Commit

Permalink
Committing no longer fails when a module's input file is removed
Browse files Browse the repository at this point in the history
  • Loading branch information
jakub-nt committed Sep 16, 2024
1 parent aedd838 commit 9e3c854
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
9 changes: 5 additions & 4 deletions cfbs/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import tempfile
from subprocess import check_call, check_output, run, PIPE, DEVNULL, CalledProcessError

from cfbs.utils import are_paths_equal


class CFBSGitError(Exception):
pass
Expand Down Expand Up @@ -199,10 +201,9 @@ def git_check_tracked_changes(scope=["all"]):
lines = result.stdout.decode("utf-8").split("\n")
changes = [line.strip().split(" ")[1] for line in lines if line]
should_commit = any(
map(
lambda x: os.path.samefile(*x),
list(itertools.product(changes, scope)),
)
# paths given in `git status` are of different form than the paths we use
are_paths_equal(p[0], p[1])
for p in itertools.product(changes, scope)
)
if not should_commit:
print("No changes to commit")
Expand Down
11 changes: 11 additions & 0 deletions cfbs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,17 @@ def path_append(dir, subdir):
return dir if not subdir else os.path.join(dir, subdir)


def canonical_path(path):
return os.path.normcase(os.path.realpath(path))


def are_paths_equal(path_a, path_b) -> bool:
canon_path_a = canonical_path(path_a)
canon_path_b = canonical_path(path_b)

return canon_path_a == canon_path_b


def cfengine_dir(subdir=None):
return path_append("~/.cfengine/", subdir)

Expand Down

0 comments on commit 9e3c854

Please sign in to comment.