如何在bash脚本中检查空樱桃挑选?

时间:2017-11-16 04:56:38

标签: git bash cherry-pick git-cherry-pick

我有一个bash脚本,它按照cherry-pick命令运行:

if git cherry-pick -x "$commitId"; then
        ammed_commit "$BRANCH" 
  else
      #here I want to check if this resulted in empty commit
fi

我尝试再次运行命令并在字符串中输出然后比较字符串,但输出不是我在控制台中看到的。我正在使用以下脚本进行测试:

#!/bin/bash

READ_STATUS=$(git cherry-pick -x 001e6beda)
SUB_STRING="The previous cherry-pick is now empty"

echo $READ_STATUS

stringContain() { [ -z "${2##*$1*}" ]; }

if stringContain "$READ_STATUS" 'The previous cherry-pick is now empty';then 
  echo yes
else 
  echo no
fi

exit

以下是我运行此脚本时收到的输出:

The previous cherry-pick is now empty, possibly due to conflict resolution.
If you wish to commit it anyway, use:

git commit --allow-empty

Otherwise, please use 'git reset'
//READ_STATUS gets this value and not the one above this line???
On branch test-stage Your branch is ahead of 'upstream/test-stage' by 1 commit. (use "git push" to publish your local commits) You are currently cherry-picking commit 001e6beda. nothing to commit, working tree clean
no

所以我有两个问题:

  1. 为什么我的字符串没有得到完整的输出?
  2. 如何解决此问题并成功检查cherry-pick是否导致空提交?

1 个答案:

答案 0 :(得分:2)

READ_STATUS=$(git cherry-pick -x 001e6beda)将其错误消息发送到stderr,而不是stdout。当{git失败时,read_status=$(git cherry-pick -x 001e6beda 2>&1) empty_message="The previous cherry-pick is now empty" if [[ $read_status = *"$empty_message"* ]]; then echo yes else echo no fi 捕获stdout并将READ_STATUS设置为空。

您可以这样重写代码:

div[role="columnheader"] {
    display: table;
    width: 100%;
}

.ui-grid-header-cell .ui-grid-cell-contents {
    height: 58px;
    /* white-space: normal !important; */
    /* -ms-text-overflow: clip; */
    /* -o-text-overflow: clip; */
    /* text-overflow: clip; */
    /* overflow: visible; */
    /* text-align: center; */
    display: table-cell;
    vertical-align: bottom;
}

另见: