def test_unlock_one_of_two(env): '''Unlocking a single file out of multiple pending changes''' file1 = join(env.repo_dir, 'foo') open(file1, 'w').write(HELLO_CONTENT) file2 = join(env.repo_dir, 'bar') open(file2, 'w').write(HELLO_CONTENT) # git should report that the repo is dirty check_status(['A .gitattributes', '?? bar', '?? foo']) # add the files to git-big check_output(['git', 'big', 'add', file1]) check_output(['git', 'big', 'add', file2]) # git should now track the new files check_status(['A .gitattributes', 'A .gitbig', 'A bar', 'A foo']) # unlock the file check_output(['git', 'big', 'unlock', file1]) # git should report that file1 is untracked but file2 is still tracked check_call(['git', 'status']) check_status(['A .gitattributes', 'A .gitbig', 'A bar', '?? foo']) # we should have a normal file and a linked file assert not fs.islink(file1) assert fs.isfile(file1) assert fs.islink(file2) # unlocked files should be writable open(file1, 'w').write('ok') # locked files should remain read-only check_locked_file(env, file2, HELLO_DIGEST)
def test_unlock(env): '''Unlocking a file should replace the symlink with a copy of the file''' file_ = join(env.repo_dir, 'foo') open(file_, 'w').write(HELLO_CONTENT) # git should report that the repo is dirty check_status(['A .gitattributes', '?? foo']) # add the file to git-big check_output(['git', 'big', 'add', file_]) # git should now track the new file check_status(['A .gitattributes', 'A .gitbig', 'A foo']) # unlock the file check_output(['git', 'big', 'unlock', file_]) # git should report that the file is untracked check_call(['git', 'status']) check_status(['A .gitattributes', '?? foo']) # we should have a normal file assert not fs.islink(file_) assert fs.isfile(file_) # unlocked files should be writable open(file_, 'w').write('ok')
def test_unlock_after_commit(env): '''Unlocking a file after a commit''' file1 = join(env.repo_dir, 'foo') open(file1, 'w').write(HELLO_CONTENT) file2 = join(env.repo_dir, 'bar') open(file2, 'w').write(HELLO_CONTENT) # git should report that the repo is dirty check_status(['A .gitattributes', '?? bar', '?? foo']) # add the files to git-big check_output(['git', 'big', 'add', file1]) check_output(['git', 'big', 'add', file2]) # make a commit check_output(['git', 'commit', '-m', 'commit']) # unlock the file check_output(['git', 'big', 'unlock', file1]) # git should report that file1 is deleted and untracked but file2 is still tracked check_call(['git', 'status']) check_status(['M .gitbig', 'D foo', '?? foo']) # we should have a normal file and a linked file assert not fs.islink(file1) assert fs.isfile(file1) assert fs.islink(file2) # unlocked files should be writable open(file1, 'w').write('ok') # locked files should remain read-only check_locked_file(env, file2, HELLO_DIGEST) # save the change check_output(['git', 'big', 'add', file1]) # see that the file is now modified check_call(['git', 'status']) check_status(['M .gitbig', 'M foo'])
def test_fresh_clone(depot_env): '''Make a fresh clone and pull''' # make the origin repo make_origin(depot_env) # clone it clone = depot_env.clone(cache_dir='clone_cache') # pull big files (initially soft) check_call(['git', 'big', 'pull']) assert fs.islink(join(clone.repo_dir, 'foo')) assert fs.islink(join(clone.repo_dir, 'bar')) assert not fs.isfile(join(clone.repo_dir, 'foo')) assert not fs.isfile(join(clone.repo_dir, 'bar')) # pull big files (now hard) check_output(['git', 'big', 'pull', '--hard']) assert fs.isfile(join(clone.repo_dir, 'foo')) assert fs.isfile(join(clone.repo_dir, 'bar'))
def check_locked_file(env, file_, digest, root_dir=None): if not root_dir: root_dir = env.repo_dir anchors_path = os.path.join(root_dir, '.gitbig-anchors', digest[:2], digest[2:4], digest) symlink_path = os.path.relpath(anchors_path, os.path.dirname(file_)) cache_path = os.path.join(env.cache_dir, 'objects', digest[:2], digest[2:4], digest) assert fs.isfile(anchors_path) assert fs.isfile(cache_path) assert fs.islink(file_) assert fs.readlink(file_) == symlink_path assert os.stat(anchors_path).st_ino == os.stat(cache_path).st_ino # once the file is added, it should be read-only with pytest.raises(Exception): file_.write('fail')
def test_checkout_diff_types(depot_env): '''Switch between branches, hooks should pull and update links. 1st commit is a big file, 2nd commit is a normal file.''' # add a file file_ = join(depot_env.repo_dir, 'foo') open(file_, 'w').write(HELLO_CONTENT) check_output(['git', 'big', 'add', file_]) # commit the changes check_call(['git', 'status']) check_output(['git', 'commit', '-m', '1st commit']) check_status([]) # make a new branch check_output(['git', 'checkout', '-b', 'changed']) # change a file check_output(['git', 'big', 'unlock', file_]) open(file_, 'w').write(WORLD_CONTENT) check_output(['git', 'add', file_]) # commit the changes check_call(['git', 'status']) check_output(['git', 'commit', '-m', '2nd commit']) check_status([]) # switch back to 1st branch check_output(['git', 'checkout', 'master']) check_locked_file(depot_env, file_, HELLO_DIGEST) # switch back to master branch check_output(['git', 'checkout', 'changed']) assert not fs.islink(file_) # switch back to 1st branch check_output(['git', 'checkout', 'master']) check_locked_file(depot_env, file_, HELLO_DIGEST)