aboutsummaryrefslogtreecommitdiff
path: root/git.cc.in
blob: 62cf4e991f900ddaec3de0ea1df0e540c232a9df (plain) (blame)
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
#include <cstdlib>
#include <iostream>

#include "git.h"
#include "cmake.h"

const char *version = "version info:\n";

bool GitMetadata::Populated() {
    return @GIT_RETRIEVED_STATE@;
}
bool GitMetadata::AnyUncommittedChanges() {
    return @GIT_IS_DIRTY@;
}
std::string GitMetadata::AuthorName() {
    return "@GIT_AUTHOR_NAME@";
}
std::string GitMetadata::AuthorEmail() {
    return "@GIT_AUTHOR_EMAIL@";
}
std::string GitMetadata::CommitSHA1() {
    return "@GIT_HEAD_SHA1@";
}
std::string GitMetadata::CommitDate() {
    return "@GIT_COMMIT_DATE_ISO8601@";
}
std::string GitMetadata::CommitSubject() {
    return "@GIT_COMMIT_SUBJECT@";
}
std::string GitMetadata::CommitBody() {
    return "@GIT_COMMIT_BODY@";
}
std::string GitMetadata::Describe() {
    return "@GIT_DESCRIBE@";
}
std::string GitMetadata::Branch() {
    return "@GIT_BRANCH@";
}
__attribute__ ((visibility ("default"))) void GitMetadata::VersionInfo() {
   std::cout << PROJECT_NAME << ": " << PROJECT_VER << std::endl;

   if(GitMetadata::Populated()) {
        if(GitMetadata::AnyUncommittedChanges()) {
            std::cerr << "\t" << "WARN: there were uncommitted changes at build-time." << std::endl;
        }
        std::cout << "\t" << "commit " << GitMetadata::CommitSHA1() << " (" << GitMetadata::Branch() << ")\n"
                  << "\t" << "describe " << GitMetadata::Describe() << "\n"
                  << "\t" << "Author: " << GitMetadata::AuthorName() << " <" << GitMetadata::AuthorEmail() << ">\n"
                  << "\t" << "Date: " << GitMetadata::CommitDate() << "\n\n"
                  << "\t" << GitMetadata::CommitSubject() << "\n" << GitMetadata::CommitBody() << std::endl;
    }
    else {
#ifdef MANUAL_GITINFO
        std::cerr << "INFO: manual git info: " << MANUAL_GITINFO << std::endl;
#else
        std::cerr << "WARN: no manual git info defined " << std::endl;
#endif
    }
}