예제 #1
0
 def test_name(self):
     self.assertEqual(
         'bar', git_address_util.name('https://foohub.com/myproj/bar.git'))
     self.assertEqual('foo-bar-baz',
                      git_address_util.name('git@git:foo-bar-baz.git'))
     r = git_temp_repo(debug=self.DEBUG)
     self.assertEqual(path.basename(r.root), git_address_util.name(r.root))
예제 #2
0
    def test_tags(self):
        config = '''\
add commit1 commit1
  kiwi.txt: kiwi.txt
tag rel/1.0.0 tag1 @commit1
add commit2 commit2
  lemon.txt: lemon.txt
tag rel/1.0.1 tag2 @commit2
add commit3 commit3
  melon.txt: melon.txt
tag rel/1.0.2 tag3 @commit3
'''
        r = git_temp_repo(remote=True, config=config, debug=self.DEBUG)
        tmp_output_file = self.make_temp_file(suffix='.txt')
        args = [
            'git',
            'tags',
            '--root-dir',
            r.root,
            '--output',
            tmp_output_file,
            '--style',
            'brief',
        ]
        rv = self.run_program(self._program, args)
        self.assertEqual(0, rv.exit_code)
        self.assert_text_file_equal_fuzzy(
            '''\
rel/1.0.0
rel/1.0.1
rel/1.0.2
''', tmp_output_file)
예제 #3
0
  def test_one_script_with_dry_run(self):
    r = git_temp_repo(debug = self.DEBUG)
    if host.is_windows():
      script = self.native_filename('fruits/kiwi.bat')
      content = '''\
@echo off
echo {} %*
exit 0
'''.format(script)
    elif host.is_unix():
      script = self.native_filename('fruits/kiwi.sh')
      content = '''\
#!/bin/bash
echo {} ${{1+"$@"}}
exit 0
'''.format(script)
    else:
      assert False
    xp_script = self.native_filename(script)
    r.add_file(self.native_filename(xp_script), content, mode = 0o0755)
    r.push('origin', 'master')
    r.tag('1.0.0')
    r.push_tag('1.0.0')
    options = git_repo_script_options(dry_run = True)
    scripts = [
      git_util.script(xp_script, [ 'arg1', 'arg2' ]),
    ]
    rv = git_util.repo_run_scripts(r.address, scripts, options = options)
    self.assertEqual( [ None ], rv.results )
예제 #4
0
  def test_bump_tag_component_major_reset_lower(self):
    config = '''\
add commit1 commit1
  kiwi.txt: kiwi.txt
tag 1.0.1 tag1 @commit1
'''
    r = git_temp_repo(remote = True, debug = self.DEBUG)
    r.apply_config_text(config)
    args = [
      'git_repo',
      'bump_tag',
      '--component', 'major',
      '--reset-lower',
      r.root,
    ]
    rv = self.run_program(self._program, args)
    self.assertEqual(0, rv.exit_code)
    args = [
      'git_repo',
      'greatest_tag',
      r.root,
    ]
    rv = self.run_program(self._program, args)
    self.assertEqual(0, rv.exit_code)
    self.assertEqual( '2.0.0', rv.output.strip() )
예제 #5
0
    def test_conflict_retry(self):
        # Create a fresh repo with a master branch.
        repo = git_temp_repo(debug=self.DEBUG)
        repo.add_file('dummy.txt', 'dummy')
        repo.push('origin', 'master')

        #try_count = []

        from conflict_retry_worker import worker

        # This test runs numerous threads that all attempt to access the repository
        # at the same time. The repository code will only do 10 retries, so if you
        # try to do more than 9 jobs or so, updates will start to fail and the test
        # will not pass.
        num_jobs = 9
        jobs = []
        for i in range(num_jobs):
            p = multiprocessing.Process(target=worker,
                                        args=(i, repo.address, self.DEBUG))
            jobs.append(p)
            #try_count.append(0)
            p.start()

        for job in jobs:
            job.join()

        # Now get the file from the remote into the main thread's local repo and
        # check the results.
        repo.pull()
        contents = repo.read_file('retries.txt')
        actual = sorted(contents.split(line_break.DEFAULT_LINE_BREAK))
        expected = [str(n) for n in range(num_jobs)]
        self.assertEqual(actual, expected)
