diff --git a/cfbs/git.py b/cfbs/git.py index f8a71d8..f0d7fcc 100644 --- a/cfbs/git.py +++ b/cfbs/git.py @@ -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 @@ -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") diff --git a/cfbs/utils.py b/cfbs/utils.py index b255083..74b329c 100644 --- a/cfbs/utils.py +++ b/cfbs/utils.py @@ -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)