Exemple #1
0
 def test_git_plugin_reup(self):
     repo = GitRepo(self.content_dir)
     master_head = repo.run('git', 'rev-parse', 'master')
     plugin_fields = {'url': self.content_dir}
     # By default, the git plugin should reup from master.
     expected_output = {'rev': master_head}
     output = test_plugin_get_reup_fields(
         self.plugin_context, 'git', plugin_fields)
     self.assertDictEqual(expected_output, output)
     # Add some new commits and make sure master gets fetched properly.
     repo.run('git', 'commit', '--allow-empty', '-m', 'junk')
     repo.run('git', 'checkout', '-q', '-b', 'newbranch')
     repo.run('git', 'commit', '--allow-empty', '-m', 'more junk')
     new_master_head = repo.run('git', 'rev-parse', 'master')
     expected_output['rev'] = new_master_head
     output = test_plugin_get_reup_fields(
         self.plugin_context, 'git', plugin_fields)
     self.assertDictEqual(expected_output, output)
     # Now specify the reup target explicitly.
     newbranch_head = repo.run('git', 'rev-parse', 'newbranch')
     plugin_fields['reup'] = 'newbranch'
     expected_output['rev'] = newbranch_head
     output = test_plugin_get_reup_fields(
         self.plugin_context, 'git', plugin_fields)
     self.assertDictEqual(expected_output, output)
Exemple #2
0
 def test_git_plugin_reup(self):
     repo = GitRepo(self.content_dir)
     master_head = repo.run("git rev-parse master")
     plugin_fields = {"url": self.content_dir}
     # By default, the git plugin should reup from master.
     expected_output = {"rev": master_head}
     output = plugin_get_reup_fields(
         self.plugin_context, "git", plugin_fields)
     self.assertDictEqual(expected_output, output)
     # Add some new commits and make sure master gets fetched properly.
     repo.run("git commit --allow-empty -m 'junk'")
     repo.run("git checkout -q -b newbranch")
     repo.run("git commit --allow-empty -m 'more junk'")
     new_master_head = repo.run("git rev-parse master")
     expected_output["rev"] = new_master_head
     output = plugin_get_reup_fields(
         self.plugin_context, "git", plugin_fields)
     self.assertDictEqual(expected_output, output)
     # Now specify the reup target explicitly.
     newbranch_head = repo.run("git rev-parse newbranch")
     plugin_fields["reup"] = "newbranch"
     expected_output["rev"] = newbranch_head
     output = plugin_get_reup_fields(
         self.plugin_context, "git", plugin_fields)
     self.assertDictEqual(expected_output, output)
Exemple #3
0
    def test_git_plugin_with_relative_submodule(self):
        content_repo = GitRepo(self.content_dir)
        # Same autocrlf workaround as above.
        content_repo.run('git', 'config', 'core.autocrlf', 'false')

        # Similar to above, but this time we use a relative path.
        submodule_dir = shared.create_dir({'another': 'file'})
        GitRepo(submodule_dir)
        submodule_basename = os.path.basename(submodule_dir)
        relative_path = "../" + submodule_basename
        content_repo.run('git', 'submodule', 'add', '-q', relative_path,
                         'subdir/')
        content_repo.run('git', 'commit', '-m', 'submodule commit')
        expected_content = self.content.copy()
        expected_content['subdir/another'] = 'file'
        with open(os.path.join(self.content_dir, '.gitmodules')) as f:
            expected_content['.gitmodules'] = f.read()
        self.do_plugin_test('git', {'url': self.content_dir}, expected_content)
Exemple #4
0
    def test_git_plugin_with_relative_submodule(self):
        content_repo = GitRepo(self.content_dir)
        # Same autocrlf workaround as above.
        content_repo.run('git', 'config', 'core.autocrlf', 'false')

        # Similar to above, but this time we use a relative path.
        submodule_dir = shared.create_dir({'another': 'file'})
        GitRepo(submodule_dir)
        submodule_basename = os.path.basename(submodule_dir)
        relative_path = "../" + submodule_basename
        content_repo.run('git', 'submodule', 'add', '-q', relative_path,
                         'subdir/')
        content_repo.run('git', 'commit', '-m', 'submodule commit')
        expected_content = self.content.copy()
        expected_content['subdir/another'] = 'file'
        with open(os.path.join(self.content_dir, '.gitmodules')) as f:
            expected_content['.gitmodules'] = f.read()
        self.do_plugin_test('git', {'url': self.content_dir}, expected_content)
