Skip to content

Commit 64a3899

Browse files
authored
Merge pull request #12331 from DeterminateSystems/git-dir
GitRepo::fetch(): Ignore $GIT_DIR
2 parents 2975c2c + 41983db commit 64a3899

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

src/libfetchers/git-utils.cc

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ static git_packbuilder_progress PACKBUILDER_PROGRESS_CHECK_INTERRUPT = &packBuil
206206

207207
} // extern "C"
208208

209-
static void initRepoAtomically(std::filesystem::path &path, bool bare) {
209+
static void initRepoAtomically(std::filesystem::path &path, bool bare)
210+
{
210211
if (pathExists(path.string())) return;
211212

212213
Path tmpDir = createTempDir(os_string_to_string(PathViewNG { std::filesystem::path(path).parent_path() }));
@@ -544,13 +545,10 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
544545
// then use code that was removed in this commit (see blame)
545546

546547
auto dir = this->path;
547-
Strings gitArgs;
548-
if (shallow) {
549-
gitArgs = { "-C", dir.string(), "fetch", "--quiet", "--force", "--depth", "1", "--", url, refspec };
550-
}
551-
else {
552-
gitArgs = { "-C", dir.string(), "fetch", "--quiet", "--force", "--", url, refspec };
553-
}
548+
Strings gitArgs{"-C", dir.string(), "--git-dir", ".", "fetch", "--quiet", "--force"};
549+
if (shallow)
550+
append(gitArgs, {"--depth", "1"});
551+
append(gitArgs, {std::string("--"), url, refspec});
554552

555553
runProgram(RunOptions {
556554
.program = "git",

src/libutil/util.hh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,17 @@ std::optional<typename T::value_type> pop(T & c)
274274
}
275275

276276

277+
/**
278+
* Append items to a container. TODO: remove this once we can use
279+
* C++23's `append_range()`.
280+
*/
281+
template<class C, typename T>
282+
void append(C & c, std::initializer_list<T> l)
283+
{
284+
c.insert(c.end(), l.begin(), l.end());
285+
}
286+
287+
277288
template<typename T>
278289
class Callback;
279290

tests/functional/common/vars.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ unset XDG_DATA_HOME
6060
unset XDG_CONFIG_HOME
6161
unset XDG_CONFIG_DIRS
6262
unset XDG_CACHE_HOME
63+
unset GIT_DIR
6364

6465
export IMPURE_VAR1=foo
6566
export IMPURE_VAR2=bar

0 commit comments

Comments
 (0)