예제 #6
0
  def test_repo_status(self):

    NUM_REPOS = 9
    NUM_THREADS = 3

    options = git_repo_status_options(num_threads = NUM_THREADS)
    
    repos = []

    repo_index_map = {}
    
    for i in range(0, NUM_REPOS):
      config = '''\
add commit1 commit1
  kiwi{index}.txt: this is kiwi{index}.txt
add commit2 commit2
  lemon{index}.txt: this is lemon{index}.txt
'''.format(index = i)
      r = git_temp_repo(remote = True, debug = self.DEBUG, config = config, prefix = 'status')
      repos.append(r.repo)
      repo_index_map[r.repo] = i
        
    for item in git_status_getter.get_status(repos, options = options):
      repo = item.repo
      status = item.status
      index = repo_index_map[repo]
      self.assertEqual( 'master', status.active_branch )
      self.assertEqual( repo.last_commit_hash(), status.last_commit.commit_hash_long )
      self.assertEqual( 'add lemon{index}.txt'.format(index = index), status.last_commit.message )
      self.assertEqual( 'unittest', status.last_commit.author )
      self.assertEqual( '*****@*****.**', status.last_commit.email )
      self.assertEqual( False, status.last_commit.is_merge_commit )
      self.assertEqual( ( 0, 0 ), status.branch_status )
예제 #7
0
    def test_delete_tags(self):
        config = '''\
add commit1 commit1
  kiwi.txt: kiwi.txt
tag rel/1.0.0 tag1 @commit1
add commit2 commit2
  lemon.txt: lemon.txt
tag rel/1.0.1 tag2 @commit2
add commit3 commit3
  melon.txt: melon.txt
tag rel/1.0.2 tag3 @commit3
'''
        r = git_temp_repo(remote=True, config=config, debug=self.DEBUG)
        self.assertEqual(['rel/1.0.0', 'rel/1.0.1', 'rel/1.0.2'],
                         r.list_local_tags().names())
        self.assertEqual(['rel/1.0.0', 'rel/1.0.1', 'rel/1.0.2'],
                         r.list_remote_tags().names())
        args = [
            'git',
            'delete_tags',
            '--root-dir',
            r.root,
            'rel/1.0.1',
        ]
        rv = self.run_program(self._program, args)
        self.assertEqual(0, rv.exit_code)
        self.assertEqual(['rel/1.0.0', 'rel/1.0.2'],
                         r.list_local_tags().names())
        self.assertEqual(['rel/1.0.0', 'rel/1.0.2'],
                         r.list_remote_tags().names())
예제 #8
0
  def test_create_git_tgz(self):
    content = [ 
      'file a/b/c/foo.txt "foo content" 755',
      'file d/e/bar.txt "bar content" 644',
      'dir  baz     ""            700',
    ]
    r = git_temp_repo(content = content, prefix = 'test_archive_', debug = self.DEBUG)
    commit = r.last_commit_hash(short_hash = True)
    
    tmp_archive = self.make_temp_file(suffix = '.tgz')

    prefix = 'foo-{}'.format(commit)
    
    args = [
      'archive',
      'create_git',
      '--root-dir', r.root,
      '--format', 'tgz',
      prefix,
      commit,
      tmp_archive,
    ]
    rv = self.run_program(self._program, args)
    self.assertEqual( 0, rv.exit_code )
    self.assertEqual( 'tgz', archiver.format_name(tmp_archive) )
    expected = [
      '{}/a/b/c/foo.txt'.format(prefix),
      '{}/d/e/bar.txt'.format(prefix),
    ]
    actual = archiver.members(tmp_archive)
    self.assert_filename_list_equal( expected, actual )
