def test_get_current_branch(): # Create a temporary workfolder tmp_dir = mkdtemp() from subprocess import check_call, PIPE # Create a test repo check_call('git init .', shell=True, cwd=tmp_dir, stdout=PIPE) from bloom.git import get_current_branch assert get_current_branch(tmp_dir) == None, \ get_current_branch(tmp_dir) + ' == None' # Make a commit check_call('touch example.txt', shell=True, cwd=tmp_dir, stdout=PIPE) check_call('git add *', shell=True, cwd=tmp_dir, stdout=PIPE) check_call('git commit -a -m "Initial commit."', shell=True, cwd=tmp_dir, stdout=PIPE) # Make a branch check_call('git branch bloom', shell=True, cwd=tmp_dir, stdout=PIPE) assert get_current_branch(tmp_dir) == 'master' # Change to the bloom branch check_call('git checkout bloom', shell=True, cwd=tmp_dir, stdout=PIPE, stderr=PIPE) assert get_current_branch(tmp_dir) == 'bloom' from vcstools import VcsClient client = VcsClient('git', tmp_dir) spec = client.get_version('master') check_call('git checkout {0}'.format(spec), shell=True, cwd=tmp_dir, stdout=PIPE, stderr=PIPE) assert get_current_branch(tmp_dir) == None, \ get_current_branch(tmp_dir) + ' == None' rmtree(tmp_dir)