Replace os.path.join with join_path
So that we use '/' on Windows
This commit is contained in:
		
							
								
								
									
										25
									
								
								libwyag.py
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								libwyag.py
									
									
									
									
									
								
							| @@ -10,6 +10,11 @@ import re | ||||
| import sys | ||||
| import zlib | ||||
|  | ||||
| def join_path(first, *rest): | ||||
|     if (first == ""): | ||||
|         return "/".join(list(rest)) | ||||
|     return "/".join([first] + list(rest)) | ||||
|  | ||||
| argparser = argparse.ArgumentParser(description="The stupidest content tracker") | ||||
|  | ||||
| argsubparsers = argparser.add_subparsers(title="Commands", dest="command") | ||||
| @@ -44,7 +49,7 @@ class GitRepository (object): | ||||
|  | ||||
|     def __init__(self, path, force=False): | ||||
|         self.worktree = path | ||||
|         self.gitdir = os.path.join(path, ".git") | ||||
|         self.gitdir = join_path(path, ".git") | ||||
|  | ||||
|         if not (force or os.path.isdir(self.gitdir)): | ||||
|             raise Exception(f"Not a git repository {path}") | ||||
| @@ -65,7 +70,7 @@ class GitRepository (object): | ||||
|  | ||||
|     def repo_path(repo, *path): | ||||
|         """Compute path under repo's gitdir.""" | ||||
|         return os.path.join(repo.gitdir, *path) | ||||
|         return join_path(repo.gitdir, *path) | ||||
|  | ||||
|     def repo_file(repo, *path, mkdir=False): | ||||
|         """Same as repo_path, but create dirname(*path) if absent. For | ||||
| @@ -150,11 +155,11 @@ def cmd_init(args): | ||||
| def repo_find(path=".", required=True): | ||||
|     path = os.path.realpath(path) | ||||
|  | ||||
|     if os.path.isdir(os.path.join(path, ".git")): | ||||
|     if os.path.isdir(join_path(path, ".git")): | ||||
|         return GitRepository(path) | ||||
|  | ||||
|     # If we haven't returned, recurse in parent | ||||
|     parent = os.path.realpath(os.path.join(path, "..")) | ||||
|     parent = os.path.realpath(join_path(path, "..")) | ||||
|  | ||||
|     match os.name: | ||||
|         case "nt": | ||||
| @@ -589,10 +594,10 @@ def ls_tree(repo, ref, recursive=None, prefix=""): | ||||
|                 # of the object pointed to. | ||||
|                 type, | ||||
|                 item.sha, | ||||
|                 os.path.join(prefix, item.path) | ||||
|                 join_path(prefix, item.path) | ||||
|             )) | ||||
|         else: # This is a branch (vs. leaf), recurse | ||||
|             ls_tree(repo, item.sha, recursive, os.path.join(prefix, item.path)) | ||||
|             ls_tree(repo, item.sha, recursive, join_path(prefix, item.path)) | ||||
|  | ||||
| argsp = argsubparsers.add_parser("checkout", help="Checkout a commit inside of a directory.") | ||||
|  | ||||
| @@ -625,7 +630,7 @@ def cmd_checkout(args): | ||||
| def tree_checkout(repo, tree, path): | ||||
|     for item in tree.items: | ||||
|         obj = object_read(repo, item.sha) | ||||
|         dest = os.path.join(path, item.path) | ||||
|         dest = join_path(path, item.path) | ||||
|  | ||||
|         if obj.fmt == b'tree': | ||||
|             os.mkdir(dest) | ||||
| @@ -661,7 +666,7 @@ def ref_list(repo, path=None): | ||||
|     ret = collections.OrderedDict() | ||||
|  | ||||
|     for f in sorted(os.listdir(path)): | ||||
|         can = os.path.join(path, f) | ||||
|         can = join_path(path, f) | ||||
|         if os.path.isdir(can): | ||||
|             ret[f] = ref_list(repo, can) | ||||
|         else: | ||||
| @@ -1001,7 +1006,7 @@ def gitignore_read(repo): | ||||
|     ret = GitIgnore(absolute=list(), scoped=dict()) | ||||
|  | ||||
|     # Read local configuration | ||||
|     repo_file = os.path.join(repo.gitdir, "info/exclude") | ||||
|     repo_file = join_path(repo.gitdir, "info/exclude") | ||||
|     if os.path.exists(repo_file): | ||||
|         with open(repo_file, "r") as f: | ||||
|             ret.absolute.append(gitignore_parse(f.readlines())) | ||||
| @@ -1011,7 +1016,7 @@ def gitignore_read(repo): | ||||
|         config_home == os.environ["XDG_CONFIG_HOME"] | ||||
|     else: | ||||
|         config_home = os.path.expanduser("~/.config") | ||||
|     global_file = os.path.join(config_home, "git/ignore") | ||||
|     global_file = join_path(config_home, "git/ignore") | ||||
|  | ||||
|     if os.path.exists(global_file): | ||||
|         with open(global_file, "r") as f: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user