Exemple #5
0
 def test_git_plugin_multiple_fetches(self):
     content_repo = GitRepo(self.content_dir)
     head = content_repo.run('git', 'rev-parse', 'HEAD')
     plugin_fields = {"url": self.content_dir, "rev": head}
     output = self.do_plugin_test("git", plugin_fields, self.content)
     self.assertEqual(output.count("git clone"), 1)
     self.assertEqual(output.count("git fetch"), 0)
     # Add a new file to the directory and commit it.
     shared.write_files(self.content_dir, {'another': 'file'})
     content_repo.run('git', 'add', '-A')
     content_repo.run('git', 'commit', '-m', 'committing another file')
     # Refetch the original rev. Git should not do a git-fetch.
     output = self.do_plugin_test("git", plugin_fields, self.content)
     self.assertEqual(output.count("git clone"), 0)
     self.assertEqual(output.count("git fetch"), 0)
     # Not delete the rev field. Git should default to master and fetch.
     del plugin_fields["rev"]
     self.content["another"] = "file"
     output = self.do_plugin_test("git", plugin_fields, self.content)
     self.assertEqual(output.count("git clone"), 0)
     self.assertEqual(output.count("git fetch"), 1)
Exemple #6
0
 def test_git_plugin_multiple_fetches(self):
     content_repo = GitRepo(self.content_dir)
     head = content_repo.run('git', 'rev-parse', 'HEAD')
     plugin_fields = {"url": self.content_dir, "rev": head}
     output = self.do_plugin_test("git", plugin_fields, self.content)
     self.assertEqual(output.count("git clone"), 1)
     self.assertEqual(output.count("git fetch"), 0)
     # Add a new file to the directory and commit it.
     shared.write_files(self.content_dir, {'another': 'file'})
     content_repo.run('git', 'add', '-A')
     content_repo.run('git', 'commit', '-m', 'committing another file')
     # Refetch the original rev. Git should not do a git-fetch.
     output = self.do_plugin_test("git", plugin_fields, self.content)
     self.assertEqual(output.count("git clone"), 0)
     self.assertEqual(output.count("git fetch"), 0)
     # Not delete the rev field. Git should default to master and fetch.
     del plugin_fields["rev"]
     self.content["another"] = "file"
     output = self.do_plugin_test("git", plugin_fields, self.content)
     self.assertEqual(output.count("git clone"), 0)
     self.assertEqual(output.count("git fetch"), 1)
Exemple #7
0
    def test_git_plugin_with_submodule(self):
        content_repo = GitRepo(self.content_dir)
        # Git has a small bug: The .gitmodules file is always created with "\n"
        # line endings, even on Windows. With core.autocrlf turned on, that
        # causes a warning when the file is added/committed, because those line
        # endings would get replaced with "\r\n" when the file was checked out.
        # We can just turn autocrlf off for this test to silence the warning.
        content_repo.run('git', 'config', 'core.autocrlf', 'false')
        submodule_dir = shared.create_dir({'another': 'file'})
        submodule_repo = GitRepo(submodule_dir)
        content_repo.run(
            'git', 'submodule', 'add', '-q', submodule_dir, 'subdir/')
        content_repo.run('git', 'commit', '-m', 'submodule commit')
        expected_content = self.content.copy()
        expected_content['subdir/another'] = 'file'
        with open(os.path.join(self.content_dir, '.gitmodules')) as f:
            expected_content['.gitmodules'] = f.read()
        self.do_plugin_test('git', {'url': self.content_dir}, expected_content)
        # Now move the submodule forward. Make sure it gets fetched again.
        shared.write_files(submodule_dir, {'more': 'stuff'})
        submodule_repo.run('git', 'add', '-A')
        submodule_repo.run('git', 'commit', '-m', 'more stuff')
        subprocess.check_output(
            ['git', 'pull', '-q'],
            cwd=os.path.join(self.content_dir, 'subdir'))
        content_repo.run('git', 'commit', '-am', 'submodule update')
        expected_content['subdir/more'] = 'stuff'
        self.do_plugin_test('git', {'url': self.content_dir}, expected_content)

        # Normally when you run `git submodule add ...`, git puts two things in
        # your repo: an entry in .gitmodules, and a commit object at the
        # appropriate path inside your repo. However, it's possible for those
        # two to get out of sync, especially if you use mv/rm on a directory
        # followed by `git add`, instead of the smarter `git mv`/`git rm`. We
        # need to create this condition and check that we then ignore the
        # submodule.
        shutil.rmtree(os.path.join(self.content_dir, 'subdir'))
        content_repo.run('git', 'commit', '-am', 'inconsistent delete')
        del expected_content['subdir/another']
        del expected_content['subdir/more']
        self.do_plugin_test('git', {'url': self.content_dir}, expected_content)

        # Finally, test explicitly disabling submodule fetching. Start by
        # reverting the 'inconsistent delete' commit from above.
        content_repo.run('git', 'revert', '--no-edit', 'HEAD')
        fields = {'url': self.content_dir, 'submodules': 'false'}
        self.do_plugin_test('git', fields, expected_content)
