-
Notifications
You must be signed in to change notification settings - Fork 1
/
RepoManStatus.cmake
87 lines (74 loc) · 2.79 KB
/
RepoManStatus.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# Show the status of a git project with regard to an expected state
# Check for missing arguments
foreach(ARGUMENT IN ITEMS NAME REPO EXPECTED_REVISION EXPECTED_REMOTE)
if(NOT ${ARGUMENT})
message(FATAL_ERROR "${ARGUMENT} is not defined.")
endif()
endforeach()
find_program(GIT_COMMAND git REQUIRED)
mark_as_advanced(GIT_COMMAND)
set(STATUS "")
# Update repo
execute_process(COMMAND ${GIT_COMMAND} fetch --all
OUTPUT_QUIET
WORKING_DIRECTORY ${REPO})
# Check remote
execute_process(COMMAND ${GIT_COMMAND} remote get-url origin
WORKING_DIRECTORY ${REPO}
OUTPUT_VARIABLE REMOTE
OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND_ERROR_IS_FATAL ANY)
if(NOT EXPECTED_REMOTE STREQUAL REMOTE)
string(APPEND STATUS "Remote: ${REMOTE} (expected ${EXPECTED_REMOTE})")
endif()
# Check current HEAD
execute_process(COMMAND ${GIT_COMMAND} show --no-patch --pretty="%D, %h" HEAD
WORKING_DIRECTORY ${REPO}
OUTPUT_VARIABLE LOCAL_REVISION
OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND_ERROR_IS_FATAL ANY)
string(REPLACE "\"" "" LOCAL_REVISION ${LOCAL_REVISION})
string(REPLACE "tag: " "" LOCAL_REVISION ${LOCAL_REVISION})
string(REPLACE ", " ";" LOCAL_REVISION ${LOCAL_REVISION})
execute_process(COMMAND ${GIT_COMMAND} branch --show-current
WORKING_DIRECTORY ${REPO}
OUTPUT_VARIABLE LOCAL_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(LOCAL_BRANCH)
list(APPEND LOCAL_REVISION ${LOCAL_BRANCH})
endif()
set(REVISION "")
list(REVERSE LOCAL_REVISION)
foreach(ITEM IN LISTS LOCAL_REVISION)
if(NOT ITEM MATCHES "^HEAD.*")
if(EXPECTED_REVISION STREQUAL ITEM)
unset(FOUND_REVISION)
break()
else()
set(FOUND_REVISION "Revision: ${ITEM} (expected ${EXPECTED_REVISION})")
endif()
endif()
endforeach()
if(FOUND_REVISION)
string(APPEND STATUS "${FOUND_REVISION})")
endif()
# Check for modifications
execute_process(COMMAND "${GIT_COMMAND}" describe --always --dirty --broken
WORKING_DIRECTORY ${REPO}
OUTPUT_VARIABLE GIT_STATUS
OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND_ERROR_IS_FATAL ANY)
if(GIT_STATUS MATCHES ".*-dirty")
execute_process(COMMAND "${GIT_COMMAND}" status --show-stash --renames --ahead-behind
WORKING_DIRECTORY "${REPO}"
OUTPUT_VARIABLE GIT_STATUS
OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND_ERROR_IS_FATAL ANY)
string(APPEND STATUS "\nStatus:\n${GIT_STATUS}")
endif()
# Print status
if(STATUS)
message(STATUS "Dependency '${NAME}': ${STATUS}")
else()
message(STATUS "Dependency '${NAME}': ok (${EXPECTED_REVISION})")
endif()