def status(): if is_father_dir_exist('.wit') is False: return wit_dir_path = get_folder_path('.wit') data_to_copy_path = pathlib.Path(wit_dir_path).parent commit_id = get_commit_id(wit_dir_path) if commit_id is None: logging.error('There was no commit yet. exiting program..') return staging_area_path = wit_dir_path + '\\staging_area' commit_id_path = wit_dir_path + '\\images\\' + commit_id files = [] changes_to_be_commited = get_files_to_be_commited(staging_area_path, commit_id_path, files.copy()) changes_not_staged_for_commit = get_changes_not_staged_for_commit(staging_area_path, data_to_copy_path, files.copy()) untracked_files = get_untraecked_files(data_to_copy_path, staging_area_path, files.copy()) print_status(commit_id, changes_to_be_commited, changes_not_staged_for_commit, untracked_files) return changes_to_be_commited, changes_not_staged_for_commit
def is_ok_for_checkout(): """return False if 1.There are changes to be commited. 2.There are changes not staged for commit. this function prevent to do checkout in situations that might lead to information loss. return True otherwise. """ wit_dir_path = get_folder_path('.wit') data_to_copy_path = pathlib.Path(wit_dir_path).parent commit_id = get_commit_id(wit_dir_path) if commit_id is None: logging.error('There was no commit yet. exiting program..') return staging_area_path = wit_dir_path + '\\staging_area' commit_id_path = wit_dir_path + '\\images\\' + commit_id files = [] changes_to_be_commited = get_files_to_be_commited(staging_area_path, commit_id_path, files.copy()) changes_not_staged_for_commit = get_changes_not_staged_for_commit(staging_area_path, data_to_copy_path, files.copy()) return len(changes_to_be_commited) == 0 and len(changes_not_staged_for_commit) == 0
def add_name_to_ref_file(wit_dir_path: str, branch_name: str) -> None: ref_file_path = os.path.join(wit_dir_path, 'references.txt') cur_commit_id = get_commit_id(wit_dir_path) content = branch_name + '=' + cur_commit_id + '\n' with open(ref_file_path, 'a') as ref_file: ref_file.write(content) logging.info('%s was added to references file.', branch_name)
def get_common_base(branch_name: str) -> str: head_commit_id = get_commit_id(wit_dir_path) branch_commit_id = get_branch_commit_id(branch_name) head_index = head_commit_id branch_index = branch_commit_id while branch_index != None: if head_index == branch_index: return head_index else:
def checkout(parameter: str): COMMIT_ID_LENGTH = 40 if is_father_dir_exist('.wit') is False: return if is_ok_for_checkout() is False: logging.error(""" There are changes to be commited or there are changes_staged_for commit, checkout failed""") return wit_dir_path = get_folder_path('.wit') if parameter == 'master': parameter = get_commit_id(wit_dir_path) if len(parameter) == COMMIT_ID_LENGTH: # checkout commit_id update_head(wit_dir_path, parameter) erase_activated_file(wit_dir_path) else: # checkout branch_name if is_branch_name_exist(parameter): write_to_activated_file(parameter) # update_head(wit_dir_path, parameter) # branch_commit_id = get_commit_id_from_activated_branch() # if branch_commit_id != None: else: print('%s does not appear in references file.', parameter) temp = get_commit_id_from_activated_branch() if temp != None: parameter = temp update_original_dir_wit_according_to_checkout(wit_dir_path, parameter) change_staging_area_content(wit_dir_path, parameter) activated_branch_name = get_activated_branch_name() if activated_branch_name is None: logging.info('There is no activated branch right now.') return
def graph(): if is_father_dir_exist('.wit') is False: return wit_dir_path = get_folder_path('.wit') cur_commit_id = get_commit_id(wit_dir_path) master_id = get_master_id(wit_dir_path) parent_commit_id = get_parent_commit_id(wit_dir_path, cur_commit_id) if cur_commit_id is None: logging.info('There was no commit yet.') return draw_graph(cur_commit_id, master_id, parent_commit_id)