예제 #9
0
    def test_basic(self):
        # This is the document to write to the repository.
        tmp_source_doc = self.make_temp_file(content='abc', suffix='-doc.txt')

        # Here's a repository to put it in.
        r = git_temp_repo(debug=self.DEBUG)
        r.add_file('dummy.txt', content='dummy')
        r.push('origin', 'master')

        tmp_db_dir = self.make_temp_dir()

        args = [
            'git_repo_document',
            'update',
            tmp_source_doc,
            r.address,
            'master',
            '--working-dir',
            tmp_db_dir,
        ]
        rv = self.run_program(self._program, args)
        self.assertEqual(0, rv.exit_code)

        # Also check doc is in repo. It will have the same name as the source doc.
        filename = path.basename(tmp_source_doc)
        r.pull()
        contents = r.read_file(filename)
        self.assertEqual(contents, 'abc')

        # Since we now have a file in the repo, let's also test whether load_document can read it.

        # Here's an auto-delete temp directory for the document DB's local repository.
        tmp_db_dir2 = temp_file.make_temp_dir(delete=not self.DEBUG)

        # By default, the CLI will put the output file in a file with the same name as the file in
        # the repo, in the current directory.
        tmp_target_filepath = path.join(getcwd(), filename)
        if path.exists(tmp_target_filepath):
            remove(tmp_target_filepath)

        # Run the CLI.
        args = [
            'git_repo_document',
            'load',
            filename,
            r.address,
            'master',
            '--working-dir',
            tmp_db_dir2,
        ]
        rv = self.run_program(self._program, args)
        self.assertEqual(0, rv.exit_code)

        # See if the file and contents are there.
        actual = file_util.read(tmp_target_filepath)
        self.assertEqual(actual, b'abc')

        # This will cause an exception and fail the test if the file wasn't created by the CLI.
        remove(tmp_target_filepath)
 def test_basic(self):
   r = git_temp_repo(debug = self.DEBUG)
   r.add_file('kiwi.txt', content = 'this is kiwi.txt', mode = 0o0644)
   r.push('origin', 'master')
   def _op(repo):
     r.add_file('melon.txt', content = 'this is melon.txt', mode = 0o0644,
                commit = False, push = False)
   git_util.repo_run_operation(r.address, _op, 'add melon.txt', options = None)
   self.assertEqual( 'this is melon.txt', r.read_file('melon.txt') )
예제 #11
0
 def test_parse_local_bare(self):
     items = [
         'file foo.txt "foo.txt"',
     ]
     r = git_temp_repo(remote=True,
                       content=items,
                       debug=self.DEBUG,
                       prefix='.repo')
     self.assertEqual(('bare_local', None, None, r.address),
                      git_remote.parse(r.address))
예제 #12
0
 def _make_repo(self,
                remote=True,
                content=None,
                prefix=None,
                commit_message=None):
     return git_temp_repo(remote=remote,
                          content=content,
                          prefix=prefix,
                          debug=self.DEBUG,
                          commit_message=commit_message)
예제 #13
0
 def _make_test_repo(clazz):
     repo = git_temp_repo(debug=clazz.DEBUG)
     src_dir = path.normpath(
         path.join(path.dirname(__file__), '../../../../bes_bash'))
     dst_dir = path.join(repo.root, 'bash/bes_bash_one_file')
     tar_util.copy_tree(src_dir, dst_dir)
     repo.add(['bash'])
     repo.commit('add', ['bash'])
     repo.push('-u', 'origin', 'master')
     return repo
