I have a list of git commits in a .txt file and I want to iterate over the commits. For each COMMIT_ID I want check them using a git command whose exit code is 0 or 1.
Depending on the result I want to echo true or false.
But when running the script, I get this error:
line 5: [: 0: unary operator expected
The script is as follows:
#!/usr/bin/env bash
input="./commits.txt"
while IFS= read -r COMMIT_ID
do
if [ 0 -eq $(git merge-base --is-ancestor $COMMIT_ID HEAD) ];
then
echo "true";
else
echo "false";
fi
done < "$input"