def execute(self, args, path: Path): args = _parse_args(args) if not contains_repository_at(path): print(f'No repository at {path.root}') return con = StageController(path) for file in args.file: if not path.exists(file): print(f'No that file or directory: {file}') con.add(file, report=True) con.write()
def execute(self, args, path: Path): if not contains_repository_at(path): print(f'There is no repository at {path.root}') return src, dst, file = _parse_args(args) provider = Provider(path) storage = StorageController(path) if not provider.is_commit(src) or not provider.is_commit(dst): print('Invalid commit id') return differ = Differ() diffs = differ.get_commit_diffs(provider.get_commit(src), provider.get_commit(dst), storage) if file is not None: print(f'Diffs at file {file}:') for d in diffs: if path.relpath(d.name) != normpath(file): continue if d.state == State.DELETED: print('File was deleted') elif d.state == State.NOT_CHANGED: print('File didnt changed') else: d.print() break else: def print_(t, p, m): l = list(filter(lambda x: x.state == t, p)) if len(l) == 0: return print(m) for d in l: print(d.name) print_(State.DELETED, diffs, 'Deleted files') print_(State.NEW, diffs, 'New files') print_(State.MODIFIED, diffs, 'Modified files')
def initialize_repository_at(path: Path): if path.isdir(CONFIG_DIR): shutil.rmtree(path.combine(CONFIG_DIR)) path.mkdir(COMMITS_DIR) path.mkdir(BRANCHES_DIR) path.mkdir(STORAGE_PATH) provider = Provider(path) commit = Commit( About(Author('N\\A', 'N\\A'), datetime.datetime.now(), 'lgit auto initialization commit'), 0, -1, {}) master = Branch('master', 0) provider.save_new(commit) provider.save_new(master) provider.set_current_branch('master')
def get_changes_from_commit(self, commit: Commit, storage: StorageController, path: Path): file_to_status = {} current_files = path.get_all_files(ignore_config_dir=True) for file in current_files: if not commit.contains_file(file): file_to_status[file] = State.NEW continue id_ = commit.get_file_storage_name(file) if self.is_file_differs(file, storage.get_path_of(id_)): file_to_status[file] = State.MODIFIED else: file_to_status[file] = State.NOT_CHANGED for cf in commit.file_to_storage_name.keys(): if cf not in current_files: file_to_status[cf] = State.DELETED return file_to_status
def test_combine__should_return_path_joined_to_root(self): path = Path("root/shmoot") sut = path.combine("lol") self.assertEquals(sut, "root/shmoot/lol")
def test_sub__should_return_path_with_combined_root(self): path = Path("root/soos") sut = path.sub("subdir") self.assertEquals(sut.root, "root/soos/subdir")
def test_path__should_return_root_path(self): path = Path("root") sut = path.root self.assertEquals(sut, "root")
def __init__(self, repository_path: Path): self.__repository_path = repository_path self.__commit_provider = CommitProvider( repository_path.sub(COMMITS_DIR)) self.__branch_provider = BranchProvider( repository_path.sub(BRANCHES_DIR))
def contains_repository_at(path: Path): return path.isdir(COMMITS_DIR) and\ path.isdir(BRANCHES_DIR) and\ path.isdir(STORAGE_PATH) and\ path.isfile(CURRENT_BRANCH_FILE)
def __init__(self, repository_path: Path): self.__repository_path = repository_path self.__storage_path = repository_path.sub(STORAGE_PATH)