Exemplo n.º 1
0
 def setUp(self) -> None:
     self.commit = Commit("NONE")
     self.wd = WorkingDirectory()
     self.di = DirectoryInfo()
     path = os.getcwd()
     self.di.init(path)
     self.file_path = os.path.join(self.di.working_path, 'TESTING.txt')
     with open(self.file_path, "w+") as file:
         file.write('SOME STRING')
Exemplo n.º 2
0
 def test_reset_should_reset_to_head_commit(self):
     head = Head()
     head.init_config()
     branch = Branch('master')
     branch.init_config()
     head.current_branch = branch
     commit = Commit('test')
     commit.branch_name = 'master'
     commit.init_config()
     head.current_branch.set_current_commit(commit)
     self.index.reset(head)
     self.assertEqual(self.index.last_commit.commit_number,
                      commit.commit_number)
Exemplo n.º 3
0
 def get_commit_history(self):
     self.load_config()
     print(f'Commit history for branch: {self.__current_branch_name}')
     if self.last_commit_number != '':
         commit = Commit.make_commit_from_config(self.last_commit_number,
                                                 self.__current_branch_name)
         commit.print_info()
     else:
         print('No commits found!')
Exemplo n.º 4
0
 def get_current_commit(self):
     """
     Returns current commit
     :returns current commit
     """
     self.load_config()
     if self.current_commit_number == '':
         return None
     commit = Commit.make_commit_from_config(self.current_commit_number,
                                             self.name)
     return commit
Exemplo n.º 5
0
 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
Exemplo n.º 6
0
    def get_data_from_config(self, config_path):
        config = configparser.ConfigParser()
        config.read(config_path)
        config.optionxform = str

        prev_commit_number = self.config['info']['last_commit']
        prev_commit_branch = self.config['info']['last_commit_branch']
        if prev_commit_number != 'None':
            commit = Commit.make_commit_from_config(prev_commit_number,
                                                    prev_commit_branch)
        else:
            commit = 'None'
        self.__last_commit = commit
        files = config['info']['files']
        if files != '':
            self.__indexed_files = set(files.split(','))
Exemplo n.º 7
0
class TestCommit(unittest.TestCase):
    def setUp(self) -> None:
        self.commit = Commit("NONE")
        self.wd = WorkingDirectory()
        self.di = DirectoryInfo()
        path = os.getcwd()
        self.di.init(path)
        self.file_path = os.path.join(self.di.working_path, 'TESTING.txt')
        with open(self.file_path, "w+") as file:
            file.write('SOME STRING')

    def tearDown(self) -> None:
        if os.path.exists(self.di.cvs_path):
            shutil.rmtree(self.di.cvs_path)
        if os.path.exists(self.file_path):
            os.remove(self.file_path)

    def test_freeze_files_should_remember_copy_path_of_indexed_files(self):
        index = Index()
        index.init_config()
        index.set_directory_info(self.di)
        index.add_new_file('TESTING.txt')
        self.commit.branch_name = 'master'
        self.commit.init_config()
        self.commit.freeze_files(index.indexed_files, self.di)
        keys = self.commit.files_with_copying_paths.keys()
        self.assertTrue('TESTING.txt' in keys)

    def test_freeze_files_should_make_hash_from_indexed_files(self):
        index = Index()
        index.init_config()
        index.set_directory_info(self.di)
        index.add_new_file('TESTING.txt')
        self.commit.branch_name = 'master'
        self.commit.init_config()
        self.commit.freeze_files(index.indexed_files, self.di)
        keys = self.commit.files_hashes.keys()
        self.assertTrue('TESTING.txt' in keys)

    def test_commit_number_should_return_unique_commit_number(self):
        first_number = self.commit.commit_number
        other_commit = Commit("Other")
        second_number = other_commit.commit_number
        self.assertNotEqual(first_number, second_number)
Exemplo n.º 8
0
 def test_commit_number_should_return_unique_commit_number(self):
     first_number = self.commit.commit_number
     other_commit = Commit("Other")
     second_number = other_commit.commit_number
     self.assertNotEqual(first_number, second_number)
Exemplo n.º 9
0
 def test_reset_should_move_head_to_previous_commit(self):
     di = DirectoryInfo()
     di.init(os.getcwd())
     head = Head()
     head.init_config()
     branch = Branch('master')
     branch.init_config()
     head.current_branch = branch
     commit = Commit('first')
     commit.branch_name = 'master'
     commit.init_config()
     prev_commit = Commit('second')
     prev_commit.branch_name = 'master'
     prev_commit.init_config()
     commit.set_previous_commit_number(prev_commit.commit_number)
     previous_commit_number = commit.get_previous_commit_number()
     head.current_branch.set_current_commit(commit)
     head.reset()
     current_commit = head.current_branch.get_current_commit()
     self.assertEqual(current_commit.commit_number, previous_commit_number)