LoginSignup
8
6

More than 5 years have passed since last update.

Git が dirty か判定する方法と CMake での応用例

Last updated at Posted at 2016-02-23

方法

git diff --shortstat --exit-code --quiet
  • 結果が 0 である -> dirty ではない
  • 結果が 0 ではない -> dirty である

実用例

CMake での応用

execute_process(
  COMMAND git diff --shortstat --exit-code --quiet
  WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  RESULT_VARIABLE version_git_dirty_flag
)

if( version_git_dirty_flag )
  message( "repository is dirty." )
endif()

Git リポジトリーの状態により branch や commit と併せて target_compile_options で渡して翻訳するソース内で使ったり、cmake の処理で扱いたい場合に使う。

Note

  • コマンドが出力する result とシェルの世界の true/false 、 cmake の世界の true/false それぞれ混乱しないように取り扱い注意。

Reference

8
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
6