Exemple #8
0
 def test_empty_git_rev(self):
     empty_dir = shared.create_dir()
     GitRepo(empty_dir)
     self.do_plugin_test('git', {'url': empty_dir}, {})
Exemple #9
0
 def test_git_plugin(self):
     GitRepo(self.content_dir)
     self.do_plugin_test("git", {"url": self.content_dir}, self.content)
Exemple #10
0
 def test_git_plugin_reup(self):
     repo = GitRepo(self.content_dir)
     master_head = repo.run('git', 'rev-parse', 'master')
     plugin_fields = {'url': self.content_dir}
     # By default, the git plugin should reup from master.
     expected_output = {'rev': master_head}
     output = test_plugin_get_reup_fields(
         self.plugin_context, 'git', plugin_fields)
     self.assertDictEqual(expected_output, output)
     # Add some new commits and make sure master gets fetched properly.
     repo.run('git', 'commit', '--allow-empty', '-m', 'junk')
     repo.run('git', 'checkout', '-q', '-b', 'newbranch')
     repo.run('git', 'commit', '--allow-empty', '-m', 'more junk')
     new_master_head = repo.run('git', 'rev-parse', 'master')
     expected_output['rev'] = new_master_head
     output = test_plugin_get_reup_fields(
         self.plugin_context, 'git', plugin_fields)
     self.assertDictEqual(expected_output, output)
     # Now specify the reup target explicitly.
     newbranch_head = repo.run('git', 'rev-parse', 'newbranch')
     plugin_fields['reup'] = 'newbranch'
     expected_output['rev'] = newbranch_head
     output = test_plugin_get_reup_fields(
         self.plugin_context, 'git', plugin_fields)
     self.assertDictEqual(expected_output, output)
Exemple #11
0
    def test_git_plugin_with_submodule(self):
        content_repo = GitRepo(self.content_dir)
        # Git has a small bug: The .gitmodules file is always created with "\n"
        # line endings, even on Windows. With core.autocrlf turned on, that
        # causes a warning when the file is added/committed, because those line
        # endings would get replaced with "\r\n" when the file was checked out.
        # We can just turn autocrlf off for this test to silence the warning.
        content_repo.run('git', 'config', 'core.autocrlf', 'false')
        submodule_dir = shared.create_dir({'another': 'file'})
        submodule_repo = GitRepo(submodule_dir)
        content_repo.run(
            'git', 'submodule', 'add', '-q', submodule_dir, 'subdir/')
        content_repo.run('git', 'commit', '-m', 'submodule commit')
        expected_content = self.content.copy()
        expected_content['subdir/another'] = 'file'
        with open(os.path.join(self.content_dir, '.gitmodules')) as f:
            expected_content['.gitmodules'] = f.read()
        self.do_plugin_test('git', {'url': self.content_dir}, expected_content)
        # Now move the submodule forward. Make sure it gets fetched again.
        shared.write_files(submodule_dir, {'more': 'stuff'})
        submodule_repo.run('git', 'add', '-A')
        submodule_repo.run('git', 'commit', '-m', 'more stuff')
        subprocess.check_output(
            ['git', 'pull', '-q'],
            cwd=os.path.join(self.content_dir, 'subdir'))
        content_repo.run('git', 'commit', '-am', 'submodule update')
        expected_content['subdir/more'] = 'stuff'
        self.do_plugin_test('git', {'url': self.content_dir}, expected_content)

        # Normally when you run `git submodule add ...`, git puts two things in
        # your repo: an entry in .gitmodules, and a commit object at the
        # appropriate path inside your repo. However, it's possible for those
        # two to get out of sync, especially if you use mv/rm on a directory
        # followed by `git add`, instead of the smarter `git mv`/`git rm`. We
        # need to create this condition and check that we then ignore the
        # submodule.
        shutil.rmtree(os.path.join(self.content_dir, 'subdir'))
        content_repo.run('git', 'commit', '-am', 'inconsistent delete')
        del expected_content['subdir/another']
        del expected_content['subdir/more']
        self.do_plugin_test('git', {'url': self.content_dir}, expected_content)

        # Finally, test explicitly disabling submodule fetching. Start by
        # reverting the 'inconsistent delete' commit from above.
        content_repo.run('git', 'revert', '--no-edit', 'HEAD')
        fields = {'url': self.content_dir, 'submodules': 'false'}
        self.do_plugin_test('git', fields, expected_content)
