Exemple #1
0
def test_basic():
    shutil.rmtree("/tmp/brigit_test", ignore_errors=True)
    git = Git("/tmp/brigit_test")
    with open("/tmp/brigit_test/file_1", "w") as f:
        f.write('1')
    git.add("/tmp/brigit_test/file_1")
    git.commit(message="Adding file_1")
    assert "Adding file_1" in git.log()
    assert len(list(git.pretty_log())) == 1
    with open("/tmp/brigit_test/file_2", "w") as f:
        f.write('2')
    git.add("/tmp/brigit_test/file_2")
    git.commit(message="Adding file_2")
    assert "Adding file_2" in git.log()
    assert len(list(git.pretty_log())) == 2
    git.reset("HEAD~1")
    assert len(list(git.pretty_log())) == 1
    assert "Untracked files:\n\tfile_2" in git.status()
    git.clean("-fdx")
    git.branch("newbranch")
    with open("/tmp/brigit_test/file_3", "w") as f:
        f.write('3')
    git.add("/tmp/brigit_test/file_3")
    git.commit(message="Adding file_3")
    assert "Adding file_3" in git.log()
    git.checkout("newbranch")
    git.cherryPick("master")
    shutil.rmtree("/tmp/brigit_test")
class GitCommandList:
    _repo = None
    _local_git_path = None
    _repo_url = None

    # to initialize the repository variable
    def init_git(self, local_git_path, repo_url):
        try:
            self._local_git_path = local_git_path
            self._repo_url = repo_url
            self._repo = Git(self._local_git_path, self._repo_url)
            self._repo.pull()
            return True
        except:
            return False

    # to make a commit, without doing a push on the remote repository on git
    def commit(self, message='Auto-commit: ' + str(datetime.now())):
        try:
            for file in local_tree(self._local_git_path):
                self._repo.add(file)
            self._repo.commit(message)
            return True
        except:
            return False

    # To push che files in the local repository.
    # A commit is generated automatically
    def push(self):
        try:

            self.commit()
            self._repo.pretty_log()
            r = self._repo.push()
            return '[*] Pushing at: ' + str(datetime.now()) + '\n' + r
        except:
            return False

    # to pull in the local from the remote repository
    def pull(self):
        try:
            self._repo.pretty_log()
            r = self._repo.pull()
            return '[*] Pulling at: ' + str(datetime.now()) + '\n' + r
        except Exception as e:
            print(e)
            return False
def test_basic():
    shutil.rmtree("/tmp/brigit_test", ignore_errors=True)
    git = Git("/tmp/brigit_test")
    with open("/tmp/brigit_test/file_1", "w") as f:
        f.write('1')
    git.add("/tmp/brigit_test/file_1")
    git.commit(message="Adding file_1")
    assert "Adding file_1" in git.log()
    assert len(list(git.pretty_log())) == 1
    with open("/tmp/brigit_test/file_2", "w") as f:
        f.write('2')
    git.add("/tmp/brigit_test/file_2")
    git.commit(message="Adding file_2")
    assert "Adding file_2" in git.log()
    assert len(list(git.pretty_log())) == 2
    git.reset("HEAD~1")
    assert len(list(git.pretty_log())) == 1
    assert "Untracked files:\n\tfile_2" in git.status()
    shutil.rmtree("/tmp/brigit_test")