Fastlane Git_commit动作 - 如果没有任何提交的话,请跳过



我使用git_commit动作:

git_commit(路径:"*",消息:"消息")

如果没有提起的话,此操作将失败。即使没有提起的话,我如何继续执行我的菜谱?

我要寻找的是两个选项中的任何一个:

  1. git_commit操作中添加一些参数,因此如果没有提交(而是继续),它不会崩溃脚本
  2. 检查是否有任何更改,然后调用git_commit

我找不到使用方法1完成此操作的方法,所以我正在寻找使用第二种方法的实现。

您可以尝试断言状态很干净,捕获例外,并通过git commit进行处理:

begin
  ensure_git_status_clean
rescue
  git_commit
end

另外,您可以使用sh操作在Shell

中执行您想做的任何事情

您可以实现一个脚本,该脚本告诉您是否有分阶段更改,然后使用输出来确定是否应该创建提交。

以下脚本返回1,如果有任何阶段更改,否则为0。

#!/bin/bash
if [[ -n "$(git diff --name-only --cached)" ]]
then
  exit 1
else
  exit 0
fi

假设您将脚本命名 CheckStagedFiles ,您必须将以下内容添加到您的车道:

shouldCommit = sh(".CheckStagedFiles.sh")
if shouldCommit
    git_commit(path: "*", message: "message")
end

最新更新