Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/src/Progmasoft/Runner/Git.hpp
blob: 44340c1bcd11741b4b99dce9231f8f0a9c895173 (plain)
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
// Copyright (c) 2026 Progmasoft.
// SPDX-License-Identifier: MPL-2.0 WITH AdditionRef-Progmasoft-Exception-2.0
#pragma once

#include "Expected.hpp"

#include <filesystem>
#include <string>
#include <vector>

namespace Progmasoft::Catch3::Runner
{
    /// What Git says about the checkout the tests come from.
    struct Changes final
    {
        std::filesystem::path root;
        std::string commit;
        /// Changed since the revision, staged or not, and untracked files;
        /// absolute paths.
        std::vector<std::filesystem::path> files;
    };

    /// The changes since `revision` (HEAD when empty) in the checkout that
    /// holds `directory`. An error when Git or the checkout is missing.
    [[nodiscard]] Expected<Changes>
    ReadChanges(const std::filesystem::path &directory,
                const std::string &revision);

    /// The commit checked out in the checkout that holds `directory`, or
    /// empty.
    [[nodiscard]] std::string
    CurrentCommit(const std::filesystem::path &directory);

    /// Whether two spellings name the same source file: equal after
    /// normalisation, or one a relative path the other ends with.
    [[nodiscard]] bool
    SameSourceFile(const std::filesystem::path &left,
                   const std::filesystem::path &right);
} // namespace Progmasoft::Catch3::Runner