예제 #14
0
    def test_apply_config_text(self):
        config = '''\
file something.txt
  content: this is my content
           it can be multi line
           or not
  perm: 644

add commit1 commit1
  foo.txt: this is a multi line
           content
  subdir/bar.txt: this is subdir/bar.txt
  scripts/go.sh[perm=655]: \\#!/bin/bash
                           echo hello
                           exit 0
  copy_of_something1.txt: @something.txt
  copy_of_something2.txt: @something.txt
  message: first commit

tag rel/1.0.0 tag1
  from_commit: @commit1

tag rel/1.0.1 tag2
  from_commit: @commit1
  annotation: first release

branch b1 b1 
  start_point: @commit1
  
branch b2 b2
  start_point: b1

remove remove1
  filename: copy_of_something1.txt
'''

        r = git_temp_repo(remote=True)
        self.assertEqual([], r.find_all_files())
        r.apply_config_text(config)
        self.assertEqual(
            self.native_filename_list([
                'copy_of_something2.txt',
                'foo.txt',
                'scripts/go.sh',
                'subdir/bar.txt',
            ]), r.find_all_files())

        expected = '''\
this is my content
it can be multi line
or not'''
        self.assert_text_file_equal(expected,
                                    r.file_path('copy_of_something2.txt'),
                                    codec='utf-8',
                                    native_line_breaks=True)
 def test_basic_dry_run(self):
   r = git_temp_repo(debug = self.DEBUG)
   r.add_file('kiwi.txt', content = 'this is kiwi.txt', mode = 0o0644)
   r.push('origin', 'master')
   def _op(repo):
     r.add_file('melon.txt', content = 'this is melon.txt', mode = 0o0644,
                commit = False, push = False)
   options = git_repo_operation_options(dry_run = True)
   git_util.repo_run_operation(r.address, _op, 'add melon.txt', options = options)
   r.pull()
   self.assertFalse( r.has_file('melon.txt') )
예제 #16
0
 def test_remote_print(self):
     r = git_temp_repo(remote=True)
     args = [
         'git',
         'remote_print',
         '--root-dir',
         r.root,
     ]
     rv = self.run_program(self._program, args)
     self.assertEqual(0, rv.exit_code)
     self.assertEqual(r.address, rv.output.strip())
예제 #17
0
  def test_many_scripts_with_push(self):
    r1 = git_temp_repo(debug = self.DEBUG)
    if host.is_windows():
      script1 = self.native_filename('scripts/script1.bat')
      script2 = self.native_filename('scripts/script2.bat')
      content1 = '''\
@echo off
echo %1% > color.txt
git add color.txt
git commit -madd color.txt
exit 0
'''
      content2 = '''\
@echo off
echo %1% > fruit.txt
git add fruit.txt
git commit -madd fruit.txt
exit 0
'''
    elif host.is_unix():
      script1 = self.native_filename('scripts/script1.sh')
      script2 = self.native_filename('scripts/script2.sh')
      content1 = '''\
#!/bin/bash
echo ${1} > color.txt
git add color.txt
git commit -madd color.txt
exit 0
'''
      content2 = '''\
#!/bin/bash
echo ${1} > fruit.txt
git add fruit.txt
git commit -madd fruit.txt
exit 0
'''
    else:
      assert False
    r1.add_file(script1, content1, mode = 0o0755)
    r1.add_file(script2, content2, mode = 0o0755)
    r1.push('origin', 'master')
    r1.tag('1.0.0')
    r1.push_tag('1.0.0')
    scripts = [
      git_util.script(script1, [ 'yellow' ]),
      git_util.script(script2, [ 'kiwi' ]),
    ]
    options = git_repo_script_options(push = True)
    rv = git_util.repo_run_scripts(r1.address, scripts, options = options)

    r2 = r1.make_temp_cloned_repo()
    self.assertEqual( 'yellow', r2.read_file('color.txt').strip() )
    self.assertEqual( 'kiwi', r2.read_file('fruit.txt').strip() )
