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_move_after_commit(env): '''Moving a file after a commit should move the link''' source = join(env.repo_dir, 'foo') open(source, 'w').write(HELLO_CONTENT) dest = join(env.repo_dir, 'bar') # git should report that the repo is dirty check_status(['A .gitattributes', '?? foo']) # add the file to git-big check_output(['git', 'big', 'add', source]) # make a commit check_output(['git', 'commit', '-m', 'commit']) # move the link check_output(['git', 'big', 'mv', source, dest]) # git should track the dest check_call(['git', 'status']) check_status(['M .gitbig', 'R foo -> bar']) # the file should now be moved assert not exists(source) check_locked_file(env, dest, HELLO_DIGEST)
def test_copy_after_commit(env): '''Copying a file after a commit should create another link''' source = join(env.repo_dir, 'foo') open(source, 'w').write(HELLO_CONTENT) dest = join(env.repo_dir, 'bar') # git should report that the repo is dirty check_status(['A .gitattributes', '?? foo']) # add the file to git-big check_output(['git', 'big', 'add', source]) # make a commit check_output(['git', 'commit', '-m', 'commit']) # copy the link check_output(['git', 'big', 'cp', source, dest]) # git should track the source and dest check_call(['git', 'status']) check_status(['M .gitbig', 'A bar']) # we should have two links to the same object check_locked_file(env, source, HELLO_DIGEST) check_locked_file(env, dest, HELLO_DIGEST)
def test_add(env): '''Adding a file to a worktree''' # create an initial commit touched = join(env.repo_dir, 'xxx') open(touched, 'w').close() check_output(['git', 'add', touched]) check_output(['git', 'commit', '-m', 'commit']) # create a worktree check_output(['git', 'worktree', 'add', 'worktree']) # change directory into the worktree os.chdir('worktree') open('foo', 'w').write(HELLO_CONTENT) # git should report that the repo is dirty check_status(['?? foo']) # add the file check_output(['git', 'big', 'add', 'foo']) # status should show two pending changes check_status(['A .gitbig', 'A foo']) # verify link is working check_locked_file(env, 'foo', HELLO_DIGEST, '.')
def add_file(env, file_, digest, expected_status): # add the file to git-big check_output(['git', 'big', 'add', file_]) # git should now ignore the new file check_status(expected_status) check_locked_file(env, file_, digest)
def test_create(env): '''Create a worktree, ensure big files are linked''' # add a file and commit file_ = join(env.repo_dir, 'foo') open(file_, 'w').write(HELLO_CONTENT) check_output(['git', 'big', 'add', file_]) check_output(['git', 'commit', '-m', 'message']) # create a worktree check_output(['git', 'worktree', 'add', 'worktree']) # change directory into the worktree os.chdir('worktree') # pull big files into worktree check_output(['git', 'big', 'pull']) # verify link is working check_locked_file(env, 'foo', HELLO_DIGEST, '.')
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_add_directory(env): '''Adding a directory should recursively add all files underneath''' dir1 = join(env.repo_dir, 'dir') file1 = join(dir1, 'foo') dir2 = join(dir1, 'dir') file2 = join(dir2, 'foo') os.makedirs(dir2) open(file1, 'w').write(HELLO_CONTENT) open(file2, 'w').write(WORLD_CONTENT) # git should report that the repo is dirty check_status(['A .gitattributes', '?? dir/']) # add the directory to git-big check_output(['git', 'big', 'add', 'dir']) # git should now ignore the new files check_status( ['A .gitattributes', 'A .gitbig', 'A dir/dir/foo', 'A dir/foo']) check_locked_file(env, file1, HELLO_DIGEST) check_locked_file(env, file2, WORLD_DIGEST)
def test_checkout_diff_types(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(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(env, file_, HELLO_DIGEST) # switch back to master branch check_output(['git', 'checkout', 'changed']) assert not islink(file_) # switch back to 1st branch check_output(['git', 'checkout', 'master']) check_locked_file(env, file_, HELLO_DIGEST)
def test_checkout(depot_env): '''Switch between branches, hooks should pull and update links''' # 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', 'big', 'add', file_]) # commit the changes check_call(['git', 'status']) check_output(['git', 'commit', '-m', '2nd commit']) check_status([]) # switch back to 1st branch check_call(['git', 'checkout', 'master']) check_locked_file(depot_env, file_, HELLO_DIGEST) check_anchors(depot_env, [HELLO_DIGEST]) # switch back to master branch check_output(['git', 'checkout', 'changed']) check_locked_file(depot_env, file_, WORLD_DIGEST) check_anchors(depot_env, [WORLD_DIGEST]) # switch back to 1st branch check_output(['git', 'checkout', 'master']) check_locked_file(depot_env, file_, HELLO_DIGEST) check_anchors(depot_env, [HELLO_DIGEST])