Skip to content

Commit

Permalink
fix: throw on non existing ssh key paths
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaDucak committed Jan 16, 2024
1 parent 124a67c commit d32011c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
14 changes: 11 additions & 3 deletions source/utils/git_repo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,21 @@ bool hasChangedFiles(git_repository *repo) {

return status_count > 0;
}
GitRepo::GitRepo(const std::filesystem::path &path, std::string sshKeyPath,
std::string sshPubKeyPath, std::string remoteName, std::string mainBranchName)
GitRepo::GitRepo(const std::filesystem::path &path, const std::filesystem::path &sshKeyPath,
const std::filesystem::path &sshPubKeyPath, std::string remoteName,
std::string mainBranchName)
: m_remoteName{std::move(remoteName)}, m_mainBranchName{std::move(mainBranchName)},
m_sshKeyPath{std::move(sshKeyPath)}, m_sshPubKeyPath{std::move(sshPubKeyPath)} {
m_sshKeyPath{sshKeyPath}, m_sshPubKeyPath{sshPubKeyPath} {
if (m_sshKeyPath.empty() || m_sshPubKeyPath.empty()) {
throw std::invalid_argument{"SSH keys are not set!"};
}
if (not std::filesystem::exists(m_sshKeyPath)) {
throw std::invalid_argument{"SSH key does not exist: " + m_sshKeyPath};
}
if (not std::filesystem::exists(m_sshPubKeyPath)) {
throw std::invalid_argument{std::string{"SSH public key does not exist: "} +
m_sshPubKeyPath};
}
if (m_remoteName.empty()) {
throw std::invalid_argument{"Remote name can not be empty!"};
}
Expand Down
5 changes: 3 additions & 2 deletions source/utils/git_repo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ class GitRepo {
std::string m_sshKeyPath;

public:
GitRepo(const std::filesystem::path &path, std::string sshKeyPath, std::string sshPubKeyPath,
std::string remoteName = "origin", std::string mainBranchName = "master");
GitRepo(const std::filesystem::path &path, const std::filesystem::path &sshKeyPath,
const std::filesystem::path &sshPubKeyPath, std::string remoteName = "origin",
std::string mainBranchName = "master");

GitRepo(const GitRepo &) = delete;
GitRepo(GitRepo &&) noexcept;
Expand Down

0 comments on commit d32011c

Please sign in to comment.