예제 #18
0
  def test_push_conflict(self):
    r1 = git_temp_repo(debug = self.DEBUG)
    if host.is_windows():
      script = self.native_filename('fruits/kiwi.bat')
      content = '''\
@echo off
echo %1 > %1
git add %1
git commit -m"add %1" %1
exit 0
'''
    elif host.is_unix():
      script = self.native_filename('fruits/kiwi.sh')
      content = '''\
#!/bin/bash
echo ${1} > ${1}
git add ${1}
git commit -m"add ${1}" ${1}
exit 0
'''
    else:
      assert False
    xp_script = self.native_filename(script)
    r1.add_file(self.native_filename(xp_script), content, mode = 0o0755)
    r1.push('origin', 'master')

    jobs = []
    for fruit in self._FRUITS:
      p = multiprocessing.Process(target = self._worker_test_push_conflict, args = ( fruit, r1.address, xp_script ) )
      jobs.append(p)
      p.start()

    for job in jobs:
      job.join()

    r2 = git_repo(self.make_temp_dir(), address = r1.address)
    r2.clone_or_pull()

    self.assertEqual( {
      xp_script, 
      'apple',
      'blueberry',
      'kiwi',
      'lemon',
      'melon',
      'orange',
      'papaya',
      'pineapple',
      'watermelon',
    }, set(r2.find_all_files()) )

    '''
예제 #19
0
    def test_remote_replace(self):
        new_url = git_temp_repo(remote=True, debug=self.DEBUG).address
        r = git_temp_repo(remote=True, debug=self.DEBUG)
        args = [
            'git',
            'remote_replace',
            '--root-dir',
            r.root,
            new_url,
        ]
        rv = self.run_program(self._program, args)
        self.assertEqual(0, rv.exit_code)

        args = [
            'git',
            'remote_print',
            '--root-dir',
            r.root,
        ]
        rv = self.run_program(self._program, args)
        self.assertEqual(0, rv.exit_code)
        self.assert_filename_equal(new_url, rv.output.strip())
예제 #20
0
    def test_the_basics(self):
        # Create an empty temporary repo for the test. You've got to add a
        # dummy file, otherwise the push won't work and the master branch won't
        # be created. add_file does the commit.
        repo = git_temp_repo(debug=self.DEBUG)
        repo.add_file('dummy.txt', 'dummy')
        repo.push('origin', 'master')
        tmp_working_dir = self.make_temp_dir()

        # Set up the test DB.
        db = git_repo_document_db(tmp_working_dir, repo.address, 'master')

        # Use the DB to store a change to the file.
        db.update_document('testdoc.txt', lambda content: content + 'a\n',
                           'test commit message')

        # Now retrieve what we stored.
        content = db.load_document('testdoc.txt')
        self.assertEqual(content, 'a\n')

        # And check that the file really exists via the repo interface and has the
        # content in it. The repo file side effect is part of the contract.
        repo.pull()
        self.assert_text_file_equal('a',
                                    repo.file_path('testdoc.txt'),
                                    codec='utf-8',
                                    strip=True,
                                    native_line_breaks=True)

        # Now modify the file further and retrieve it again.
        db.update_document('testdoc.txt', lambda content: content + 'b\n',
                           'test commit message 2')
        expected = '''\
a
b
'''
        repo.pull()
        self.assert_string_equal(expected,
                                 db.load_document('testdoc.txt'),
                                 strip=True,
                                 native_line_breaks=True)

        # Try replacing everything.
        db.update_document('testdoc.txt', lambda content: 'foo',
                           'test commit message 3')
        content = db.load_document('testdoc.txt')
        self.assertEqual(content, 'foo')
        repo.pull()
        self.assertEqual('foo', repo.read_file('testdoc.txt'))
예제 #21
0
    def test_simple(self):
        r1 = git_temp_repo(debug=self.DEBUG)
        r1.add_file('coconut', 'coconut')
        r1.push('origin', 'master')

        r2 = git_repo(self.make_temp_dir(), address=r1.address)
        r2.clone_or_pull()
        r2.add_file('kiwi', 'kiwi')
        r1.add_file('lemon', 'lemon')
        r1.push()
        r2.push_with_rebase()

        r3 = git_repo(self.make_temp_dir(), address=r1.address)
        r3.clone_or_pull()
        self.assertEqual(['coconut', 'kiwi', 'lemon'], r3.find_all_files())
예제 #22
0
  def xtest_list_dir_persistent(self):
    items = [
      'file foo.txt "foo.txt"',
    ]
    r = git_temp_repo(remote = True, content = items, debug = self.DEBUG, prefix = '.repo')
    config_dir1 = self.make_temp_dir(suffix = '.config.dir')
    fs = vfs_git_repo(r.address, config_dir1, False)
    t = vfs_tester(fs)
    self.assertEqual( 'foo.txt file 7 ddab29ff2c393ee52855d21a240eb05f775df88e3ce347df759f0c4b80356c35\n',
                      t.list_dir('/', False, tester.OPTIONS) )
    r.add_file('bar.txt', 'bar.txt')
    r.push()
    config_dir2 = self.make_temp_dir(suffix = '.config.dir')
    fs = vfs_git_repo(r.address, config_dir2, False)
    t = vfs_tester(fs)
    expected = '''\
