| 299 | } |
| 300 | |
| 301 | static std::string get_repo_state_path () |
| 302 | { |
| 303 | // git rev-parse --show-toplevel |
| 304 | std::vector<std::string> command; |
| 305 | command.push_back("git"); |
| 306 | command.push_back("rev-parse"); |
| 307 | command.push_back("--show-toplevel"); |
| 308 | |
| 309 | std::stringstream output; |
| 310 | |
| 311 | if (!successful_exit(exec_command(command, output))) { |
| 312 | throw Error("'git rev-parse --show-toplevel' failed - is this a Git repository?"); |
| 313 | } |
| 314 | |
| 315 | std::string path; |
| 316 | std::getline(output, path); |
| 317 | |
| 318 | if (path.empty()) { |
| 319 | // could happen for a bare repo |
| 320 | throw Error("Could not determine Git working tree - is this a non-bare repo?"); |
| 321 | } |
| 322 | |
| 323 | // Check if the repo state dir has been explicitly configured. If so, use that in path construction. |
| 324 | if (git_has_config("git-crypt.repoStateDir")) { |
| 325 | std::string repoStateDir = get_git_config("git-crypt.repoStateDir"); |
| 326 | |
| 327 | // The repoStateDir value must always be relative to git work tree to ensure the repoStateDir can be committed |
| 328 | // along with the remainder of the repository. |
| 329 | path += '/' + repoStateDir; |
| 330 | } else { |
| 331 | // There is no explicitly configured repo state dir configured, so use the default. |
| 332 | path += "/.git-crypt"; |
| 333 | } |
| 334 | |
| 335 | return path; |
| 336 | } |
| 337 | |
| 338 | static std::string get_repo_keys_path (const std::string& repo_state_path) |
| 339 | { |
no test coverage detected