Exemplo n.º 1
0
 def create_git_commit(self):
     self.add_tracked_file()
     with ChDir(self.dir):
         self._silent_call(["git", "commit", "-m", "message"])
         commit_id = self._silent_call(
             ["git", "rev-parse", "--short", "HEAD"]).strip()
         return commit_id
Exemplo n.º 2
0
    def test_call_without_specifying_dir(self):
        with GitDir() as git, TempFile() as out_file:
            commit_id = git.create_git_commit()
            expected = """
                    # ---------------------------------------------------
                    # This file is autogenerated by git-version.
                    # DO NOT MODIFY!
                    # ---------------------------------------------------

                    VERSION_STRING = "dev1+rev%s"
                    GIT_TAG_NAME = "master"
                    GIT_COMMITS_SINCE_TAG = 1
                    GIT_COMMIT_ID = "%s"
                    MODIFIED_SINCE_COMMIT = False
                    IS_DEV_VERSION = True
                    IS_STABLE_VERSION = False
                """ % (commit_id[0:7], commit_id[0:7])
            script_dir = os.getcwd()
            with ChDir(git.dir), open("/dev/null", 'w') as devnull:
                subprocess.check_call([
                    sys.executable, "-m", "gitversionbuilder", "--lang",
                    "python", out_file
                ],
                                      stdout=devnull,
                                      env={"PYTHONPATH": script_dir})
            self.assertCodeEqual(expected, self.read_file(out_file))
Exemplo n.º 3
0
 def checkout_git_commit(self, commit_id):
     with ChDir(self.dir):
         self._silent_call(["git", "checkout", commit_id])
Exemplo n.º 4
0
 def switch_git_branch(self, branch_name):
     with ChDir(self.dir):
         self._silent_call(["git", "checkout", branch_name])
Exemplo n.º 5
0
 def modify_file(self, filename):
     content = self._random_string(10)
     with ChDir(self.dir):
         with open(filename, 'w') as file:
             file.write(content)
Exemplo n.º 6
0
 def add_tracked_file(self):
     filename = self.add_untracked_file()
     with ChDir(self.dir):
         self._silent_call(["git", "add", filename])
         return filename
Exemplo n.º 7
0
 def add_untracked_file(self):
     filename = self._random_string(10)
     with ChDir(self.dir):
         self._silent_call(["touch", filename])
         return filename
Exemplo n.º 8
0
 def _setup_git(self):
     with ChDir(self.dir):
         self._silent_call(["git", "init"])
         self._silent_call(
             ["git", "config", "user.email", "*****@*****.**"])
         self._silent_call(["git", "config", "user.name", "Your Name"])
Exemplo n.º 9
0
 def create_git_tag(self, tag_name):
     with ChDir(self.dir):
         self._silent_call(["git", "tag", tag_name])