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] 
  • one
    maybe the problem is that the environment is different? print out os.environ and 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
  • It does not seem to be different. Yes, and I have a hardcode yet. There is a thought: commit = git.get_all_commits (newrev, oldrev) [- 1] should return the earliest commit from the target branch, returns newrev, and since it is not running, it does not yet belong to any of the branches, therefore it returns an empty line - kslava

0