SHARE
TWEET

Github-magic-merge-commit

kriti21 May 19th, 2018 13 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def get_head_commit(self):
  2.     with change_directory(self.get_config_dir() or os.getcwd()):
  3.         stdout, stderr = run_shell_command('git log -1 --pretty=%B')
  4.  
  5.         stdout = stdout.rstrip('\n')
  6.         pos = stdout.find('\n')
  7.         shortlog = stdout[:pos] if pos != -1 else stdout
  8.  
  9.         magic_github_merge_commit_regex = re.compile(
  10.             r'^Merge [0-9a-f]+ into [0-9a-f]+$|....')
  11.         match = re.fullmatch(magic_github_merge_commit_regex, shortlog)
  12.  
  13.         if match and len(shortlog) == 92:
  14.             command = 'git log --pretty=%P -n 1 ' + head_commit
  15.             parent_commits = run_shell_command(command)
  16.             sha_regex = re.compile(r'([0-9a-f]{40})')
  17.             unmerged_commit_sha = re.findall(sha_regex, parent_commits)[1]
  18.  
  19.             command = ('git log -n 1 ' +
  20.                        str(unmerged_commit_sha) + ' --pretty=%B')
  21.  
  22.             return run_shell_command(command)
  23.  
  24.         else:
  25.             return run_shell_command('git log -1 --pretty=%B')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top