I wrote a python script to determine the last running commit. I want to use it as a pre-receive hook. I do a push, but for some reason, after finding a commit (step 1), it does not return the branches to which it belongs (returns an empty string). Naturally, traysbek falls out and the hook does not work. I try manually in the command line, returns the branches. What could be the problem?
#!/usr/bin/env python import sys, os import git for line in sys.stdin: refname = line.split(" ")[2].strip() oldrev = line.split(" ")[0].strip() newrev = line.split(" ")[1].strip() commit = git.get_all_commits(newrev, oldrev)[-1] branches_that_contains_commit = git.get_branches_that_contain_commit(commit) list_of_commits = git.get_all_commits(newrev, branches_that_contains_commit[0], opts=["^%s" % i for i in branches_that_contains_commit[1:]].append("--first-parent"))[-1] last_pushed_commit = git.get_commits_parent(list_of_commits)[1]
os.environand compare. btw, the three lines of your code can be written shorter (oldrev, newrev, refname) = line.split ("") but then perhaps you need to write more. - KoVadim