How to validate a tag using GitPython

In a python script, I am trying to validate a tag after cloning a git repository. I am using GitPython 0.3.2.

#!/usr/bin/env python import git g = git.Git() g.clone(" user@host :repos") g = git.Git(repos) g.execute(["git", "checkout", "tag_name"]) 

With this code, I have an error:

 g.execute(["git", "checkout", "tag_name"]) File "/usr/lib/python2.6/site-packages/git/cmd.py", line 377, in execute raise GitCommandError(command, status, stderr_value) GitCommandError: 'git checkout tag_name' returned exit status 1: error: pathspec 'tag_name' did not match any file(s) known to git. 

If I replace the tag name with the branch name, I have no problem. I did not find the information in the GitPython documentation. And if I try to check the same tag in the shell, I have a problem.

Do you know how can I check the git tag in python?

+6
source share
2 answers

Assuming you cloned a repository in 'path / to / repo', just try the following:

 from git import Git g = Git('path/to/repo') g.checkout('tag_name') 
+3
source
 from git import Git g = Git(repo_path) g.init() g.checkout(version_tag) 

Like cmd.py class git comments say

 """ The Git class manages communication with the Git binary. It provides a convenient interface to calling the Git binary, such as in:: g = Git( git_dir ) g.init() # calls 'git init' program rval = g.ls_files() # calls 'git ls-files' program ``Debugging`` Set the GIT_PYTHON_TRACE environment variable print each invocation of the command to stdout. Set its value to 'full' to see details about the returned values. """ 
+1
source

Source: https://habr.com/ru/post/958399/


All Articles