Skip to content

Commit

Permalink
feat: Enhance git_config functions to support worktree option AGWA#105
Browse files Browse the repository at this point in the history
  • Loading branch information
maxisam committed Nov 11, 2024
1 parent da5a8e4 commit 4948f77
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,12 @@ static std::vector<int> make_version (int a, int b, int c)
return version;
}

static void git_config (const std::string& name, const std::string& value)
static void git_config (const std::string& name, const std::string& value, bool from_worktree=true)
{
std::vector<std::string> command;
command.push_back("git");
command.push_back("config");
if (from_worktree) command.push_back("--worktree");
command.push_back(name);
command.push_back(value);

Expand All @@ -124,11 +125,12 @@ static void git_config (const std::string& name, const std::string& value)
}
}

static bool git_has_config (const std::string& name)
static bool git_has_config (const std::string& name, bool from_worktree)
{
std::vector<std::string> command;
command.push_back("git");
command.push_back("config");
if (from_worktree) command.push_back("--worktree");
command.push_back("--get-all");
command.push_back(name);

Expand All @@ -140,11 +142,12 @@ static bool git_has_config (const std::string& name)
}
}

static void git_deconfig (const std::string& name)
static void git_deconfig (const std::string& name, bool from_worktree=true)
{
std::vector<std::string> command;
command.push_back("git");
command.push_back("config");
if (from_worktree) command.push_back("--worktree");
command.push_back("--remove-section");
command.push_back(name);

Expand Down Expand Up @@ -277,12 +280,13 @@ static std::string get_internal_key_path (const char* key_name)
return path;
}

std::string get_git_config (const std::string& name)
std::string get_git_config (const std::string& name, bool from_worktree=true)
{
// git config --get
std::vector<std::string> command;
command.push_back("git");
command.push_back("config");
if (from_worktree) command.push_back("--worktree");
command.push_back("--get");
command.push_back(name);

Expand Down Expand Up @@ -321,7 +325,7 @@ static std::string get_repo_state_path ()
}

// Check if the repo state dir has been explicitly configured. If so, use that in path construction.
if (git_has_config("git-crypt.repoStateDir")) {
if (git_has_config("git-crypt.repoStateDir", false)) {
std::string repoStateDir = get_git_config("git-crypt.repoStateDir");

// The repoStateDir value must always be relative to git work tree to ensure the repoStateDir can be committed
Expand Down
2 changes: 1 addition & 1 deletion commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ void help_refresh (std::ostream&);
void help_status (std::ostream&);

// other
std::string get_git_config (const std::string& name);
std::string get_git_config (const std::string& name, bool from_worktree=true);

#endif

0 comments on commit 4948f77

Please sign in to comment.