V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
biguli
V2EX  ›  问与答

git pre-receive 钩子求助

  •  
  •   biguli · 2022 年 7 月 14 日 · 609 次点击
    这是一个创建于 1364 天前的主题,其中的信息可能已经有所发展或是发生改变。
    老铁们,请教怎么在脚本里执行 git 命令
    想拦截掉某些 push 包含特定的 commit
    百度谷歌半天,都不行


    服务器上现有脚本如下:
    #!/usr/bin/env ruby


    # This file was placed here by GitLab. It makes sure that your pushed commits
    # will be processed properly.


    refs = $stdin.read
    gl_id = ENV.delete('GL_ID')
    protocol = ENV.delete('GL_PROTOCOL')
    repo_path = Dir.pwd
    gl_repository = ENV['GL_REPOSTTORY']


    def increase_reference_counter(gl_repository, repo_path)
    result = GitlabNet.new.pre_receive(gl_repository)

    result && result['reference_counter_increased']
    end

    require_relative '../lib/gitlab_custom_hook'
    require_relative '../lib/gitlab_access'
    require_relative '../lib/gitlab_net'


    # It’s important that on pre-receive 'increase_reference_counter' gets executed
    # last so that it only runs if everything else succeeded. On post-receive on the
    # other hand, we run GitlabPostReceive first because the push is already done
    # and we don’t want to skip it if the custom hook fails.
    if GitlabAccess.new(gl_repository, repo_path, gl_id, refs, protocol).exec &&
    GitlabCustomHook.new(repo_path, gl_id).pre_receive(refs) &&
    increase_reference_counter(gl_repository, repo_path)
    exit 0
    else
    exit 1
    end
    目前尚无回复
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   5531 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 07:49 · PVG 15:49 · LAX 00:49 · JFK 03:49
    ♥ Do have faith in what you're doing.