def set_current_branch_name(self, name): self.load_config() self.config['info']['current_branch'] = name branch = Branch.make_branch_from_config(name) commit = branch.get_current_commit() if commit is None: self.config['info']['last_commit'] = '' else: self.config['info']['last_commit'] = commit.commit_number self.save_config()
def add_commit(self, commit): """Adds new commit to last branch, copying files""" di = DirectoryInfo() self.load_config() for file in commit.files_with_copying_paths: path = commit.files_with_copying_paths[file] commits_path = di.get_commits_path(self.__current_branch_name) commit_path = os.path.join(commits_path, commit.commit_number) if not os.path.exists(commit_path): os.makedirs(commit_path) copy_path = os.path.join(commit_path, file) copyfile(path, copy_path) file_hash = commit.files_hashes[file] print(f'File {file} saved - {file_hash}') commit.set_previous_commit_number(self.last_commit_number) self.last_commit_number = commit.commit_number self.config['info']['last_commit'] = commit.commit_number branch = Branch.make_branch_from_config(self.__current_branch_name) branch.set_current_commit(commit) self.save_config()
def make_commit(self, commit_message, branch_name) -> Commit: """ Makes commit, freezing current files state :returns Commit """ self.load_config() commit = Commit(commit_message) commit.branch_name = branch_name commit.init_config() branch = Branch.make_branch_from_config(branch_name) prev_commit = branch.get_current_commit() if prev_commit is not None: commit_number = prev_commit.commit_number commit.set_previous_commit_number(commit_number) commit.freeze_files(self.__indexed_files, self.__directory) self.__last_commit = commit self.config['info']['files'] = '' self.config['info']['last_commit'] = commit.commit_number self.config['info']['last_commit_branch'] = commit.branch_name self.save_config() return commit
def diff(self, filename, first_version, second_version): branch_name = self.repository.current_branch.name branch = Branch.make_branch_from_config(branch_name) branch.diff(filename, first_version, second_version)
def update(self, filename, version): """Updates file with a specific version from repository""" branch_name = self.repository.current_branch.name branch = Branch.make_branch_from_config(branch_name) branch.update(filename, version)
def current_branch(self): self.load_config() branch = Branch.make_branch_from_config(self.__current_branch_name) return branch