gitpython推送结果(预接收钩子被拒绝),文件较大。

问题描述 投票:2回答:1

有没有办法获得更多关于发生错误的信息?看到 (pre-receive hook declined) 并没有真正表达问题的核心,即文件太大。

gitpython
1个回答
0
投票

push方法让我们可以提供自己的进度处理程序。我们可以做一个将git命令的原始输出打印出来的处理程序。 你可以让它做任何事情,记录它,收集它,但在这个例子中,我们只打印它。

要制作一个,我们可以基于 RemoteProgress 类,并覆盖 new_message_handler 方法。 这里面有一个函数,叫做 handler(line) 而似乎所有的原始输出行都会经过这里。 我们可以在它们的原始代码上加一个小的单行,以便在处理这些行的时候打印出来。

如果我们再将一个新类的实例传递到推送方法的 "进度 "参数中,我们就应该看到git命令的输出在运行时打印出来。

from git import Repo, RemoteProgress

class MyProgressPrinter(RemoteProgress):

    def new_message_handler(self):
        """
        :return:
            a progress handler suitable for handle_process_output(), passing lines on to this Progress
            handler in a suitable format"""
        def handler(line):
            print(line.rstrip())  # THIS IS THE LINE I ADDED TO THE ORIGINAL METHOD
            return self._parse_progress_line(line.rstrip())
        # end
        return handler

# Now that we've defined it, let's use it...

with Repo('path/to/my/repo/folder') as repo:
     origin = repo.remote()

     # And then pass in an instance of the new class when you perform your operation:

     result = origin.push(progress=MyProgressPrinter())

你可以找到原始的 RemoteProgress 阶级和 new_message_handler 方法,在这个文件中。https:/github.comgitpython-developersGitPythonblobmastergitutil.

© www.soinside.com 2019 - 2024. All rights reserved.