Exemple #12
0
 def test_git_plugin_with_submodule(self):
     content_repo = GitRepo(self.content_dir)
     # Git has a small bug: The .gitmodules file is always created with "\n"
     # line endings, even on Windows. With core.autocrlf turned on, that
     # causes a warning when the file is added/committed, because those line
     # endings would get replaced with "\r\n" when the file was checked out.
     # We can just turn autocrlf off for this test to silence the warning.
     content_repo.run('git', 'config', 'core.autocrlf', 'false')
     submodule_dir = shared.create_dir({'another': 'file'})
     submodule_repo = GitRepo(submodule_dir)
     content_repo.run(
         'git', 'submodule', 'add', '-q', submodule_dir, 'subdir/')
     content_repo.run('git', 'commit', '-m', 'submodule commit')
     expected_content = self.content.copy()
     expected_content['subdir/another'] = 'file'
     with open(os.path.join(self.content_dir, '.gitmodules')) as f:
         expected_content['.gitmodules'] = f.read()
     self.do_plugin_test('git', {'url': self.content_dir}, expected_content)
     # Now move the submodule forward. Make sure it gets fetched again.
     shared.write_files(submodule_dir, {'more': 'stuff'})
     submodule_repo.run('git', 'add', '-A')
     submodule_repo.run('git', 'commit', '-m', 'more stuff')
     subprocess.check_output(
         ['git', 'pull', '-q'],
         cwd=os.path.join(self.content_dir, 'subdir'))
     content_repo.run('git', 'commit', '-am', 'submodule update')
     expected_content['subdir/more'] = 'stuff'
     self.do_plugin_test('git', {'url': self.content_dir}, expected_content)
Exemple #13
0
 def test_git_plugin_with_submodule(self):
     content_repo = GitRepo(self.content_dir)
     # Git has a small bug: The .gitmodules file is always created with "\n"
     # line endings, even on Windows. With core.autocrlf turned on, that
     # causes a warning when the file is added/committed, because those line
     # endings would get replaced with "\r\n" when the file was checked out.
     # We can just turn autocrlf off for this test to silence the warning.
     content_repo.run('git', 'config', 'core.autocrlf', 'false')
     submodule_dir = shared.create_dir({'another': 'file'})
     submodule_repo = GitRepo(submodule_dir)
     content_repo.run('git', 'submodule', 'add', '-q', submodule_dir,
                      'subdir/')
     content_repo.run('git', 'commit', '-m', 'submodule commit')
     expected_content = self.content.copy()
     expected_content['subdir/another'] = 'file'
     with open(os.path.join(self.content_dir, '.gitmodules')) as f:
         expected_content['.gitmodules'] = f.read()
     self.do_plugin_test('git', {'url': self.content_dir}, expected_content)
     # Now move the submodule forward. Make sure it gets fetched again.
     shared.write_files(submodule_dir, {'more': 'stuff'})
     submodule_repo.run('git', 'add', '-A')
     submodule_repo.run('git', 'commit', '-m', 'more stuff')
     subprocess.check_output(['git', 'pull', '-q'],
                             cwd=os.path.join(self.content_dir, 'subdir'))
     content_repo.run('git', 'commit', '-am', 'submodule update')
     expected_content['subdir/more'] = 'stuff'
     self.do_plugin_test('git', {'url': self.content_dir}, expected_content)
Exemple #14
0
 def test_git_plugin_with_submodule(self):
     content_repo = GitRepo(self.content_dir)
     submodule_dir = shared.create_dir({'another': 'file'})
     submodule_repo = GitRepo(submodule_dir)
     content_repo.run('git submodule add -q "{}" subdir/'.format(
         submodule_dir))
     content_repo.run('git commit -m "submodule commit"')
     expected_content = self.content.copy()
     expected_content['subdir/another'] = 'file'
     with open(os.path.join(self.content_dir, '.gitmodules')) as f:
         expected_content['.gitmodules'] = f.read()
     self.do_plugin_test('git', {'url': self.content_dir}, expected_content)
     # Now move the submodule forward. Make sure it gets fetched again.
     shared.write_files(submodule_dir, {'more': 'stuff'})
     submodule_repo.run('git add -A')
     submodule_repo.run('git commit -m "more stuff"')
     subprocess.check_output(
         ['git', 'pull', '-q'],
         cwd=os.path.join(self.content_dir, 'subdir'))
     content_repo.run('git commit -am "submodule udate"')
     expected_content['subdir/more'] = 'stuff'
     self.do_plugin_test('git', {'url': self.content_dir}, expected_content)