Beispiel #1
0
    def test_sync_repository(self, mock_labbook_lfs_disabled):
        username = '******'
        lb = mock_labbook_lfs_disabled[2]
        bm = BranchManager(lb, username)
        assert bm.branches_remote == []
        assert bm.branches_local == ['master']

        jobs.publish_repository(lb,
                                username=username,
                                access_token='fake',
                                id_token='fake-too')

        assert os.path.exists(lb.remote)

        # Assert that publish only pushes up the master branch.
        assert bm.branches_local == ['master']
        assert bm.branches_remote == ['master']

        assert bm.get_commits_ahead('master') == 0
        assert bm.get_commits_behind('master') == 0

        lb.write_readme("do a commit")

        assert bm.get_commits_ahead('master') == 1
        assert bm.get_commits_behind('master') == 0

        jobs.sync_repository(lb,
                             username=username,
                             override=MergeOverride.OURS,
                             access_token='fake',
                             id_token='fake-too')

        assert bm.get_commits_ahead('master') == 0
        assert bm.get_commits_behind('master') == 0
Beispiel #2
0
 def resolve_commits_ahead(self, info):
     logged_in_user = get_logged_in_username()
     lb = InventoryManager().load_labbook(logged_in_user, self.owner,
                                          self.name)
     self._configure_git(lb, info)
     bm = BranchManager(lb)
     if self._fetch_loader:
         return self._fetch_loader.load(
             f"labbook&{logged_in_user}&{self.owner}&{self.name}").then(
                 lambda _: bm.get_commits_ahead(branch_name=self.branch_name
                                                ))
     else:
         return bm.get_commits_ahead(branch_name=self.branch_name)
Beispiel #3
0
 def resolve_commits_ahead(self, info):
     lb = InventoryManager().load_labbook(get_logged_in_username(),
                                          self.owner,
                                          self.name)
     self._configure_git(lb, info)
     bm = BranchManager(lb)
     return bm.get_commits_ahead(branch_name=self.branch_name)
Beispiel #4
0
    def test_count_commits_behind_remote_when_no_change(self, mock_config_file, remote_labbook_repo,
                                                        mock_labbook_lfs_disabled):
        # When the branch is up to date, ensure it doesn't report being behind.
        lb = mock_labbook_lfs_disabled[2]
        bm = BranchManager(lb, username='******')
        lb.add_remote("origin", remote_labbook_repo)
        bm.workon_branch('testing-branch')

        bm.fetch()
        behind = bm.get_commits_behind()
        ahead = bm.get_commits_ahead()
        assert ahead == 0
        assert behind == 0
Beispiel #5
0
    def test_count_commits_behind_for_local_branch(self, mock_config_file, remote_labbook_repo,
                                                   mock_labbook_lfs_disabled):
        # When we're using a local branch, by definition it is never behind.
        lb = mock_labbook_lfs_disabled[2]
        bm = BranchManager(lb, username='******')
        lb.add_remote("origin", remote_labbook_repo)
        bm.create_branch("super-local-branch")

        bm.fetch()
        behind = bm.get_commits_behind()
        ahead = bm.get_commits_ahead()

        # Should be up-to-date.
        assert ahead == 0
        assert behind == 0
Beispiel #6
0
    def test_get_commits_with_local_changes(self, mock_config_file, remote_labbook_repo,
                                            mock_labbook_lfs_disabled):
        # When the branch is up to date, ensure it doesn't report being behind.
        lb = mock_labbook_lfs_disabled[2]
        lb.add_remote("origin", remote_labbook_repo)
        bm = BranchManager(lb, username='******')
        bm.workon_branch("testing-branch")

        # Do some stuff to make commits locally
        FileOperations.makedir(lb, 'code/rand_dir', create_activity_record=True)
        FileOperations.delete_files(lb, 'code', ['rand_dir'])

        behind = bm.get_commits_behind()
        ahead = bm.get_commits_ahead()
        assert ahead == 4
        assert behind == 0
Beispiel #7
0
    def test_get_commits_with_remote_changes(self, mock_config_file,
                                             remote_labbook_repo,
                                             mock_labbook_lfs_disabled):
        # When the branch is up to date, ensure it doesn't report being behind.
        lb = mock_labbook_lfs_disabled[2]
        lb.add_remote("origin", remote_labbook_repo)
        bm = BranchManager(lb, username='******')
        bm.workon_branch("testing-branch")

        from gtmcore.inventory.inventory import InventoryManager
        remote_lb = InventoryManager(mock_config_file[0]).load_labbook_from_directory(remote_labbook_repo)
        remote_bm = BranchManager(remote_lb, 'test')
        remote_bm.workon_branch("testing-branch")
        FileOperations.makedir(remote_lb, 'code/xyzdir', create_activity_record=True)


        bm.fetch()
        behind = bm.get_commits_behind()
        ahead = bm.get_commits_ahead()
        assert ahead == 0
        assert behind == 2