Reputation: 3052
In a repository where I cant set both user.name
and user.email
configurations I need to script a commit with:
commit -a --message "message" --author="author"
Message and author are parametrized.
When I commit with a wrong author (not present on rev-list
and bad formatted for git) I get:
fatal: --author 'bad-formatted-author' is not 'Name ' and matches no existing author
Is there any way to check against git if the author is valid before the commit?
Upvotes: 4
Views: 3158
Reputation: 18556
Use git commit -a --message "message" --author="author" --dry-run
.
The added --dry-run
flag will make git commit
not actually commit anything but still exit non-zero if the --author
option string given is invalid.
Note, however, that there may be other reasons the exit status is non-zero, such as the commit being empty (i.e. not having any changes).
Upvotes: 5
Reputation: 488053
This really is right in the documentation:
--author=author
Override the commit author. Specify an explicit author using the standard
A U Thor <[email protected]>
format. Otherwiseauthor
is assumed to be a pattern and is used to search for an existing commit by that author (i.e.rev-list --all -i --author=author
); the commit author is then copied from the first such commit found.
You even copied these in your question:
not present on rev-list and bad formatted for git
which means this is your answer: check the format to see if it matches the Name <email>
style, and if not, run git rev-list
with the parameters shown to see if there is at least one matching commit.
In general, though, it's probably simpler to just attempt the commit and catch the failure.
Upvotes: 2