def test_transaction_set_simple(): tmp = util.maketemp() storage.git_init(tmp) storage.init(tmp) orig_head = storage.git_rev_parse( rev='bugit/HEAD', repo=tmp, ) with storage.Transaction(repo=tmp) as t: t.set( 'f3da69cd9eca7a69ed72a4edf2d65c84e83b0411/xyzzy', 'mockdata\n', ) got = storage.get( path='f3da69cd9eca7a69ed72a4edf2d65c84e83b0411/xyzzy', repo=tmp, ) eq(got, 'mockdata\n') parent = storage.git_rev_parse( rev='bugit/HEAD^1', repo=tmp, ) eq(orig_head, parent) merge = storage.git_rev_parse( rev='bugit/HEAD^2', repo=tmp, ) eq(merge, None)
def test_editor_noop(): tmp = util.maketemp() storage.git_init(tmp) storage.init(tmp) orig_head = storage.git_rev_parse(rev="bugit/HEAD", repo=tmp) class FakeTTYFileDescription(object): def isatty(self): return True FAKE_EDITOR = os.path.join(os.path.dirname(__file__), "editor-that-does-nothing") result = util.clitest( args=["new"], environ=dict(BUGIT_EDITOR=FAKE_EDITOR), stdin=FakeTTYFileDescription(), allow_stderr=True, cwd=tmp ) result.check_stdout("") result.check_stderr( re.compile( r""" ^ bugit\ new:\ creating\ ticket\ ([0-9a-f]{40})\ \.\.\.\n bugit\ new:\ file\ was\ not\ changed,\ discarding\n $ """, re.VERBOSE, ) ) new_head = storage.git_rev_parse(rev="bugit/HEAD", repo=tmp) eq(orig_head, new_head)
def check_bugit_repository(repo): assert os.path.isdir(os.path.join(repo, '.git', 'bugit')) eq(os.listdir(os.path.join(repo, '.git', 'bugit')), ['HEAD']) sha = storage.git_rev_parse( rev='refs/heads/bugit/master', repo=repo, ) assert sha is not None process = subprocess.Popen( args=[ 'git', 'symbolic-ref', 'bugit/HEAD', ], cwd=repo, close_fds=True, stdout=subprocess.PIPE, ) got = process.stdout.read() returncode = process.wait() eq(returncode, 0) eq(got, 'refs/heads/bugit/master\n')
def test_editor_no_ticket(): tmp = util.maketemp() storage.git_init(tmp) storage.init(tmp) with storage.Transaction(repo=tmp) as t: t.set( '29d7ae1a7d7cefd4c79d095ac0e47636aa02d4a5/description', 'old', ) orig_head = storage.git_rev_parse( rev='bugit/HEAD', repo=tmp, ) TICKET = '29d7ae1a7d7cefd4c79d095ac0e47636aa02d4a5' class FakeTTYFileDescription(object): def isatty(self): return True FAKE_EDITOR = os.path.join( os.path.dirname(__file__), 'editor-that-does-nothing', ) result = util.clitest( args=[ 'edit', ], environ=dict( BUGIT_EDITOR=FAKE_EDITOR, ), stdin=FakeTTYFileDescription(), exit_status=1, allow_stderr=True, cwd=tmp, ) result.check_stdout('') result.check_stderr("""\ bugit edit: Missing ticket argument for interactive editing """) new_head = storage.git_rev_parse( rev='bugit/HEAD', repo=tmp, ) eq(orig_head, new_head) def list_tickets(): # TODO share me for (mode, type_, object, basename) in storage.git_ls_tree( path='', repo=tmp, children=True, ): yield basename got = list(list_tickets()) eq(got, [TICKET]) got = sorted(storage.ls( path=TICKET, repo=tmp, )) eq( got, sorted([ 'description', ]), ) got = storage.get( path=os.path.join(TICKET, 'description'), repo=tmp, ) # without explicit no-edit detection, this gets a newline appended eq(got, 'old')
def test_simple_stdin_ticketInStdin(): tmp = util.maketemp() storage.git_init(tmp) storage.init(tmp) with storage.Transaction(repo=tmp) as t: t.set( '29d7ae1a7d7cefd4c79d095ac0e47636aa02d4a5/description', 'old', ) orig_head = storage.git_rev_parse( rev='bugit/HEAD', repo=tmp, ) result = util.clitest( args=[ 'edit', ], stdin="""\ ticket 29d7ae1a7d7cefd4c79d095ac0e47636aa02d4a5 Frobbing is borked I ran frob and it was supposed to blarb, but it qwarked. """, cwd=tmp, allow_stderr=True, ) result.check_stdout('') result.check_stderr("""\ bugit edit: updating ticket 29d7ae1a7d7cefd4c79d095ac0e47636aa02d4a5 ... bugit edit: saved """) def list_tickets(): # TODO share me for (mode, type_, object, basename) in storage.git_ls_tree( path='', repo=tmp, children=True, ): yield basename got = list(list_tickets()) eq(got, ['29d7ae1a7d7cefd4c79d095ac0e47636aa02d4a5']) got = sorted(storage.ls( path='29d7ae1a7d7cefd4c79d095ac0e47636aa02d4a5', repo=tmp, )) eq( got, sorted([ 'description', #TODO 'tags/reporter:TODO' ]), ) got = storage.get( path=os.path.join( '29d7ae1a7d7cefd4c79d095ac0e47636aa02d4a5', 'description', ), repo=tmp, ) eq(got, """\ Frobbing is borked I ran frob and it was supposed to blarb, but it qwarked. """) process = subprocess.Popen( args=[ 'git', 'cat-file', 'commit', 'bugit/HEAD', ], cwd=tmp, close_fds=True, stdout=subprocess.PIPE, ) got = process.stdout.read() returncode = process.wait() eq(returncode, 0) m = re.match( r""" ^ tree\ [0-9a-f]{40}\n parent\ (?P<parent>[0-9a-f]{40})\n author\ [^\n]+\n committer\ [^\n]+\n \n Edited\ ticket\ (?P<ticket>[0-9a-f]{40})\n $ """, got, re.VERBOSE, ) assert m is not None, 'stdout does not match:\n%s' % got eq(m.group('parent'), orig_head) eq(m.group('ticket'), '29d7ae1a7d7cefd4c79d095ac0e47636aa02d4a5')