bar.txt file 7 08bd2d247cc7aa38b8c4b7fd20ee7edad0b593c3debce92f595c9d016da40bae
foo.txt file 7 ddab29ff2c393ee52855d21a240eb05f775df88e3ce347df759f0c4b80356c35
'''
    self.assertEqual( expected, t.list_dir('/', False, tester.OPTIONS) )
예제 #23
0
    def test_tag(self):
        config = '''\
add commit1 commit1
  kiwi.txt: kiwi.txt
tag 1.0.0 tag1 @commit1
'''
        r = git_temp_repo(remote=True, config=config, debug=self.DEBUG)
        self.assertEqual('1.0.0', r.greatest_local_tag().name)
        args = [
            'git',
            'tag',
            '--root-dir',
            r.root,
        ]
        rv = self.run_program(self._program, args)
        self.assertEqual(0, rv.exit_code)
        self.assert_string_equal_fuzzy('''\
local: 1.0.0
remote: 1.0.0
''', rv.output)
예제 #24
0
  def test_greatest_tag(self):
    config = '''\
add commit1 commit1
  kiwi.txt: kiwi.txt
tag rel/1.0.0 tag1 @commit1
add commit2 commit2
  lemon.txt: lemon.txt
tag rel/1.0.1 tag2 @commit2
add commit3 commit3
  melon.txt: melon.txt
tag rel/1.0.2 tag3 @commit3
'''
    r = git_temp_repo(remote = True, debug = self.DEBUG)
    r.apply_config_text(config)
    args = [
      'git_repo',
      'greatest_tag',
      r.root,
    ]
    rv = self.run_program(self._program, args)
    self.assertEqual(0, rv.exit_code)
    self.assertEqual( 'rel/1.0.2', rv.output.strip() )
예제 #25
0
    def test_bump_tag_with_prefix(self):
        config = '''\
add commit1 commit1
  kiwi.txt: kiwi.txt
tag rel/v2/1.0.0 tag1 @commit1
add commit2 commit2
  lemon.txt: lemon.txt
tag rel/v2/1.0.1 tag2 @commit2
add commit3 commit3
  melon.txt: melon.txt
tag rel/v2/1.0.2 tag3 @commit3
add commit4 commit4
  potato.txt: potato.txt
tag test/v3/1.0.0 tag4 @commit4
tag test/v3/1.0.1 tag5 @commit4
'''
        r = git_temp_repo(remote=True, config=config, debug=self.DEBUG)
        args = [
            'git',
            'bump_tag',
            '--root-dir',
            r.root,
            '--component',
            'revision',
            '--prefix',
            'rel/v2/',
        ]
        self.assertEqual('rel/v2/1.0.2',
                         r.greatest_local_tag(prefix='rel/v2/').name)
        self.assertEqual('test/v3/1.0.1',
                         r.greatest_local_tag(prefix='test/v3/').name)

        rv = self.run_program(self._program, args)
        self.assertEqual(0, rv.exit_code)

        self.assertEqual('rel/v2/1.0.3',
                         r.greatest_local_tag(prefix='rel/v2/').name)
        self.assertEqual('test/v3/1.0.1',
                         r.greatest_local_tag(prefix='test/v3/').name)
예제 #26
0
  def test_one_script_with_bump_tag(self):
    r1 = git_temp_repo(debug = self.DEBUG)
    if host.is_windows():
      script = 'nothing.bat'
      content = '''\
@echo off
exit 0
'''.format(script)
    elif host.is_unix():
      script = './nothing.sh'
      content = '''\
