-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use only Git commands in git_info
#179
Conversation
endif() | ||
|
||
configure_file( | ||
${PROJECT_SOURCE_DIR}/cmake/downloaded/git_info.h.in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bast This path is hardcoded. I was not able to find a permanent fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @robertodr ,
is there some requirements as to the git version ? Change is based on git flags, would be good to know what is the lowest git version...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@miroi The oldest version of Git I have access to is 1.7.1 and these commands work fine.
Might be that for Git <= 1.6 git log
should be used instead of git show
:
For the commit hash:
git --no-pager log -1 --pretty=format:"%h" -n 1
For the author name:
git --no-pager log -1 --pretty=format:"%aN" -n 1
For the commit date:
git --no-pager log -1 --pretty=format:"%ad" -n 1
Thanks! Can you summarize in one or two sentences what has changed? A bit tricky to see from the diff. Why is the test failing? You write that a path is hardcoded - how would you ideally like the code to be if it was not hardcoded? In other words what did you have in mind? |
@bast Before my changes that line read |
Do you have an idea why the OS X tests failed? |
The hardcoding can be solved like this:
Also I wonder whether we should not drop the default parameters but always require explicit parameters from the outside to simplify code and make things more explicit. |
@bast I have integrated your modifications. The failure on Mac seems unrelated to this PR, maybe a failure in running |
Thanks! Looks good now. I will test a bit more on my side and integrate very soon. |
Merged - however I will remove the defaults and the function needs to be called explicitly always. I think this is better. |
I left the default arguments not to hurt existing code using this module. I fully agree with you, explicit is better than implicit. |
I have changed it to explicit. The change anyway requires codes to add at least one line. |
This PR removes the need for CMake regexes to find the commit author name.
Moreover, the header can be generated in a custom directory and with a custom name.
@bast @miroi I have fixed the test and fine-tuned the implementation:
add_custom_command
ingit_info.cmake
with a CMake functiongenerate_git_info_header
(the name can be changed) to fine-tune how the header is generated. The user can now choose location and name. If no arguments are provided to the function, this falls back to the previous implementation, i.e. generate agit_info.h
header in${PROJECT_BINARY_DIR}
git_info_sub.cmake
file, since it is no longer necessary.