Skip to content

Commit a5529c1

Browse files
committed
feat: Enhance git_config functions to support worktree option AGWA#105
1 parent da5a8e4 commit a5529c1

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

commands.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,12 @@ static std::vector<int> make_version (int a, int b, int c)
111111
return version;
112112
}
113113

114-
static void git_config (const std::string& name, const std::string& value)
114+
static void git_config (const std::string& name, const std::string& value, bool from_worktree=true)
115115
{
116116
std::vector<std::string> command;
117117
command.push_back("git");
118118
command.push_back("config");
119+
if (from_worktree) command.push_back("--worktree");
119120
command.push_back(name);
120121
command.push_back(value);
121122

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

127-
static bool git_has_config (const std::string& name)
128+
static bool git_has_config (const std::string& name, bool from_worktree=true)
128129
{
129130
std::vector<std::string> command;
130131
command.push_back("git");
131132
command.push_back("config");
133+
if (from_worktree) command.push_back("--worktree");
132134
command.push_back("--get-all");
133135
command.push_back(name);
134136

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

143-
static void git_deconfig (const std::string& name)
145+
static void git_deconfig (const std::string& name, bool from_worktree=true)
144146
{
145147
std::vector<std::string> command;
146148
command.push_back("git");
147149
command.push_back("config");
150+
if (from_worktree) command.push_back("--worktree");
148151
command.push_back("--remove-section");
149152
command.push_back(name);
150153

@@ -277,12 +280,13 @@ static std::string get_internal_key_path (const char* key_name)
277280
return path;
278281
}
279282

280-
std::string get_git_config (const std::string& name)
283+
std::string get_git_config (const std::string& name, bool from_worktree=true)
281284
{
282285
// git config --get
283286
std::vector<std::string> command;
284287
command.push_back("git");
285288
command.push_back("config");
289+
if (from_worktree) command.push_back("--worktree");
286290
command.push_back("--get");
287291
command.push_back(name);
288292

@@ -321,7 +325,7 @@ static std::string get_repo_state_path ()
321325
}
322326

323327
// 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")) {
328+
if (git_has_config("git-crypt.repoStateDir", false)) {
325329
std::string repoStateDir = get_git_config("git-crypt.repoStateDir");
326330

327331
// The repoStateDir value must always be relative to git work tree to ensure the repoStateDir can be committed

commands.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,6 @@ void help_refresh (std::ostream&);
7171
void help_status (std::ostream&);
7272

7373
// other
74-
std::string get_git_config (const std::string& name);
74+
std::string get_git_config (const std::string& name, bool from_worktree=true);
7575

7676
#endif

0 commit comments

Comments
 (0)