Пример #1
0
    def test_checkout_branch(self):
        '''
        creates a new branch, adds a commit
        checks out back and forth
        additional file should appear,
          missing file should disappear since there are no changes on it
        '''
        file1_name, _ = self.create_file()
        add_command([file1_name])
        self.assertIndexEquals([file1_name])
        commit_command(['-m', 'first commit'])

        branch_command(['branch1'])
        self.assertBranchHEADEquals('branch1', [file1_name])
        checkout_command(['branch1'])

        file2_name, _ = self.create_file()
        add_command([file2_name])
        self.assertIndexEquals([file1_name, file2_name])
        commit_command(['-m', 'second commit'])
        self.assertBranchHEADEquals('branch1', [file1_name, file2_name])

        checkout_command(['master'])
        self.assertIndexEquals([file1_name])
        self.assertFilesEqual([file1_name])

        checkout_command(['branch1'])
        self.assertIndexEquals([file1_name, file2_name])
        self.assertFilesEqual([file1_name, file2_name])
Пример #2
0
    def test_add_remove(self):
        file1_name, _ = self.create_file()
        add_command([file1_name])
        self.assertIndexEquals([file1_name])

        file2_name, _ = self.create_file()
        add_command([file2_name])
        self.assertIndexEquals([file1_name, file2_name])

        rm_command([file1_name])
        self.assertIndexEquals([file2_name])
Пример #3
0
    def test_checkout(self):
        '''
        Commits, then checks out HEAD~1
        '''
        file1_name, _ = self.create_file()
        add_command([file1_name])
        self.assertIndexEquals([file1_name])
        commit_command(['-m', 'first commit'])

        file2_name, _ = self.create_file()
        add_command([file2_name])
        self.assertIndexEquals([file1_name, file2_name])
        commit_command(['-m', 'second commit'])
        self.assertBranchHEADEquals('master', [file1_name, file2_name])

        checkout_command(['HEAD~1'])
        self.assertIndexEquals([file1_name])
Пример #4
0
    def test_status(self):
        removed_file_name, _ = self.create_file('removed_file.txt')
        add_command([removed_file_name])
        self.assertIndexEquals([removed_file_name])
        commit_command(['-m', 'first commit'])

        modified_fs_removed_file_name, _ = self.create_file(
            'modified_fs_removed_file.txt')
        add_command([modified_fs_removed_file_name])
        self.assertIndexEquals(
            [removed_file_name, modified_fs_removed_file_name])
        commit_command(['-m', 'second commit'])
        self.assertBranchHEADEquals(
            'master', [removed_file_name, modified_fs_removed_file_name])

        # staging differences
        # added file
        added_fs_modified_file_name, _ = self.create_file(
            'added_fs_modified_file.txt')
        add_command([added_fs_modified_file_name])

        # removed file
        rm_command([removed_file_name])

        # modify file
        self.modify_file(modified_fs_removed_file_name)
        add_command([modified_fs_removed_file_name])

        # file system differences

        # fs added file
        fs_added_file_name, _ = self.create_file('fs_added_file.txt')

        # fs removed file
        os.remove(modified_fs_removed_file_name)

        # fs modified_file
        self.modify_file(added_fs_modified_file_name)

        ((removed_files, changed_files, new_files),
         (fs_removed_files, fs_changed_files,
          fs_new_files)) = status_command([])

        self.assertEquals(removed_files, [removed_file_name])
        self.assertEquals(changed_files, [modified_fs_removed_file_name])
        self.assertEquals(new_files, [added_fs_modified_file_name])

        self.assertEquals(fs_removed_files, [modified_fs_removed_file_name])
        self.assertEquals(fs_changed_files, [added_fs_modified_file_name])
        self.assertEquals(fs_new_files, [fs_added_file_name])