test_clone.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # vim: set fileencoding=utf-8 :
  2. #
  3. # (C) 2016 Guido Günther <agx@sigxcpu.org>
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, please see
  17. # <http://www.gnu.org/licenses/>
  18. import os
  19. from tests.component import (ComponentTestBase,
  20. ComponentTestGitRepository)
  21. from tests.component.deb.fixtures import RepoFixtures
  22. from nose.tools import ok_
  23. from gbp.scripts.clone import main as clone
  24. class TestClone(ComponentTestBase):
  25. """Test cloning from a remote"""
  26. @RepoFixtures.native()
  27. def test_clone_nonempty(self, repo):
  28. """Test that cloning into an existing dir fails"""
  29. os.chdir('..')
  30. ok_(clone(['arg0', repo.path]) == 1,
  31. "Cloning did no fail as expected")
  32. self._check_log(-2,
  33. "gbp:error: Git command failed: Error "
  34. "running git clone: fatal: destination path "
  35. "'git-buildpackage' already exists and is not "
  36. "an empty directory.")
  37. @RepoFixtures.native()
  38. def test_clone_native(self, repo):
  39. """Test that cloning of debian native packages works"""
  40. dest = os.path.join(self._tmpdir,
  41. 'cloned_repo')
  42. clone(['arg0',
  43. '--postclone=printenv > postclone.out',
  44. repo.path, dest])
  45. cloned = ComponentTestGitRepository(dest)
  46. self._check_repo_state(cloned, 'master', ['master'])
  47. assert len(cloned.get_commits()) == 1
  48. self.check_hook_vars('postclone', ["GBP_GIT_DIR"])
  49. def test_clone_environ(self):
  50. """Test that environment variables influence git configuration"""
  51. # Build up somethng we can clone from
  52. os.environ['DEBFULLNAME'] = 'testing tester'
  53. os.environ['DEBEMAIL'] = 'gbp-tester@debian.invalid'
  54. repo = RepoFixtures.import_native()
  55. got = repo.get_config("user.email")
  56. want = os.environ['DEBEMAIL']
  57. ok_(got == want, "unexpected git config user.email: got %s, want %s" % (got, want))
  58. got = repo.get_config("user.name")
  59. want = os.environ['DEBFULLNAME']
  60. ok_(got == want, "unexpected git config user.name: got %s, want %s" % (got, want))