def testActionDiff(self): temp_dir = 'test_diff_command_git_repo_dir' git = r'C:\D\bin\git\bin\git.exe' if not os.path.exists(git): git = 'git' self.git = git # Test diffing with new folder structure subprocess.call([git] + 'init test_diff_command_git_repo_dir'.split(), cwd='.') os.mkdir(os.path.join(temp_dir, 'folder1')) with open(os.path.join(temp_dir, 'folder1', 'out.txt'), 'w') as f: f.write('out') called = self.CallDiff() self.assertEqual(['winmergeu.exe'], called) # Test diffing with previous version of HEAD without changes subprocess.call([git] + 'add -A'.split(), cwd=temp_dir) subprocess.call([git] + 'commit -m "Second'.split(), cwd=temp_dir) called = self.CallDiff() self.assertEqual([], called) #Not called as we don't have any changes. # Test diffing with previous version of HEAD^ def CheckStructure(): prev = os.path.join('.mu.diff.git.tmp', 'REPO', 'test_diff_command_git_repo_dir', 'folder1', 'out.txt') curr = os.path.join('.mu.diff.git.tmp', 'WORKING', 'test_diff_command_git_repo_dir', 'folder1', 'out.txt') self.assert_(os.path.exists(prev)) self.assert_(os.path.exists(curr)) Print('prev', open(prev, 'r').read()) Print('curr', open(curr, 'r').read()) with open(os.path.join(temp_dir, 'folder1', 'out.txt'), 'w') as f: f.write('new out') subprocess.call([git] + 'add -A'.split(), cwd=temp_dir) subprocess.call([git] + 'commit -m "Second'.split(), cwd=temp_dir) called = self.CallDiff('HEAD^', check_structure=CheckStructure) self.assertEqual(['winmergeu.exe'], called) # Test diffing dir structure in git changed for file in working dir subprocess.call([git] + 'add -A'.split(), cwd=temp_dir) subprocess.call([git] + 'commit -m "Third'.split(), cwd=temp_dir) RmTree(os.path.join(temp_dir, 'folder1')) with open(os.path.join(temp_dir, 'folder1'), 'w') as f: f.write('folder1 is now file.') called = self.CallDiff() self.assertEqual(['winmergeu.exe'], called) # Do mu st/mu up just to check if it works. from mu_repo.action_default import Run config = Config(repos=[temp_dir], git=git) Run(Params(config, ['st'], config_file=None)) import mu_repo mu_repo.main(config_file=None, args=['up'])
def test_action_diff(): temp_dir = 'test_diff_command_git_repo_dir' # Test diffing with new folder structure subprocess.call([git, 'init', temp_dir], cwd='.') configure_git_user(cwd=temp_dir) os.mkdir(os.path.join(temp_dir, 'folder1')) with open(os.path.join(temp_dir, 'folder1', 'out.txt'), 'w') as f: f.write('out') called = _call_diff() if sys.platform.startswith('win'): merge_command = 'winmergeu.exe' else: merge_command = 'meld' assert [merge_command] == called # Test diffing with previous version of HEAD without changes subprocess.check_call([git] + 'add -A'.split(), cwd=temp_dir) subprocess.check_call([git] + 'commit -m "Second'.split(), cwd=temp_dir) called = _call_diff() assert [] == called # Not called as we don't have any changes. # Test diffing with previous version of HEAD~1 def check_structure(): prev = os.path.join('.mu.diff.git.tmp', 'REPO', 'test_diff_command_git_repo_dir', 'folder1', 'out.txt') curr = os.path.join('.mu.diff.git.tmp', 'WORKING', 'test_diff_command_git_repo_dir', 'folder1', 'out.txt') assert os.path.exists(prev) assert os.path.exists(curr) Print('prev', open(prev, 'r').read()) Print('curr', open(curr, 'r').read()) with open(os.path.join(temp_dir, 'folder1', 'out.txt'), 'w') as f: f.write('new out') subprocess.check_call([git] + 'add -A'.split(), cwd=temp_dir) subprocess.check_call([git] + 'commit -m "Second'.split(), cwd=temp_dir) called = _call_diff('HEAD~1', check_structure=check_structure) assert [merge_command] == called # Test diffing dir structure in git changed for file in working dir # Nothing changed at this point: newest git now gives a non-zero value in # such a case if we try to commit. # subprocess.check_call([git] + 'add -A'.split(), cwd=temp_dir) # subprocess.check_call([git] + 'commit -m "Third'.split(), cwd=temp_dir) RmTree(os.path.join(temp_dir, 'folder1')) with open(os.path.join(temp_dir, 'folder1'), 'w') as f: f.write('folder1 is now file.') called = _call_diff() assert [merge_command] == called # Do mu st/mu up just to check if it works. from mu_repo.action_default import Run config = Config(repos=[temp_dir], git=git) Run(Params(config, ['st'], config_file=None)) import mu_repo mu_repo.main(config_file=None, args=['up'])
def test_serial(): status = mu_repo.main(config_file='.bar_file', args=['set-var', 'serial=1']) assert status.succeeded status = mu_repo.main(config_file='.bar_file', args=['get-vars']) assert status.config.serial status = mu_repo.main(config_file='.bar_file', args=['set-var', 'serial=0']) assert status.succeeded status = mu_repo.main(config_file='.bar_file', args=['get-vars']) assert not status.config.serial
def testSerial(self): status = mu_repo.main(config_file='.bar_file', args=['set-var', 'serial=1']) self.assert_(status.succeeded) status = mu_repo.main(config_file='.bar_file', args=['get-vars']) self.assert_(status.config.serial) status = mu_repo.main(config_file='.bar_file', args=['set-var', 'serial=0']) self.assert_(status.succeeded) status = mu_repo.main(config_file='.bar_file', args=['get-vars']) self.assert_(not status.config.serial)
def testRegister(self): status = mu_repo.main(config_file='.bar_file', args=[]) self.assert_(not status.succeeded, status.status_message) status = mu_repo.main(config_file='.bar_file', args=['register', 'pydev']) self.assert_(status.succeeded) status = mu_repo.main(config_file='.bar_file', args=['list']) self.assertEquals(status.config.repos, ['pydev']) status = mu_repo.main(config_file='.bar_file', args=['register', 'a', 'b']) self.assert_(status.succeeded) status = mu_repo.main(config_file='.bar_file', args=['list']) self.assertEquals(status.config.repos, ['a', 'b', 'pydev'])
def test_register(): status = mu_repo.main(config_file='.bar_file', args=[]) assert not status.succeeded, status.status_message status = mu_repo.main(config_file='.bar_file', args=['register', 'pydev']) assert status.succeeded status = mu_repo.main(config_file='.bar_file', args=['list']) assert status.config.repos == ['pydev'] status = mu_repo.main(config_file='.bar_file', args=['register', 'a', 'b']) assert status.succeeded status = mu_repo.main(config_file='.bar_file', args=['list']) assert status.config.repos == ['a', 'b', 'pydev']
def test_direct_symlink(workdir): """Linking directly to a repository inside of initial search path""" paths = set_up(workdir) os.symlink(paths['repo1'], paths['link1']) with push_dir('projectA'): status = mu_repo.main(config_file='.bar_file', args=['register', '--recursive']) assert status.succeeded assert status.config.repos == ['sectionX/repo1']
def test_search_path_expansion(workdir): """Linking to a repository outside of initial search path""" paths = set_up(workdir) os.symlink(paths['repo2'], paths['link1']) with push_dir('projectA'): status = mu_repo.main(config_file='.bar_file', args=['register', '--recursive']) assert status.succeeded assert set(status.config.repos) == set(['sectionX/repo1', '../projectB/sectionY/repo2'])
def test_infinite_cycle(workdir): """Linking to own ancestor directory""" paths = set_up(workdir) os.symlink(paths['dir1'], paths['link1']) with push_dir('projectA'): status = mu_repo.main(config_file='.bar_file', args=['register', '--recursive']) assert status.succeeded assert status.config.repos == ['sectionX/repo1']
def test_infinite_cycle_ouside(workdir): """Linking to own ancestor directory in expanded search path""" paths = set_up(workdir) os.symlink(paths['dir2'], paths['link1']) os.symlink(paths['dir2'], paths['link2']) with push_dir('projectA'): status = mu_repo.main(config_file='.bar_file', args=['register', '--recursive']) assert status.succeeded assert set(status.config.repos) == set(['sectionX/repo1', '../projectB/sectionY/repo2'])
def test_search_path_expansion(workdir): """Linking to a repository outside of initial search path""" paths = set_up(workdir) os.symlink(paths['repo2'], paths['link1']) with push_dir('projectA'): status = mu_repo.main(config_file='.bar_file', args=['register', '--recursive']) assert status.succeeded assert set(status.config.repos) == set( ['sectionX/repo1', '../projectB/sectionY/repo2'])
def test_infinite_cycle_ouside(workdir): """Linking to own ancestor directory in expanded search path""" paths = set_up(workdir) os.symlink(paths['dir2'], paths['link1']) os.symlink(paths['dir2'], paths['link2']) with push_dir('projectA'): status = mu_repo.main(config_file='.bar_file', args=['register', '--recursive']) assert status.succeeded assert set(status.config.repos) == set( ['sectionX/repo1', '../projectB/sectionY/repo2'])
def set_up(workdir): subprocess.call('git init {}/lib'.format(workdir).split(), cwd='.') subprocess.call('git init {}/app'.format(workdir).split(), cwd='.') open('{}/lib/dummy'.format(workdir), 'w').close() open('{}/app/dummy'.format(workdir), 'w').close() with open('{}/.mu_repo'.format(workdir), 'w') as config_file: config_file.write('repo=lib\nrepo=app\n') # Do an initial commit to create master branch mu_repo.main(config_file='.mu_repo', args=['add', '.']) mu_repo.main(config_file='.mu_repo', args=['config', '--local', 'user.email', 'you@example']) mu_repo.main(config_file='.mu_repo', args=['commit', '-am', '"init"'])
def test_clone_with_deps(): git = 'git' print(os.path.abspath('.')) # Test diffing with new folder structure subprocess.check_call([git] + 'init test_temp_dir/remote/projectA'.split(), cwd='.') subprocess.check_call([git] + 'init test_temp_dir/remote/projectB'.split(), cwd='.') subprocess.check_call([git] + 'init test_temp_dir/remote/projectC'.split(), cwd='.') # C depends on B and A with open('./test_temp_dir/remote/projectC/.mu_repo', 'w') as stream: stream.write('repo=.\nrepo=../projectB\nrepo=../projectA') remote_base = os.path.realpath(os.path.abspath('./test_temp_dir/remote')) # B depends on A with open('./test_temp_dir/remote/projectB/.mu_repo', 'w') as stream: stream.write('repo=.\nrepo=../projectA') # Commit the changes with _push_dir(remote_base + '/projectB'): configure_git_user() mu_repo.main(config_file=None, args=['ac', 'Initial commit']) with _push_dir(remote_base + '/projectC'): configure_git_user() mu_repo.main(config_file=None, args=['ac', 'Initial commit']) makedirs('./test_temp_dir/local') with _push_dir('./test_temp_dir/local'): # git clone C:\bin\mu-repo\test_temp_dir\remote\projectC config = mu_repo.Config() config.serial = True config.remote_hosts = [remote_base] mu_repo.main(config_file=None, args=['clone', 'projectC'], config=config) assert os.path.exists('projectA/.git') assert os.path.exists('projectB/.git') assert os.path.exists('projectB/.mu_repo') assert os.path.exists('projectC/.git') assert os.path.exists('projectC/.mu_repo')
def test_clone_with_deps(self): git = 'git' print(os.path.abspath('.')) # Test diffing with new folder structure subprocess.check_call([git] + 'init test_temp_dir/remote/projectA'.split(), cwd='.') subprocess.check_call([git] + 'init test_temp_dir/remote/projectB'.split(), cwd='.') subprocess.check_call([git] + 'init test_temp_dir/remote/projectC'.split(), cwd='.') # C depends on B and A with open('./test_temp_dir/remote/projectC/.mu_repo', 'w') as stream: stream.write('repo=.\nrepo=../projectB\nrepo=../projectA') remote_base = os.path.realpath(os.path.abspath('./test_temp_dir/remote')) # B depends on A with open('./test_temp_dir/remote/projectB/.mu_repo', 'w') as stream: stream.write('repo=.\nrepo=../projectA') # Commit the changes with self.push_dir(remote_base + '/projectB'): configure_git_user() mu_repo.main(config_file=None, args=['ac', 'Initial commit']) with self.push_dir(remote_base + '/projectC'): configure_git_user() mu_repo.main(config_file=None, args=['ac', 'Initial commit']) makedirs('./test_temp_dir/local') with self.push_dir('./test_temp_dir/local'): # git clone C:\bin\mu-repo\test_temp_dir\remote\projectC config = mu_repo.Config() config.serial = True config.remote_hosts = [remote_base] mu_repo.main(config_file=None, args=['clone', 'projectC'], config=config) assert os.path.exists('projectA/.git') assert os.path.exists('projectB/.git') assert os.path.exists('projectB/.mu_repo') assert os.path.exists('projectC/.git') assert os.path.exists('projectC/.mu_repo')
def testUnregister(self): status = mu_repo.main(config_file='.bar_file', args=['register', 'pydev', 'a', 'b']) self.assert_(status.succeeded) status = mu_repo.main(config_file='.bar_file', args=['list']) self.assertEquals(status.config.repos, ['a', 'b', 'pydev']) status = mu_repo.main(config_file='.bar_file', args=['unregister', 'a']) self.assert_(status.succeeded) status = mu_repo.main(config_file='.bar_file', args=['list']) self.assertEquals(status.config.repos, ['b', 'pydev']) status = mu_repo.main(config_file='.bar_file', args=['unregister', '--all']) self.assert_(status.succeeded) status = mu_repo.main(config_file='.bar_file', args=['list']) self.assertEquals(status.config.repos, [])
def test_unregister(): status = mu_repo.main(config_file='.bar_file', args=['register', 'pydev', 'a', 'b']) assert status.succeeded status = mu_repo.main(config_file='.bar_file', args=['list']) assert status.config.repos == ['a', 'b', 'pydev'] status = mu_repo.main(config_file='.bar_file', args=['unregister', 'a']) assert status.succeeded status = mu_repo.main(config_file='.bar_file', args=['list']) assert status.config.repos == ['b', 'pydev'] status = mu_repo.main(config_file='.bar_file', args=['unregister', '--all']) assert status.succeeded status = mu_repo.main(config_file='.bar_file', args=['list']) assert status.config.repos == []
def setUp(self): PushIgnorePrint() self.clear() self.workspace = 'test_temp_dir' subprocess.call('git init {}/lib'.format(self.workspace).split(), cwd='.') subprocess.call('git init {}/app'.format(self.workspace).split(), cwd='.') open('{}/lib/dummy'.format(self.workspace), 'w').close() open('{}/app/dummy'.format(self.workspace), 'w').close() with open('{}/.mu_repo'.format(self.workspace), 'w') as config_file: config_file.write('repo=lib\nrepo=app\n') self._last_dir = os.getcwd() os.chdir(self.workspace) # Do an initial commit to create master branch mu_repo.main(config_file='.mu_repo', args=['add', '.']) mu_repo.main(config_file='.mu_repo', args=['config', '--local', 'user.email', 'you@example']) mu_repo.main(config_file='.mu_repo', args=['commit', '-am', '"init"'])
#!/usr/bin/env python if __name__ == '__main__': import mu_repo mu_repo.main()
def testGroups(self): status = mu_repo.main(config_file='.bar_file', args=['register', 'pydev']) self.assert_(status.succeeded) self.assertEqual(status.config.repos, ['pydev']) self.assertEqual(status.config.current_group, None) self.assertEqual(status.config.groups, {}) # calling group without enough arguments and invalid group status = mu_repo.main(config_file='.bar_file', args=['group', 'add']) self.assert_(not status.succeeded) status = mu_repo.main(config_file='.bar_file', args=['group', 'rm', 'invalid-group']) self.assert_(not status.succeeded) # create group, copying current repos status = mu_repo.main(config_file='.bar_file', args=['group', 'add', 'group1']) self.assertEquals(status.config.repos, ['pydev']) self.assertEqual(status.config.current_group, 'group1') self.assertEqual(status.config.groups, {'group1' : ['pydev']}) # create group from scratch and add one repo status = mu_repo.main(config_file='.bar_file', args=['group', 'add', 'group2', '--clean']) self.assertEquals(status.config.repos, ['pydev']) self.assertEqual(status.config.current_group, 'group2') self.assertEqual(status.config.groups, {'group1' : ['pydev'], 'group2' : []}) status = mu_repo.main(config_file='.bar_file', args=['register', 'studio3']) self.assertEquals(status.config.repos, ['pydev', 'studio3']) self.assertEqual(status.config.current_group, 'group2') self.assertEqual(status.config.groups, {'group1' : ['pydev'], 'group2' : ['studio3']}) # group switch status = mu_repo.main(config_file='.bar_file', args=['group', 'switch', 'group1']) self.assertEqual(status.config.current_group, 'group1') # group del status = mu_repo.main(config_file='.bar_file', args=['group', 'del', 'group1']) self.assertEquals(status.config.repos, ['pydev', 'studio3']) self.assertEqual(status.config.current_group, None) self.assertEqual(status.config.groups, {'group2' : ['studio3']}) # make sure state is to the rest of the application in other commands # switch back to group1 and make sure "list" picks only the repos in that group status = mu_repo.main(config_file='.bar_file', args=['group', 'switch', 'group2']) self.assertEqual(status.config.current_group, 'group2') status = mu_repo.main(config_file='.bar_file', args=['list']) self.assertEquals(status.config.repos, ['studio3']) self.assertEqual(status.config.current_group, 'group2') # reset grouping and make sure "list" picks all repos status = mu_repo.main(config_file='.bar_file', args=['group', 'reset']) self.assertEqual(status.config.current_group, None) status = mu_repo.main(config_file='.bar_file', args=['list']) self.assertEquals(status.config.repos, ['pydev', 'studio3']) self.assertEqual(status.config.current_group, None)
def test_groups(): status = mu_repo.main(config_file='.bar_file', args=['register', 'pydev']) assert status.succeeded assert status.config.repos == ['pydev'] assert status.config.current_group == None assert status.config.groups == {} # calling group without enough arguments and invalid group status = mu_repo.main(config_file='.bar_file', args=['group', 'add']) assert not status.succeeded status = mu_repo.main(config_file='.bar_file', args=['group', 'rm', 'invalid-group']) assert not status.succeeded # create group, copying current repos status = mu_repo.main(config_file='.bar_file', args=['group', 'add', 'group1']) assert status.config.repos == ['pydev'] assert status.config.current_group == 'group1' assert status.config.groups == {'group1' : ['pydev']} # create group from scratch and add one repo status = mu_repo.main(config_file='.bar_file', args=['group', 'add', 'group2', '--clean']) assert status.config.repos == ['pydev'] assert status.config.current_group == 'group2' assert status.config.groups == {'group1' : ['pydev'], 'group2' : []} status = mu_repo.main(config_file='.bar_file', args=['register', 'studio3']) assert status.config.repos == ['pydev', 'studio3'] assert status.config.current_group == 'group2' assert status.config.groups == {'group1' : ['pydev'], 'group2' : ['studio3']} status = mu_repo.main(config_file='.bar_file', args=['list', '@group1']) assert status.config.repos == ['pydev'] status = mu_repo.main(config_file='.bar_file', args=['list', '@group2']) assert status.config.repos == ['studio3'] # group switch status = mu_repo.main(config_file='.bar_file', args=['group', 'switch', 'group1']) assert status.config.current_group == 'group1' # group del status = mu_repo.main(config_file='.bar_file', args=['group', 'del', 'group1']) assert status.config.repos == ['pydev', 'studio3'] assert status.config.current_group == None assert status.config.groups == {'group2' : ['studio3']} # make sure state is to the rest of the application in other commands # switch back to group1 and make sure "list" picks only the repos in that group status = mu_repo.main(config_file='.bar_file', args=['group', 'switch', 'group2']) assert status.config.current_group == 'group2' status = mu_repo.main(config_file='.bar_file', args=['list']) assert status.config.repos == ['studio3'] assert status.config.current_group == 'group2' # reset grouping and make sure "list" picks all repos status = mu_repo.main(config_file='.bar_file', args=['group', 'reset']) assert status.config.current_group == None status = mu_repo.main(config_file='.bar_file', args=['list']) assert status.config.repos == ['pydev', 'studio3'] assert status.config.current_group == None
def test_stat_server(self): mu_repo.main(config_file='.mu_repo', args=['branch', 'fb-rock']) mu_repo.main(config_file='.mu_repo', args=['branch', 'fb-paper']) mu_repo.main(config_file='.mu_repo', args=['branch', 'rb-scissors']) # Checkout fb-rock on both projects mu_repo.main(config_file='.mu_repo', args=['checkout', 'fb-rock']) self.assertEqual('fb-rock', self.get_current_branch('app')) self.assertEqual('fb-rock', self.get_current_branch('lib')) # Only one possible mathc, switch to rb-scissors mu_repo.main(config_file='.mu_repo', args=['checkout', 'rb-']) self.assertEqual('rb-scissors', self.get_current_branch('app')) self.assertEqual('rb-scissors', self.get_current_branch('lib')) # Couldn't guess branch name, do not checkout mu_repo.main(config_file='.mu_repo', args=['checkout', 'fb-']) self.assertEqual('rb-scissors', self.get_current_branch('lib'))
def testMain(self): status = mu_repo.main(config_file='.bar_file', args=[]) self.assert_(not status.succeeded)
def test_groups(): status = mu_repo.main(config_file='.bar_file', args=['register', 'pydev']) assert status.succeeded assert status.config.repos == ['pydev'] assert status.config.current_group == None assert status.config.groups == {} # calling group without enough arguments and invalid group status = mu_repo.main(config_file='.bar_file', args=['group', 'add']) assert not status.succeeded status = mu_repo.main(config_file='.bar_file', args=['group', 'rm', 'invalid-group']) assert not status.succeeded # create group, copying current repos status = mu_repo.main(config_file='.bar_file', args=['group', 'add', 'group1']) assert status.config.repos == ['pydev'] assert status.config.current_group == 'group1' assert status.config.groups == {'group1': ['pydev']} # create group from scratch and add one repo status = mu_repo.main(config_file='.bar_file', args=['group', 'add', 'group2', '--clean']) assert status.config.repos == ['pydev'] assert status.config.current_group == 'group2' assert status.config.groups == {'group1': ['pydev'], 'group2': []} status = mu_repo.main(config_file='.bar_file', args=['register', 'studio3']) assert status.config.repos == ['pydev', 'studio3'] assert status.config.current_group == 'group2' assert status.config.groups == {'group1': ['pydev'], 'group2': ['studio3']} status = mu_repo.main(config_file='.bar_file', args=['list', '@group1']) assert status.config.repos == ['pydev'] status = mu_repo.main(config_file='.bar_file', args=['list', '@group2']) assert status.config.repos == ['studio3'] # group switch status = mu_repo.main(config_file='.bar_file', args=['group', 'switch', 'group1']) assert status.config.current_group == 'group1' # group del status = mu_repo.main(config_file='.bar_file', args=['group', 'del', 'group1']) assert status.config.repos == ['pydev', 'studio3'] assert status.config.current_group == None assert status.config.groups == {'group2': ['studio3']} # make sure state is to the rest of the application in other commands # switch back to group1 and make sure "list" picks only the repos in that group status = mu_repo.main(config_file='.bar_file', args=['group', 'switch', 'group2']) assert status.config.current_group == 'group2' status = mu_repo.main(config_file='.bar_file', args=['list']) assert status.config.repos == ['studio3'] assert status.config.current_group == 'group2' # reset grouping and make sure "list" picks all repos status = mu_repo.main(config_file='.bar_file', args=['group', 'reset']) assert status.config.current_group == None status = mu_repo.main(config_file='.bar_file', args=['list']) assert status.config.repos == ['pydev', 'studio3'] assert status.config.current_group == None
def test_main(): status = mu_repo.main(config_file='.bar_file', args=[]) assert not status.succeeded
def test_checkout_partial_names(workdir): set_up(workdir) mu_repo.main(config_file='.mu_repo', args=['branch', 'fb-rock']) mu_repo.main(config_file='.mu_repo', args=['branch', 'fb-paper']) mu_repo.main(config_file='.mu_repo', args=['branch', 'rb-scissors']) # Checkout fb-rock on both projects mu_repo.main(config_file='.mu_repo', args=['checkout', 'fb-rock']) assert 'fb-rock' == get_current_branch('app') assert 'fb-rock' == get_current_branch('lib') # Only one possible mathc, switch to rb-scissors mu_repo.main(config_file='.mu_repo', args=['checkout', 'rb-']) assert 'rb-scissors' == get_current_branch('app') assert 'rb-scissors' == get_current_branch('lib') # Couldn't guess branch name, do not checkout mu_repo.main(config_file='.mu_repo', args=['checkout', 'fb-']) assert 'rb-scissors' == get_current_branch('lib')
def test_clone_all(self): git = 'git' print(os.path.abspath('.')) remote_dir = 'test_temp_dir/remote_clone_all'; # Test diffing with new folder structure subprocess.check_call([git] + ('init %s/meta_project' % (remote_dir)).split(), cwd='.') subprocess.check_call([git] + ('init %s/projectD' % (remote_dir)).split(), cwd='.') subprocess.check_call([git] + ('init %s/projectE' % (remote_dir)).split(), cwd='.') subprocess.check_call([git] + ('init %s/projectF' % (remote_dir)).split(), cwd='.') remote_base = os.path.realpath(os.path.abspath(remote_dir)) # Register meta project repos with open('%s/meta_project/.mu_repo' % (remote_dir), 'w') as stream: stream.write('repo=.\nrepo=../projectD\nrepo=../projectE\nrepo=../projectF\n') stream.write('remote_host=%s' % (remote_base)) with self.push_dir(os.path.join(remote_base, 'meta_project')): configure_git_user() mu_repo.main(config_file=None, args=['ac', 'Added projects']) # add some content to A with open('%s/projectD/D.txt' % (remote_dir), 'w') as stream: stream.write('some content of D') # add some content to B with open('%s/projectE/E.txt' % (remote_dir), 'w') as stream: stream.write('some content of E') # add some content to C with open('%s/projectF/F.txt' % (remote_dir), 'w') as stream: stream.write('some content of F') # Commit the changes with self.push_dir(remote_base + '/projectD'): configure_git_user() mu_repo.main(config_file=None, args=['ac', 'Initial commit']) with self.push_dir(remote_base + '/projectE'): configure_git_user() mu_repo.main(config_file=None, args=['ac', 'Initial commit']) with self.push_dir(remote_base + '/projectF'): configure_git_user() mu_repo.main(config_file=None, args=['ac', 'Initial commit']) local_clone_all = os.path.realpath(os.path.abspath('./test_temp_dir/local_clone_all')) makedirs(local_clone_all) with self.push_dir(local_clone_all): config = mu_repo.Config() config.serial = True config.remote_hosts = [remote_base] mu_repo.main(config_file=None, args=['clone', 'meta_project'], config=config) with self.push_dir('./meta_project'): mu_repo.main(args=['clone', '--all']) assert os.path.exists(os.path.join(local_clone_all, 'projectD', '.git')) assert os.path.exists(os.path.join(local_clone_all, 'projectD', 'D.txt')) assert os.path.exists(os.path.join(local_clone_all, 'projectE', '.git')) assert os.path.exists(os.path.join(local_clone_all, 'projectE', 'E.txt')) assert os.path.exists(os.path.join(local_clone_all, 'projectF', '.git')) assert os.path.exists(os.path.join(local_clone_all, 'projectF', 'F.txt'))
def testGroups(self): status = mu_repo.main(config_file='.bar_file', args=['register', 'pydev']) self.assert_(status.succeeded) self.assertEqual(status.config.repos, ['pydev']) self.assertEqual(status.config.current_group, None) self.assertEqual(status.config.groups, {}) # calling group without enough arguments and invalid group status = mu_repo.main(config_file='.bar_file', args=['group', 'add']) self.assert_(not status.succeeded) status = mu_repo.main(config_file='.bar_file', args=['group', 'rm', 'invalid-group']) self.assert_(not status.succeeded) # create group, copying current repos status = mu_repo.main(config_file='.bar_file', args=['group', 'add', 'group1']) self.assertEquals(status.config.repos, ['pydev']) self.assertEqual(status.config.current_group, 'group1') self.assertEqual(status.config.groups, {'group1': ['pydev']}) # create group from scratch and add one repo status = mu_repo.main(config_file='.bar_file', args=['group', 'add', 'group2', '--clean']) self.assertEquals(status.config.repos, ['pydev']) self.assertEqual(status.config.current_group, 'group2') self.assertEqual(status.config.groups, { 'group1': ['pydev'], 'group2': [] }) status = mu_repo.main(config_file='.bar_file', args=['register', 'studio3']) self.assertEquals(status.config.repos, ['pydev', 'studio3']) self.assertEqual(status.config.current_group, 'group2') self.assertEqual(status.config.groups, { 'group1': ['pydev'], 'group2': ['studio3'] }) # group switch status = mu_repo.main(config_file='.bar_file', args=['group', 'switch', 'group1']) self.assertEqual(status.config.current_group, 'group1') # group del status = mu_repo.main(config_file='.bar_file', args=['group', 'del', 'group1']) self.assertEquals(status.config.repos, ['pydev', 'studio3']) self.assertEqual(status.config.current_group, None) self.assertEqual(status.config.groups, {'group2': ['studio3']}) # make sure state is to the rest of the application in other commands # switch back to group1 and make sure "list" picks only the repos in that group status = mu_repo.main(config_file='.bar_file', args=['group', 'switch', 'group2']) self.assertEqual(status.config.current_group, 'group2') status = mu_repo.main(config_file='.bar_file', args=['list']) self.assertEquals(status.config.repos, ['studio3']) self.assertEqual(status.config.current_group, 'group2') # reset grouping and make sure "list" picks all repos status = mu_repo.main(config_file='.bar_file', args=['group', 'reset']) self.assertEqual(status.config.current_group, None) status = mu_repo.main(config_file='.bar_file', args=['list']) self.assertEquals(status.config.repos, ['pydev', 'studio3']) self.assertEqual(status.config.current_group, None)