I want to construct and execute the following git log statement to get summary of commits for yesterday for specific authors: name1
and name2
, so the final desired executed git log should be as follows:
git log --author name1 --author name2
--since yesterday --reverse
--pretty=format:"%h - %an , %ad : %s" > commits.txt
As you may notice output is redirected to commits.txt
file.
The output commits.txt
file should finally contain some text like this:
350411e - name1, Mon Apr 18 18:03:01 2016 +0200 : Fix bug X
366411e - name2, Mon Apr 18 18:05:06 2016 +0200 : Introduce feature Y
752411e - name1, Mon Apr 18 18:11:12 2016 +0200 : Merge version Z
Here's my code in script.sh
team=( name1 name2 )
function create_commits_log_file () {
authors=''
for author in "${@}"
do
authors="$authors --author $author "
done
git_log_statement="git log $authors --since yesterday --reverse --pretty=format:\"%h - %an , %ad : %s\" > commits.txt"
echo "$git_log_statement"
$git_log_statement
}
create_commits_log_file "${team[@]}"
Unfortunately when I run it as bash script.sh
, it throws an error:
git log --author name1 --author name2 --since yesterday --reverse --pretty=format:"%h - %an , %ad : %s" > commits.txt
fatal: ambiguous argument '%an': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this: 'git [...] -- [...]'
Despite that if I run the echo
'ed git command on console it works perfectly!
What is the problem ? and how may I fix it ?
UPDATE - Attempt:
Based on comments, I also tried to execute the git log command directly without storing it in a variable as follows :
team=( ashraf.bashir diego.palacios )
function create_commits_log_file () {
authors=''
for author in "${@}"
do
authors="$authors --author $author "
done
git log $authors --since yesterday --reverse --pretty=format:\"%h - %an , %ad : %s\" >commits.txt
}
create_commits_log_file "${team[@]}"
But I am still getting the same error