Python get commit hash
19 Python code examples are found related to "
get commit hash".
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
Example 1
Source File: generic_utils.py From TTS with Mozilla Public License 2.0 | 6 votes |
def get_commit_hash(): """https://stackoverflow.com/questions/14989858/get-the-current-git-hash-in-a-python-script""" # try: # subprocess.check_output(['git', 'diff-index', '--quiet', # 'HEAD']) # Verify client is clean # except: # raise RuntimeError( # " !! Commit before training to get the commit hash.") try: commit = subprocess.check_output( ['git', 'rev-parse', '--short', 'HEAD']).decode().strip() # Not copying .git folder into docker container except subprocess.CalledProcessError: commit = "0000000" print(' > Git Hash: {}'.format(commit)) return commit
Example 2
Source File: utils.py From flambe with MIT License | 6 votes |
def get_commit_hash() -> str: """Get the commit hash of the current flambe development package. This will only work if flambe was install from github in dev mode. Returns ------- str The commit hash Raises ------ Exception In case flambe was not installed in dev mode. """ x = freeze.freeze() for pkg in x: if "flambe" in pkg: if pkg.startswith("-e"): git_url = pkg.split(" ")[-1] commit = git_url.split("@")[-1].split("#")[0] return commit raise Exception("Tried to lookup commit hash in NOT development mode.")
Example 3
Source File: info.py From upribox with GNU General Public License v3.0 | 5 votes |
def get_last_commit_short_hash(self): try: self.last_commit_short = subprocess.check_output(['/usr/bin/git', '-C', self.GIT_REPO_LOCAL_DIR, 'rev-parse', '--short', 'HEAD']).strip() except: pass
Example 4
Source File: git.py From integrations-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_latest_commit_hash(root=None): with chdir(root or get_root()): result = run_command('git rev-parse HEAD', capture=True, check=True) return result.stdout.strip()
Example 5
Source File: setup.py From pyfasttext with GNU General Public License v3.0 | 5 votes |
def get_fasttext_commit_hash(): try: with open('.git/modules/fastText/HEAD', 'r') as f: return f.read().strip() except: return 'unknown'
Example 6
Source File: experiments.py From PyVideoResearch with GNU General Public License v3.0 | 5 votes |
def get_script_dir_commit_hash(): current_working_dir = os.getcwd() os.chdir(os.path.dirname(__file__)) try: commit = subprocess.check_output(["git", "describe", "--always"]).strip() return commit.decode('UTF-8') except Exception as e: print(e) return '' finally: os.chdir(current_working_dir)
Example 7
Source File: requirements.py From requirementslib with MIT License | 5 votes |
def get_commit_hash(self): # type: () -> STRING_TYPE with pip_shims.shims.global_tempdir_manager(): hash_ = self.repo.get_commit_hash() return hash_
Example 8
Source File: active_branch.py From GitSavvy with MIT License | 5 votes |
def get_commit_hash_for_head(self): """ Get the SHA1 commit hash for the commit at HEAD. """ return self.git("rev-parse", "HEAD").strip()
Example 9
Source File: vulnerability.py From vulncode-db with Apache License 2.0 | 5 votes |
def get_by_commit_hash(cls, commit_hash: str): return (cls.query.join( Vulnerability.commits, aliased=True).filter_by(commit_hash=commit_hash).options( default_vuln_view_options).first())
Example 10
Source File: build.py From blackbox with BSD 2-Clause "Simplified" License | 5 votes |
def getCommitHash(): gitLog = shellExec(localRepository, "git log " + branch + " -1") global commitHash commitHash = gitLog.split("\n")[0].split(" ")[1] return commitHash
Example 11
Source File: tuilib.py From komodo-cctools-python with MIT License | 5 votes |
def get_commit_hash(repo_path): os.chdir(repo_path) proc = subprocess.run(['git', 'log', '-n', '1'], check=True, stdout=subprocess.PIPE, universal_newlines=True) output = proc.stdout return output.split()[1]
Example 12
Source File: build_context.py From gigantum-client with MIT License | 5 votes |
def get_current_commit_hash(length=None) -> str: """Method to get the current commit hash of the gtm repository Returns: str """ # Get the path of the root directory repo = Repo(common.config.get_client_root()) if length is None: return repo.head.commit.hexsha else: return repo.head.commit.hexsha[:length]
Example 13
Source File: git.py From rdopkg with Apache License 2.0 | 5 votes |
def get_latest_commit_hash(self, ref=None): cmd = ['log', '-n', '1', '--format=%H'] if ref: cmd.append(ref) out = self(*cmd, log_cmd=False, log_fail=False, fatal=False) return out
Example 14
Source File: git.py From detect-secrets-server with Apache License 2.0 | 5 votes |
def get_last_commit_hash(directory): return _git( directory, 'rev-parse', 'HEAD', )
Example 15
Source File: hg.py From FAI-PEP with Apache License 2.0 | 5 votes |
def getNextCommitHash(self, commit, step): self.pull(commit) res = self._run('next', str(step)) if res is None: return commit res = res.split("\n") if len(res) > 0 and res[0].strip() == "reached head commit": # Not yet have step commits return commit return self.getCurrentCommitHash()
Example 16
Source File: hg.py From FAI-PEP with Apache License 2.0 | 5 votes |
def getCommitHash(self, commit): if commit: output = self._run('log', '--template', '<START>{node}<END>', '-r', commit) else: output = self._run('log', '-l', "1", '--template', '<START>{node}<END>') start = output.index('<START>') + len('<START>') end = output.index('<END>') return output[start:end]
Example 17
Source File: hg.py From FAI-PEP with Apache License 2.0 | 5 votes |
def getCurrentCommitHash(self): commit = self.getCommitHash(None) if commit[-1] == '+': commit = commit[:-1] return self.getCommitHash(commit)
Example 18
Source File: writer.py From autonomous-learning-library with MIT License | 5 votes |
def get_commit_hash(): result = subprocess.run( ["git", "rev-parse", "--short", "HEAD"], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, check=False ) return result.stdout.decode("utf-8").rstrip()