def setup(): master_path, master = init_master(test_name) # Prepare master repo master.git.checkout(b=test_name) # Crate test repo path = join(basepath, test_name) master.clone(path, b=test_name) repo = Repo(path, odbt=GitCmdObjectDB) # repo = Repo.init(path) # update_file(repo, 'Initial commit') os.chdir(path) assert repo.working_dir == path # Rename test repo branch repo.git.branch(test_name + '_renamed', m=True) # Add subrepo write_file(join(path, '.gitmodules'), '') repo.create_submodule('sub', 'sub', master_path) repo.git.add('.gitmodules', 'sub/') repo.git.commit(m='Added submodule') repo.git.submodule('init') # Modify file in master update_file(master, test_name)
def setup(): master_path, master = init_master(test_name) # Prepare master repo master.git.checkout(b=test_name) # Clone to test repo path = join(basepath, test_name) master.clone(path, b=test_name) repo = Repo(path, odbt=GitCmdObjectDB) assert repo.working_dir == path # Modify file in master update_file(master, test_name) # Modify file in our repo contents = 'completely changed!' repo_file = join(path, testfile_name) write_file(repo_file, contents) repo.index.add([repo_file]) repo.index.commit(test_name) # Modify file in master update_file(master, test_name)
def setup(): master_path, master = init_master(test_name) os.makedirs(git_dir) os.makedirs(work_tree) # Prepare master repo master.git.checkout(b=test_name) # Create work tree with open(join(work_tree, '.git'), 'w') as f: f.write('gitdir: ' + git_dir) # Clone master os.environ['GIT_DIR'] = git_dir os.environ['GIT_WORK_TREE'] = work_tree repo = Repo.init(work_tree) repo.git.remote('add', 'origin', master_path) repo.git.fetch('origin') repo.git.checkout('origin/' + test_name, b=test_name) del os.environ['GIT_DIR'] del os.environ['GIT_WORK_TREE'] # Modify file in our repo repo_path_file = join(master_path, testfile_name) write_file(repo_path_file, 'line 1\nline 2\ncounter: 2') master.index.add([repo_path_file]) master.index.commit(test_name)
def setup(): master_path, master = init_master(test_name) # Prepare master repo master.git.checkout(b=test_name) # Clone to test repo path = join(basepath, test_name) master.clone(path, b=test_name) repo = Repo(path, odbt=GitCmdObjectDB) assert repo.working_dir == path # Modify file in master master_file = update_file(master, test_name) # Modify file in our repo contents = _read_file(master_file) contents = contents.replace('line 1', 'line x') repo_file = join(path, testfile_name) write_file(repo_file, contents) repo.index.add([repo_file]) repo.index.commit(test_name) # Set git-up.rebase.arguments to '--abort', what results in an # invalid cmd and thus git returning an error, that we look for. repo.git.config('git-up.rebase.arguments', '--abort')
def setup(): master_path, master = init_master(test_name) # Prepare master repo master.git.checkout(b=test_name) # Clone to test repo path = join(basepath, test_name) master.clone(path, b=test_name) repo = Repo(path, odbt=GitCmdObjectDB) assert repo.working_dir == path # Modify file in master master_file = update_file(master, test_name) # Modify file in our repo contents = _read_file(master_file) contents = contents.replace('line 1', 'line x') repo_file = join(path, testfile_name) write_file(repo_file, contents) repo.index.add([repo_file]) repo.index.commit(test_name)
def test_forget_dir(self) -> None: self.assertFalse(Stat.exists("foo")) self.assertFalse(Stat.exists("foo/bar")) os.mkdir("foo") write_file("foo/bar") self.assertFalse(Stat.exists("foo")) self.assertFalse(Stat.exists("foo/bar")) Stat.forget("foo") self.assertTrue(Stat.exists("foo")) self.assertTrue(Stat.exists("foo/bar")) shutil.rmtree("foo") self.assertTrue(Stat.exists("foo")) self.assertTrue(Stat.exists("foo/bar")) Stat.forget("foo") self.assertFalse(Stat.exists("foo")) self.assertFalse(Stat.exists("foo/bar"))
def test_path_escape(self): c = cache.Cache("__test_path_escape__") # create file tests.write_file(tests.data_path("tmp", "file.txt", exists=False), "Hello, world!") # sanity check self.assertEqual(tests.read_file(tests.data_path("tmp", "file.txt")), "Hello, world!") # insert file into cache key = 'this key/path needs: escaping!.?' c[key] = tests.data_path("tmp", "file.txt") # check file contents self.assertEqual(tests.read_file(c[key]), "Hello, world!") c.empty()
def test_remove(self): c = cache.Cache("__test_remove__") # create file tests.write_file(tests.data_path("tmp", "file.txt", exists=False), "Hello, world!") # sanity check self.assertEqual(tests.read_file(tests.data_path("tmp", "file.txt")), "Hello, world!") # insert file into cache c['foobar'] = tests.data_path("tmp", "file.txt") # remove from cache del c['foobar'] self.assertFalse(c['foobar']) c.empty()
def setup(): master_path, master = init_master(test_name) # Prepare master repo master.git.checkout(b=test_name) # Clone to test repo path = join(basepath, test_name) master.clone(path, b=test_name) repo = Repo(path, odbt=GitCmdObjectDB) assert repo.working_dir == path # Modify file in our repo repo_path_file = join(path, testfile_name) write_file(repo_path_file, 'line 1\nline 2\ncounter: 2') repo.index.add([repo_path_file]) repo.index.commit(test_name)
def test_submodules_dirty(): """ Run 'git up' with submodules in a dirty repo """ repo = Repo(repo_path) repo_head = repo.head.commit.hexsha submod_head = repo.submodules[0].hexsha # Change file in submodule write_file('sub/file', 'submodule changed') from PyGitUp.gitup import GitUp gitup = GitUp(testing=True) # PyGitUp uses the main repo assert_equal(repo_head, gitup.git.repo.head.commit.hexsha) gitup.run() assert_equal(len(gitup.states), 1) assert_equal(gitup.states[0], 'rebasing')
def setup(): master_path, master = init_master(test_name) # Prepare master repo master.git.checkout(b=test_name) # Clone to test repo path = join(basepath, test_name) master.clone(path, b=test_name) repo = Repo(path, odbt=GitCmdObjectDB) assert repo.working_dir == path # Modify file in master update_file(master, test_name, filename='test1.txt') # Modify file in working directory write_file(join(path, 'test1.txt'), 'Hello world!')
def setup(): master_path, master = init_master(test_name) # Prepare master repo master.git.checkout(b=test_name) # Add Gemfile gemfile = join(master_path, 'Gemfile') write_file(gemfile, "source 'https://rubygems.org'\ngem 'colored'") master.index.add([gemfile]) master.index.commit(test_name) # Clone to test repo path = join(basepath, test_name) master.clone(path, b=test_name) repo = Repo(path, odbt=GitCmdObjectDB) repo.git.config('git-up.bundler.check', 'true') assert repo.working_dir == path
def test_set_and_get(self): c = cache.Cache("__test_set_and_get__") # create file tests.write_file(tests.data_path("tmp", "file.txt", exists=False), "Hello, world!") # sanity check self.assertEqual(tests.read_file(tests.data_path("tmp", "file.txt")), "Hello, world!") # insert file into cache c['foobar'] = tests.data_path("tmp", "file.txt") # file must be in cache self.assertTrue(fs.isfile(fs.path(c.path, "foobar"))) # file must have been moved self.assertFalse(fs.isfile(tests.data_path("file.txt", exists=False))) # check file contents self.assertTrue(tests.read_file(c['foobar']), "Hello, world!") c.empty()
def setup(): master_path, master = init_master(test_name) # Prepare master repo master.git.checkout(b=test_name) # Clone to test repo path = join(basepath, test_name) master.clone(path, b=test_name) repo = Repo(path, odbt=GitCmdObjectDB) assert repo.working_dir == path # Create second branch and add test_file.1 to index write_file(join(path, testfile_name + '.1'), 'contents :)') repo.index.add([testfile_name + '.1']) # Checkout first branch and add same file but untracked repo.git.checkout(test_name) write_file(join(path, testfile_name), 'content')
def setup(): master_path, master = init_master(test_name) # Prepare master repo master.git.checkout(b=test_name) # Clone to test repo path = join(basepath, test_name) master.clone(path, b=test_name) repo = Repo(path, odbt=GitCmdObjectDB) assert repo.working_dir == path # Modify file in master master_path_file = join(master_path, testfile_name) write_file(master_path_file, 'contents') master.index.add([master_path_file]) master.index.commit(test_name) # Modify file in repo path_file = join(path, testfile_name) os.unlink(path_file)
def setup(): master_path, master = init_master(test_name) # Prepare master repo master.git.checkout(b=test_name) # Clone to test repo path = join(basepath, test_name) master.clone(path, b=test_name) repo = Repo(path, odbt=GitCmdObjectDB) testfile_path = join(path, testfile_name) assert repo.working_dir == path # Modify file in master master_path_file = join(master_path, testfile_name) write_file(master_path_file, 'contents1') master.index.add([master_path_file]) master.index.commit(test_name) # Create unmerged paths in working dir branch_master = repo.active_branch branch_changed = repo.create_head(test_name + '.branch') branch_changed.set_commit('HEAD') branch_changed.checkout() write_file(testfile_path, 'contents1') repo.index.add([testfile_path]) repo.index.commit('Update in branch') branch_master.checkout() write_file(testfile_path, 'contents2') repo.index.add([testfile_path]) repo.index.commit('Update in origin') try: repo.git.merge(test_name + '.branch') except GitCommandError: pass
def test_glob_fmt(self) -> None: write_file("x.txt", "") self.assertEqual(glob_fmt("{*foo}.txt", "{foo}.csv"), ["x.csv"])
def test_file(self) -> None: write_file("foo") self.assertTrue(Stat.exists("foo")) self.assertTrue(Stat.isfile("foo")) self.assertFalse(Stat.isdir("foo")) Stat.stat("foo")
def test_forget_file(self) -> None: self.assertFalse(Stat.exists("foo")) write_file("foo") self.assertFalse(Stat.exists("foo")) Stat.forget("foo") self.assertTrue(Stat.exists("foo"))