def test_remove_remote_branch(self, mock_labbook_lfs_disabled): lb = mock_labbook_lfs_disabled[2] with tempfile.TemporaryDirectory() as tempdir: call_subprocess('git init .'.split(), tempdir) call_subprocess('touch FILE_A'.split(), tempdir) call_subprocess('git add FILE_A'.split(), tempdir) call_subprocess('git commit -am "message"'.split(), tempdir) call_subprocess('git checkout -b remote-branch'.split(), cwd=tempdir) call_subprocess('git checkout master'.split(), cwd=tempdir) lb.git.add_remote('origin', tempdir) bm = BranchManager(lb) bm.fetch() assert 'remote-branch' in bm.branches_remote # Get this remote branch locally, but go back to master bm.workon_branch('remote-branch') call_subprocess('git checkout master'.split(), cwd=bm.repository.root_dir) bm.remove_remote_branch('remote-branch') bm.fetch() # Confirm branch exists locally, but is gone on remote. assert 'remote-branch' in bm.branches_local assert 'remote-branch' not in bm.branches_remote
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
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
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
def helper_resolve_commits_behind(self, dataset): """Helper to get the commits behind for a dataset. Used for linked datasets to see if they are out of date""" bm = BranchManager(dataset) bm.fetch() return bm.get_commits_behind(branch_name='master')