gitinfo#
- gitinfo(path=None, hashlen=7, die=False, verbose=True)[source]#
Retrieve git info
This function reads git branch and commit information from a .git directory. Given a path, it will check for a
.git
directory. If the path doesn’t contain that directory, it will search parent directories for.git
until it finds one. Then, the current information will be parsed.Note: if direct directory reading fails, it will attempt to use the gitpython library.
- Parameters:
path (str) – A folder either containing a .git directory, or with a parent that contains a .git directory
hashlen (int) – Length of hash to return (default: 7)
die (bool) – whether to raise an exception if git information can’t be retrieved (default: no)
verbose (bool) – if not dying, whether to print information about the exception
- Returns:
Dictionary containing the branch, hash, and commit date
Examples:
info = sc.gitinfo() # Get git info for current script repository info = sc.gitinfo(my_package.__file__) # Get git info for a particular Python package