#!/bin/bash
exit 0
'''.format(script)
    else:
      assert False
    xp_script = self.native_filename(script)
    r1.add_file(xp_script, content, mode = 0o0755)
    r1.push('origin', 'master')
    r1.tag('1.0.0')
    r1.push_tag('1.0.0')
    options = git_repo_script_options(bump_tag_component = 'revision')
    scripts = [
      git_util.script(xp_script, []),
    ]
    rv = git_util.repo_run_scripts(r1.address, scripts, options = options)
    self.assertEqual( 1, len(rv.results) )

    r2 = r1.make_temp_cloned_repo()
    self.assertEqual( '1.0.1', r2.greatest_local_tag().name )

    options = git_repo_script_options(bump_tag_component = 'major')
    scripts = [
      git_util.script(xp_script, []),
    ]
    rv = git_util.repo_run_scripts(r1.address, scripts, options = options)
    self.assertEqual( 1, len(rv.results) )
    self.assertEqual( '2.0.1', r2.greatest_remote_tag().name )
예제 #27
0
  def test_bump_tag(self):
    config = '''\
add commit1 commit1
  kiwi.txt: kiwi.txt
tag 1.0.0 tag1 @commit1
'''
    r = git_temp_repo(remote = True, debug = self.DEBUG)
    r.apply_config_text(config)
    args = [
      'git_repo',
      'bump_tag',
      r.root,
    ]
    rv = self.run_program(self._program, args)
    self.assertEqual(0, rv.exit_code)
    args = [
      'git_repo',
      'greatest_tag',
      r.root,
    ]
    rv = self.run_program(self._program, args)
    self.assertEqual(0, rv.exit_code)
    self.assertEqual( '1.0.1', rv.output.strip() )
예제 #28
0
  def test_sync(self):
    config = '''\
add commit1 commit1
  kiwi.txt: kiwi.txt
tag 1.0.1 tag1 @commit1
push origin master
'''
    r1 = git_temp_repo(remote = True, debug = self.DEBUG)
    r1.apply_config_text(config)
    tmp_dir = self.make_temp_dir(suffix = '-tmp-sync-dir')
    args = [
      'git_repo',
      'sync',
      r1.address,
      tmp_dir,
    ]
    rv = self.run_program(self._program, args)
    self.assertEqual(0, rv.exit_code)
    r2 = git_repo(tmp_dir)
    self.assertEqual( '1.0.1', r2.greatest_local_tag().name )
    self.assertEqual( [
      'kiwi.txt',
    ], r2.find_all_files() )
예제 #29
0
    def test_bump_tag_major(self):
        'Just a smoke test bes.git has more test cases for bump_tag'
        content = [
            'file foo.txt "this is foo.txt" 644',
            'file bar.txt "this is bar.txt" 644',
        ]
        r1 = git_temp_repo(content=content, debug=self.DEBUG)
        r2 = r1.make_temp_cloned_repo()
        self.assertEqual(None, r1.greatest_local_tag())

        args = [
            'git',
            'bump_tag',
            '--root-dir',
            r1.root,
            '--component',
            'revision',
            '--reset-lower',
        ]
        rv = self.run_program(self._program, args)
        self.assertEqual(0, rv.exit_code)
        r2.pull()
        self.assertEqual('1.0.0', r2.greatest_local_tag().name)

        args = [
            'git',
            'bump_tag',
            '--root-dir',
            r1.root,
            '--component',
            'major',
            '--reset-lower',
        ]
        rv = self.run_program(self._program, args)
        self.assertEqual(0, rv.exit_code)
        r2.pull()
        self.assertEqual('2.0.0', r2.greatest_local_tag().name)
예제 #30
0
    def test_many_concurrent(self):
        '''
    Create a bunch of processes trying to push to the same repo simulataneously.
    This creates git locking issues and exercises the safe_push retry code.
    '''
        r1 = git_temp_repo(debug=self.DEBUG)

        initial_content = self._make_content('coconut')
        r1.add_file('coconut', initial_content)
        r1.push('origin', 'master')

        jobs = []
        for fruit in self._FRUITS:
            p = multiprocessing.Process(
                target=self._test_many_concurrent_worker,
                args=(self.__class__, fruit, r1.address))
            jobs.append(p)
            p.start()

        for job in jobs:
            job.join()

        r2 = git_repo(self.make_temp_dir(), address=r1.address)
        r2.clone_or_pull()

        self.assertEqual([
            'apple',
            'blueberry',
            'coconut',
            'kiwi',
            'lemon',
            'melon',
            'orange',
            'papaya',
            'pineapple',
            'watermelon',
        ], r2.find_all_files())