This testcase creates several repositores:
- A repository at dirs['repo'] called repo
- A bare repository at dirs['bare'] called bare
- A clone of repo below dirs['clone'] called clone
- A mirror of repo below mirror_dirs['clone'] called mirror
Function | setup |
Undocumented |
Function | teardown |
Undocumented |
Function | test |
Add some dummy data |
Function | test |
First branch is called master |
Function | test |
Checkout treeishs |
Function | test |
Remove untracked files from the working tree |
Function | test |
Clone a repository |
Function | test |
Methods tested: |
Function | test |
Create a repository |
Function | test |
Create a bare repository |
Function | test |
Create a branch name foo |
Function | test |
Check that creating a repository at a path that isn't writeable fails |
Function | test |
Create a branch named foo2 and delete it |
Function | test |
Delete tags |
Function | test |
Describe commit-ish |
Function | test |
Test git-diff |
Function | test |
Methods tested: |
Function | test |
Empty repos have no branch |
Function | test |
Fetch from a remote repository |
Function | test |
Find the closest tags on a certain branch to a given commit |
Function | test |
Find tags |
Function | test |
Test garbage collection |
Function | test |
Test inspecting commits |
Function | test |
Test listing commits |
Function | test |
Find the common ancestor of two objects |
Function | test |
Find commit SHA1 related to tags |
Function | test |
Check remotes |
Function | test |
Get info about upstream branches set in test_set_upstream_branch |
Function | test |
Properties tested: |
Function | test |
Test grepping through commit messages |
Function | test |
Test if branch is fast forwardable |
Function | test |
List files in the index |
Function | test |
Test git-mk-tree |
Function | test |
Merge a branch |
Function | test |
Mirror a repository |
Function | test |
Move a tag |
Function | test |
Check that accessing a non-existent repository fails. |
Function | test |
Pull from a remote repository |
Function | test |
Create branch named baz, rename it to bax and finally delete it |
Function | test |
Methods tested: |
Function | test |
Switch to branch named foo |
Function | test |
Methods tested: |
Function | test |
Set upstream branch master -> origin/master |
Function | test |
Methods tested: |
Function | test |
Methods tested: |
Function | test |
Make surewe can init repos from a subdir >>> import gbp.git, os >>> os.mkdir(os.path.join(dirs['repo'], 'subdir')) >>> repo = gbp.git.GitRepository(os.path.join(dirs['repo'], 'subdir'), toplevel=False) >>> repo... |
Function | test |
Create a tag named tag and check its existance |
Function | test |
Test updating a reference |
Function | test |
Updating submodules if we don't have any is a noop |
Variable | dirs |
Undocumented |
Variable | subdirs |
Undocumented |
Add some dummy data
Methods tested:
Properties tested:
>>> import gbp.git, shutil, os >>> repo = gbp.git.GitRepository(dirs['repo']) >>> ret = shutil.copy(os.path.join(repo.path, ".git/HEAD"), ... os.path.join(repo.path, "testfile")) >>> repo.is_clean()[0] False >>> repo.is_clean('doesnotexist')[0] True >>> repo.is_clean(paths='testfile')[0] False >>> repo.is_clean(paths=['doesnotexist', 'testfile'])[0] False >>> repo.is_clean(ignore_untracked=True)[0] True >>> repo.add_files(repo.path, force=True) >>> repo.commit_all(msg="foo") >>> repo.is_clean()[0] True >>> h = repo.head >>> len(h) 40
First branch is called master
Methods tested:
>>> import gbp.git, shutil >>> repo = gbp.git.GitRepository(dirs['repo']) >>> repo.get_branch() 'master' >>> repo.branch 'master'
Checkout treeishs
Methods tested:
gbp.git.GitRepository.checkout
gbp.git.GitRepository.get_branch
gbp.git.GitRepository.set_branch
gbp.git.GitRepository.rev_parse
Properties tested:
>>> import gbp.git >>> repo = gbp.git.GitRepository(dirs['repo']) >>> repo.checkout('master') >>> repo.branch 'master' >>> repo.rev_parse('doesnotexist') Traceback (most recent call last): ... gbp.git.repository.GitRepositoryError: revision 'doesnotexist' not found >>> sha1 = repo.rev_parse('master', short=10) >>> len(sha1) 10 >>> sha1 = repo.rev_parse('master') >>> len(sha1) 40 >>> repo.checkout(sha1) >>> repo.branch >>> repo.get_branch() Traceback (most recent call last): ... gbp.git.repository.GitRepositoryError: Currently not on a branch >>> tag = repo.tags[0] >>> repo.checkout(tag) >>> repo.branch
Remove untracked files from the working tree
Methods tested:
>>> import gbp.git, shutil, os >>> repo = gbp.git.GitRepository(dirs['repo']) >>> ret = shutil.copy(os.path.join(repo.path, ".git/HEAD"), ... os.path.join(repo.path, "testclean")) >>> repo.clean(dry_run=True) >>> repo.is_clean()[0] False >>> repo.clean(directories=True, force=True) >>> repo.is_clean()[0] True
Clone a repository
Methods tested:
gbp.git.GitRepository.clone
gbp.git.GitRepository.is_empty
gbp.git.GitRepository.set_branch
gbp.git.GitRepository.branch
gbp.git.GitRepository.get_merge_branch
gbp.git.GitRepository.get_remote_branches
gbp.git.GitRepository.get_local_branches
gbp.git.GitRepository.get_remote_repos
gbp.git.GitRepository.has_remote_repo
>>> import gbp.git >>> repo = gbp.git.GitRepository(dirs['repo']) >>> repo.set_branch('master') >>> clone = gbp.git.GitRepository.clone(dirs['clone'], repo.path) >>> clone.is_empty() False >>> clone.branch 'master' >>> clone.get_remote_branches() ['origin/HEAD', 'origin/foo', 'origin/master'] >>> clone.get_local_branches() ['master'] >>> clone.get_merge_branch('master') 'origin/master' >>> clone.create_branch('foo', 'origin/foo') >>> clone.get_merge_branch('foo') 'origin/foo' >>> clone.create_branch('bar') >>> clone.get_merge_branch('bar') # None if no merge branch exists >>> clone.get_local_branches() ['bar', 'foo', 'master'] >>> clone.get_remote_repos() ['origin'] >>> clone.has_remote_repo('origin') True >>> clone.has_branch('origin/master', remote=True) True >>> clone.has_remote_repo('godiug') False
Methods tested:
>>> import gbp.git >>> repo = gbp.git.GitRepository(dirs['repo']) >>> repo._cmd_has_feature("commit", "a") True >>> repo._cmd_has_feature("commit", "reuse-message") True >>> repo._cmd_has_feature("merge", "n") True >>> repo._cmd_has_feature("merge", "stat") True >>> repo._cmd_has_feature("format-patch", "cc") True >>> repo._cmd_has_feature("merge", "foobaroption") False >>> repo._cmd_has_feature("foobarcmd", "foobaroption") Traceback (most recent call last): ... gbp.git.repository.GitRepositoryError: Invalid git command 'foobarcmd': No manual entry for gitfoobarcmd >>> repo._cmd_has_feature("show", "standard-notes") True >>> repo._cmd_has_feature("show", "no-standard-notes") True
Create a repository
Methods tested:
Properties tested:
>>> import os, gbp.git >>> repo = gbp.git.GitRepository.create(dirs['repo']) >>> repo.path == dirs['repo'] True >>> repo.git_dir == os.path.join(dirs['repo'], '.git') True >>> type(repo) == gbp.git.GitRepository True
Create a bare repository
Methods tested:
>>> import gbp.git >>> bare = gbp.git.GitRepository.create(dirs['bare'], bare=True, description="msg") >>> bare.path == dirs['bare'] True >>> bare.git_dir == dirs['bare'] True >>> type(bare) == gbp.git.GitRepository True >>> bare.is_empty() True >>> bare.is_clean() (True, '')
Create a branch name foo
Methods tested:
>>> import gbp.git, shutil >>> repo = gbp.git.GitRepository(dirs['repo']) >>> repo.create_branch("foo") >>> repo.branch_contains("foo", 'HEAD') True >>> repo.branch_contains("doesnotexist", 'HEAD', remote=True) False
Check that creating a repository at a path that isn't writeable fails
Methods tested:
>>> import gbp.git >>> gbp.git.GitRepository.create("/does/not/exist") Traceback (most recent call last): ... gbp.git.repository.GitRepositoryError: Cannot create Git repository at '/does/not/exist': [Errno 13] Permission denied: '/does'
Create a branch named foo2 and delete it
Methods tested:
>>> import gbp.git, shutil >>> repo = gbp.git.GitRepository(dirs['repo']) >>> repo.create_branch("bar") >>> repo.delete_branch("bar") >>> repo.delete_branch("master") Traceback (most recent call last): ... gbp.git.repository.GitRepositoryError: Can't delete the branch you're on
Delete tags
Methods tested:
>>> import gbp.git >>> repo = gbp.git.GitRepository(dirs['repo']) >>> repo.has_tag("moved") True >>> repo.delete_tag("moved") >>> repo.has_tag("moved") False
Describe commit-ish
Methods tested:
>>> import gbp.git >>> repo = gbp.git.GitRepository(dirs['repo']) >>> sha = repo.rev_parse('HEAD') >>> repo.describe('HEAD') 'tag2' >>> repo.describe('HEAD', longfmt=True) == 'tag2-0-g%s' % sha[:7] True >>> repo.describe('HEAD', pattern='foo*') Traceback (most recent call last): ... gbp.git.repository.GitRepositoryError: Can't describe HEAD. Git error: fatal: No names found, cannot describe anything. >>> repo.describe('HEAD', pattern='foo*', always=True) == sha[:7] True >>> repo.describe('HEAD', always=True, abbrev=16) 'tag2' >>> repo.describe('HEAD', pattern='foo*', always=True, abbrev=16) == sha[:16] True >>> tag = repo.describe('HEAD', longfmt=True, abbrev=16) == 'tag2-0-g%s' % sha[:16] >>> repo.delete_tag('tag2') >>> repo.describe('HEAD', tags=True) 'tag' >>> repo.describe('HEAD', tags=True, exact_match=True) 'tag' >>> repo.create_tag('tag2', msg='foo')
Test git-diff
Methods tested:
>>> import gbp.git >>> repo = gbp.git.GitRepository(dirs['repo']) >>> len(repo.diff('HEAD~1', 'HEAD')) > 3 True >>> len(repo.diff('HEAD~1', 'HEAD', 'testfile')) > 3 True >>> len(repo.diff('HEAD~1', 'HEAD', 'testfile', text=True)) > 3 True >>> len(repo.diff('HEAD~1', 'HEAD', 'filenotexist')) == 0 True >>> repo.diff('HEAD~1', 'HEAD') == repo.diff('HEAD~1') True
Methods tested:
>>> import gbp.git >>> repo = gbp.git.GitRepository(dirs['repo']) >>> repo.diff_status("HEAD", "HEAD") defaultdict(<class 'list'>, {}) >>> repo.diff_status("HEAD~1", "HEAD") defaultdict(<class 'list'>, {'M': [b'testfile']})
Empty repos have no branch
Methods tested:
>>> import gbp.git >>> repo = gbp.git.GitRepository(dirs['repo']) >>> repo.get_branch() >>> repo.branch >>> repo.is_empty() True
Fetch from a remote repository
Methods tested:
gbp.git.GitRepository.fetch
gbp.git.GitRepository.push
gbp.git.GitRepository.push_tag
gbp.git.GitRepository.add_remote_repo
gbp.git.GitRepository.remove_remote_repo
>>> import gbp.git, os >>> d = os.path.join(dirs['clone'], 'repo') >>> clone = gbp.git.GitRepository(d) >>> clone.fetch() >>> clone.push() >>> clone.push('origin', dry_run=True) >>> clone.push('origin') >>> clone.push('origin', 'master') >>> clone.push('origin', 'master', force=True) >>> clone.create_tag('tag3') >>> clone.push_tag('origin', 'tag3', True) >>> clone.push_tag('origin', 'tag3') >>> clone.create_tag('tag4') >>> clone.push('origin', 'master', tags=True) >>> clone.add_remote_repo('foo', dirs['repo']) >>> clone.fetch('foo') >>> clone.fetch('foo', tags=True) >>> clone.fetch('foo', refspec='refs/heads/master') >>> clone.fetch(all_remotes=True) >>> clone.remove_remote_repo('foo')
Find the closest tags on a certain branch to a given commit
Methods tested:
>>> import gbp.git >>> repo = gbp.git.GitRepository(dirs['repo']) >>> repo.find_branch_tag('HEAD', 'master', 'tag*') 'tag2' >>> repo.find_branch_tag('HEAD', 'master', 'v*') # doctest:+ELLIPSIS Traceback (most recent call last): ... gbp.git.repository.GitRepositoryError: Can't describe .... Git error: fatal: No names found, cannot describe anything.
Find tags
Methods tested:
>>> import gbp.git >>> repo = gbp.git.GitRepository(dirs['repo']) >>> repo.find_tag('HEAD') 'tag2' >>> repo.find_tag('HEAD', pattern='foo*') Traceback (most recent call last): ... gbp.git.repository.GitRepositoryError: Can't describe HEAD. Git error: fatal: No names found, cannot describe anything.
Test garbage collection
Methods tested:
>>> import gbp.git >>> repo = gbp.git.GitRepository(dirs['repo']) >>> repo.collect_garbage() >>> repo.collect_garbage(prune=True) >>> repo.collect_garbage(prune='all', aggressive=True)
Test inspecting commits
Methods tested:
>>> import gbp.git >>> from datetime import datetime >>> repo = gbp.git.GitRepository(dirs['repo']) >>> info = repo.get_commit_info('HEAD') >>> info['id'] 'HEAD' >>> info['body'] '' >>> info['subject'] 'foo' >>> '@' in info['author'].email True >>> '@' in info['committer'].email True >>> now = datetime.now() >>> (now - datetime.fromtimestamp(int(info['author'].date.split()[0]))).seconds < 10 True >>> (now - datetime.fromtimestamp(int(info['committer'].date.split()[0]))).seconds < 10 True >>> info['patchname'] 'foo' >>> info['files'] # doctest:+ELLIPSIS defaultdict(<class 'list'>, {'M': [b'testfile']}) >>> repo.get_subject('HEAD') 'foo'
Test listing commits
Methods tested:
>>> import gbp.git >>> repo = gbp.git.GitRepository(dirs['repo']) >>> commits = repo.get_commits() >>> type(commits) == list and len(commits) == 2 True >>> len(repo.get_commits(num=1)) == 1 True >>> commits2 = repo.get_commits(since='HEAD~1') >>> len(commits2) == 1 True >>> commits2[0] == commits[0] True >>> commits2 = repo.get_commits(until='HEAD~1') >>> len(commits2) == 1 True >>> commits2[0] == commits[-1] True >>> repo.get_commits(paths=['foo', 'bar']) [] >>> repo.get_commits(paths=['testfile']) == commits True
Find the common ancestor of two objects
Methods tested:
>>> import gbp.git >>> repo = gbp.git.GitRepository(dirs['repo']) >>> sha1 = repo.get_merge_base('master', 'foo') >>> len(sha1) 40 >>> repo.get_merge_base('master', 'doesnotexist') Traceback (most recent call last): ... gbp.git.repository.GitRepositoryError: Failed to get common ancestor: fatal: Not a valid object name doesnotexist
Find commit SHA1 related to tags
Methods tested:
gbp.git.GitRepository.create_tag
gbp.git.GitRepository.get_obj_type
gbp.git.GitRepository.delete_tag
>>> import gbp.git >>> repo = gbp.git.GitRepository(dirs['repo']) >>> repo.create_tag("tag3", "tag msg") >>> repo.get_obj_type("tag3") 'tag' >>> repo.get_obj_type("HEAD") 'commit' >>> repo.get_obj_type("HEAD:testfile") 'blob' >>> repo.delete_tag("tag3")
Check remotes
Methods tested:
>>> import os >>> import gbp.git.repository >>> repo = gbp.git.repository.GitRepository(os.path.join(dirs['clone'], 'repo')) >>> remotes = repo.get_remotes() >>> len(remotes) 1 >>> origin = remotes['origin'] >>> origin.name 'origin' >>> origin.fetch_url == dirs['repo'] True >>> origin.push_urls == [dirs['repo']] True
Get info about upstream branches set in test_set_upstream_branch
>>> import gbp.git >>> repo = gbp.git.GitRepository(dirs['repo']) >>> repo.get_upstream_branch('master') 'origin/master' >>> repo.get_upstream_branch('foo') '' >>> repo.get_upstream_branch('bla') Traceback (most recent call last): gbp.git.repository.GitRepositoryError: Branch bla doesn't exist!
Properties tested:
>>> import os, gbp.git >>> git_dir = os.path.join(dirs['repo'], '.git') >>> os.environ['GIT_DIR'] = git_dir >>> somewhere = gbp.git.GitRepository(os.path.join(dirs['repo'], '..')) >>> somewhere.git_dir == git_dir True >>> del os.environ['GIT_DIR']
Test grepping through commit messages
Methods tested:
>>> import gbp.git >>> repo = gbp.git.GitRepository(dirs['repo']) >>> repo.set_branch('master') >>> len(repo.grep_log('foo')) == 2 True >>> len(repo.grep_log('foo', 'master')) == 2 True >>> repo.grep_log('blafasel') [] >>> repo.grep_log('foo', 'doesnotexist') Traceback (most recent call last): ... gbp.git.repository.GitRepositoryError: Error grepping log for foo: fatal: bad revision 'doesnotexist'
Test if branch is fast forwardable
Methods tested:
>>> import gbp.git >>> repo = gbp.git.GitRepository(dirs['repo']) >>> repo.is_fast_forward('master', 'foo') (True, True) >>> repo.create_branch('ff', 'HEAD^') >>> repo.is_fast_forward('ff', 'master') (True, False) >>> repo.is_fast_forward('master', 'ff') (False, True)
List files in the index
Methods tested:
gbp.git.GitRepository.list_files
gbp.git.GitRepository.add_files
gbp.git.GitRepository.commit_staged
gbp.git.GitRepository.commit_files
gbp.git.GitRepository.force_head
>>> import gbp.git, os, shutil >>> repo = gbp.git.GitRepository(dirs['repo']) >>> src = os.path.join(repo.path, ".git/HEAD") >>> dst = os.path.join(repo.path, "testfile") >>> repo.list_files() [b'testfile'] >>> repo.list_files(['modified']) [] >>> repo.list_files(['modified', 'deleted']) [] >>> repo.list_files(['modified', 'deleted', 'cached']) [b'testfile'] >>> ret = shutil.copy(src, dst) >>> repo.list_files(['modified']) [b'testfile'] >>> repo.add_files(dst) >>> repo.commit_staged(msg="foo") >>> repo.list_files(['modified']) [] >>> repo.list_files(['foo']) Traceback (most recent call last): ... gbp.git.repository.GitRepositoryError: Unknown type 'foo' >>> repo.force_head('HEAD^', hard=True) >>> repo.list_files(['modified']) [] >>> ret = shutil.copy(src, dst) >>> repo.list_files(['modified']) [b'testfile'] >>> repo.commit_files(dst, msg="foo") >>> repo.list_files(['modified']) []
Test git-mk-tree
Methods tested:
>>> import gbp.git >>> repo = gbp.git.GitRepository(dirs['repo']) >>> sha1 = repo.write_file('testfile') >>> sha1 '19af7398c894bc5e86e17259317e4db519e9241f' >>> head = list(repo.list_tree('HEAD')) >>> head [('100644', 'blob', '19af7398c894bc5e86e17259317e4db519e9241f', b'testfile')] >>> head.append(['100644', 'blob', '19af7398c894bc5e86e17259317e4db519e9241f', 'testfile2']) >>> newtree = repo.make_tree(head) >>> newtree '745951810c9e22fcc6de9b23f05efd6ab5512123' >>> list(repo.list_tree(newtree, recurse=False, paths='testfile')) [('100644', 'blob', '19af7398c894bc5e86e17259317e4db519e9241f', b'testfile')] >>> list(repo.list_tree(newtree, recurse=False, paths='testfile', sizes=True)) [('100644', 'blob', '19af7398c894bc5e86e17259317e4db519e9241f', 20, b'testfile')] >>> repo.make_tree([]) '4b825dc642cb6eb9a060e54bf8d69288fbee4904'
Merge a branch
Methods tested:
>>> import gbp.git >>> repo = gbp.git.GitRepository(dirs['repo']) >>> repo.set_branch('master') >>> repo.merge('foo') >>> repo.is_in_merge() False
Mirror a repository
Methods tested:
gbp.git.GitRepository.clone
gbp.git.GitRepository.is_empty
gbp.git.GitRepository.set_branch
gbp.git.GitRepository.has_branch
gbp.git.GitRepository.branch
>>> import gbp.git >>> repo = gbp.git.GitRepository(dirs['repo']) >>> repo.set_branch('master') >>> repo.branch 'master' >>> mirror = gbp.git.GitRepository.clone(dirs['mirror_clone'], repo.path, mirror=True) >>> mirror.is_empty() False >>> mirror.branch 'master' >>> mirror.has_branch('foo') True >>> mirror.has_branch('bar') False >>> mirror.set_branch('foo') >>> mirror.branch 'foo' >>> mirror.force_head('foo^')
Move a tag
Methods tested:
>>> import gbp.git >>> repo = gbp.git.GitRepository(dirs['repo']) >>> repo.move_tag("tag", "moved") >>> repo.has_tag("tag") False >>> repo.has_tag("moved") True
Check that accessing a non-existent repository fails.
Methods tested:
>>> import gbp.git >>> bare = gbp.git.GitRepository("/does/not/exist") Traceback (most recent call last): ... gbp.git.repository.GitRepositoryError: No Git repository at '/does/not/exist'
Pull from a remote repository
Methods tested:
>>> import gbp.git, os >>> d = os.path.join(dirs['clone'], 'repo') >>> clone = gbp.git.GitRepository(d) >>> clone.set_branch('master') >>> clone.pull() >>> clone.pull(all_remotes=True) >>> clone.pull('origin', all_remotes=True)
Create branch named baz, rename it to bax and finally delete it
Methods tested:
gbp.git.GitRepository.create_branch
gbp.git.GitRepository.rename_branch
gbp.git.GitRepository.delete_branch
>>> import gbp.git >>> repo = gbp.git.GitRepository(dirs['repo']) >>> repo.create_branch("baz") >>> repo.rename_branch("baz", "bax") >>> repo.delete_branch("bax")
Methods tested:
>>> import gbp.git >>> repo = gbp.git.GitRepository(dirs['repo']) >>> repo.rename_file("testfile", "testfile2") >>> repo.rename_file("testfile2", "testfile") >>> repo.rename_file("doesnotexit", "testfile2") Traceback (most recent call last): ... gbp.errors.GbpError: Failed to move 'doesnotexit' to 'testfile2': fatal: bad source, source=doesnotexit, destination=testfile2
Switch to branch named foo
Methods tested:
>>> import gbp.git >>> repo = gbp.git.GitRepository(dirs['repo']) >>> repo.set_branch("foo") >>> repo.get_branch() == "foo" True >>> repo.branch == "foo" True
Methods tested:
>>> import gbp.git >>> repo = gbp.git.GitRepository(dirs['repo']) >>> repo.set_config("user.email", "foo@example.com") >>> repo.get_config("user.email") 'foo@example.com'
Set upstream branch master -> origin/master
>>> import os, shutil >>> import gbp.git >>> repo = gbp.git.GitRepository(dirs['repo']) >>> os.makedirs(os.path.join(repo.git_dir, 'refs/remotes/origin')) >>> ret = shutil.copy(os.path.join(repo.git_dir, 'refs/heads/master'), os.path.join(repo.git_dir, 'refs/remotes/origin/')) >>> repo.add_remote_repo('origin', 'git://git.example.com/git/origin') >>> repo.set_upstream_branch('master', 'origin/master') >>> repo.get_upstream_branch('master') 'origin/master' >>> repo.set_upstream_branch('bla', 'origin/master') Traceback (most recent call last): gbp.git.repository.GitRepositoryError: Branch bla doesn't exist! >>> repo.set_upstream_branch('foo', 'origin/bla') Traceback (most recent call last): gbp.git.repository.GitRepositoryError: Branch origin/bla doesn't exist!
Methods tested:
>>> import gbp.git >>> repo = gbp.git.GitRepository(dirs['repo']) >>> repo.set_user_name("Michael Stapelberg") >>> repo.set_user_email("stapelberg@test.invalid")
Methods tested:
>>> import gbp.git, os, shutil >>> repo = gbp.git.GitRepository(dirs['repo']) >>> fname = os.path.join(repo.path, "test_status") >>> ret = shutil.copy(os.path.join(repo.path, ".git/HEAD"), fname) >>> list(repo.status().items()) [('??', [b'test_status'])] >>> list(repo.status(['bla*']).items()) [] >>> list(repo.status(['te*']).items()) [('??', [b'test_status'])] >>> repo.add_files(repo.path, force=True) >>> repo.commit_all(msg='added %s' % fname) >>> _ = repo._git_inout('mv', [fname, fname + 'new']) >>> list(repo.status().items()) [('R ', [b'test_status\x00test_statusnew'])]
Make surewe can init repos from a subdir >>> import gbp.git, os >>> os.mkdir(os.path.join(dirs['repo'], 'subdir')) >>> repo = gbp.git.GitRepository(os.path.join(dirs['repo'], 'subdir'), toplevel=False) >>> repo.path == dirs['repo'] True >>> repo = gbp.git.GitRepository(os.path.join(dirs['repo'], 'subdir'), toplevel=True) # doctest:+ELLIPSIS Traceback (most recent call last): ... gbp.git.repository.GitRepositoryError: Not the toplevel of a Git repository at ...
Create a tag named tag and check its existance
Methods tested:
gbp.git.GitRepository.create_tag
gbp.git.GitRepository.verify_tag
gbp.git.GitRepository.has_tag
gbp.git.GitRepository.get_tags
>>> import gbp.git >>> repo = gbp.git.GitRepository(dirs['repo']) >>> repo.create_tag("tag") >>> repo.has_tag("tag") True >>> repo.has_tag("unknown") False >>> repo.create_tag("tag2", msg="foo") >>> repo.has_tag("tag2") True >>> repo.verify_tag("tag2") False >>> repo.get_tags() ['tag', 'tag2'] >>> repo.tags ['tag', 'tag2']
Test updating a reference
Methods tested:
>>> import gbp.git, os >>> repo = gbp.git.GitRepository(dirs['repo']) >>> repo.update_ref('new_ref', 'master', msg='update') >>> os.path.exists(os.path.join(repo.git_dir, 'new_ref')) True