[git] always pass autocrlf=false
ADD
include/vcpkg/base/fwd/system.process.h
+#pragma once
+
+namespace vcpkg::System
+{
+ struct CMakeVariable;
+ struct Command;
+ struct CommandLess;
+}

MODIFY
include/vcpkg/base/system.process.h
include/vcpkg/base/system.process.h
#pragma once
+#include <vcpkg/base/fwd/system.process.h>
+
#include <vcpkg/base/files.h>
#include <vcpkg/base/zstringview.h>

MODIFY
include/vcpkg/vcpkgpaths.h
include/vcpkg/vcpkgpaths.h
#pragma once
#include <vcpkg/base/fwd/json.h>
+#include <vcpkg/base/fwd/system.process.h>
#include <vcpkg/fwd/configuration.h>
#include <vcpkg/fwd/registries.h>
@@ -118,6 +119,8 @@ namespace vcpkg
const fs::path& get_tool_exe(const std::string& tool) const;
const std::string& get_tool_version(const std::string& tool) const;
+ System::Command git_cmd_builder(const fs::path& dot_git_dir, const fs::path& work_tree) const;
+
// Git manipulation in the vcpkg directory
ExpectedS<std::string> get_current_git_sha() const;
std::string get_current_git_sha_message() const;

MODIFY
src/vcpkg/commands.porthistory.cpp
src/vcpkg/commands.porthistory.cpp
@@ -28,28 +28,11 @@ namespace vcpkg::Commands::PortHistory
Versions::Scheme scheme;
};
- const System::ExitCodeAndOutput run_git_command_inner(const VcpkgPaths& paths,
- const fs::path& dot_git_directory,
- const fs::path& working_directory,
- const System::Command& cmd)
+ System::ExitCodeAndOutput run_git_command(const VcpkgPaths& paths, const System::Command& cmd)
{
- const fs::path& git_exe = paths.get_tool_exe(Tools::GIT);
+ auto full_cmd = paths.git_cmd_builder(paths.root / ".git", paths.root).raw_arg(cmd.command_line());
- auto full_cmd = System::Command(git_exe)
- .string_arg(Strings::concat("--git-dir=", fs::u8string(dot_git_directory)))
- .string_arg(Strings::concat("--work-tree=", fs::u8string(working_directory)))
- .raw_arg(cmd.command_line());
-
- auto output = System::cmd_execute_and_capture_output(full_cmd);
- return output;
- }
-
- const System::ExitCodeAndOutput run_git_command(const VcpkgPaths& paths, const System::Command& cmd)
- {
- const fs::path& work_dir = paths.root;
- const fs::path dot_git_dir = paths.root / ".git";
-
- return run_git_command_inner(paths, dot_git_dir, work_dir, cmd);
+ return System::cmd_execute_and_capture_output(full_cmd);
}
vcpkg::Optional<HistoryVersion> get_version_from_text(const std::string& text,

MODIFY
src/vcpkg/commands.portsdiff.cpp
src/vcpkg/commands.portsdiff.cpp
@@ -82,7 +82,6 @@ namespace vcpkg::Commands::PortsDiff
{
std::error_code ec;
auto& fs = paths.get_filesystem();
- const fs::path& git_exe = paths.get_tool_exe(Tools::GIT);
const fs::path dot_git_dir = paths.root / ".git";
const std::string ports_dir_name_as_string = fs::u8string(paths.builtin_ports_directory().filename());
const fs::path temp_checkout_path =
@@ -91,9 +90,7 @@ namespace vcpkg::Commands::PortsDiff
const auto checkout_this_dir =
Strings::format(R"(.\%s)", ports_dir_name_as_string); // Must be relative to the root of the repository
- auto cmd = System::Command(git_exe)
- .string_arg(Strings::format("--git-dir=%s", fs::u8string(dot_git_dir)))
- .string_arg(Strings::format("--work-tree=%s", fs::u8string(temp_checkout_path)))
+ auto cmd = paths.git_cmd_builder(dot_git_dir, temp_checkout_path)
.string_arg("checkout")
.string_arg(git_commit_id)
.string_arg("-f")
@@ -102,7 +99,8 @@ namespace vcpkg::Commands::PortsDiff
.string_arg(checkout_this_dir)
.string_arg(".vcpkg-root");
System::cmd_execute_and_capture_output(cmd, System::get_clean_environment());
- System::cmd_execute_and_capture_output(System::Command(git_exe).string_arg("reset"),
+ System::cmd_execute_and_capture_output(
+ paths.git_cmd_builder(dot_git_dir, temp_checkout_path).string_arg("reset"),
System::get_clean_environment());
const auto ports_at_commit = Paragraphs::load_overlay_ports(fs, temp_checkout_path / ports_dir_name_as_string);
std::map<std::string, VersionT> names_and_versions;
@@ -115,11 +113,14 @@ namespace vcpkg::Commands::PortsDiff
return names_and_versions;
}
- static void check_commit_exists(const fs::path& git_exe, const std::string& git_commit_id)
+ static void check_commit_exists(const VcpkgPaths& paths, const std::string& git_commit_id)
{
static const std::string VALID_COMMIT_OUTPUT = "commit\n";
- auto cmd = System::Command(git_exe).string_arg("cat-file").string_arg("-t").string_arg(git_commit_id);
+ auto cmd = paths.git_cmd_builder(paths.root / ".git", paths.root)
+ .string_arg("cat-file")
+ .string_arg("-t")
+ .string_arg(git_commit_id);
const System::ExitCodeAndOutput output = System::cmd_execute_and_capture_output(cmd);
Checks::check_exit(
VCPKG_LINE_INFO, output.output == VALID_COMMIT_OUTPUT, "Invalid commit id %s", git_commit_id);
@@ -137,14 +138,13 @@ namespace vcpkg::Commands::PortsDiff
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths)
{
(void)args.parse_arguments(COMMAND_STRUCTURE);
- const fs::path& git_exe = paths.get_tool_exe(Tools::GIT);
const std::string git_commit_id_for_previous_snapshot = args.command_arguments.at(0);
const std::string git_commit_id_for_current_snapshot =
args.command_arguments.size() < 2 ? "HEAD" : args.command_arguments.at(1);
- check_commit_exists(git_exe, git_commit_id_for_current_snapshot);
- check_commit_exists(git_exe, git_commit_id_for_previous_snapshot);
+ check_commit_exists(paths, git_commit_id_for_current_snapshot);
+ check_commit_exists(paths, git_commit_id_for_previous_snapshot);
const std::map<std::string, VersionT> current_names_and_versions =
read_ports_from_commit(paths, git_commit_id_for_current_snapshot);

MODIFY
src/vcpkg/vcpkgpaths.cpp
src/vcpkg/vcpkgpaths.cpp
@@ -70,13 +70,6 @@ namespace
return result;
}
- System::Command git_cmd_builder(const VcpkgPaths& paths, const fs::path& dot_git_dir, const fs::path& work_tree)
- {
- return System::Command()
- .path_arg(paths.get_tool_exe(Tools::GIT))
- .string_arg(Strings::concat("--git-dir=", fs::u8string(dot_git_dir)))
- .string_arg(Strings::concat("--work-tree=", fs::u8string(work_tree)));
- }
} // unnamed namespace
namespace vcpkg
@@ -522,6 +515,15 @@ If you wish to silence this error and use classic mode, you can:
return m_pimpl->m_tool_cache->get_tool_version(*this, tool);
}
+ System::Command VcpkgPaths::git_cmd_builder(const fs::path& dot_git_dir, const fs::path& work_tree) const
+ {
+ return System::Command(get_tool_exe(Tools::GIT))
+ .string_arg(Strings::concat("--git-dir=", fs::u8string(dot_git_dir)))
+ .string_arg(Strings::concat("--work-tree=", fs::u8string(work_tree)))
+ .string_arg("-c")
+ .string_arg("core.autocrlf=false");
+ }
+
void VcpkgPaths::git_checkout_subpath(const VcpkgPaths& paths,
StringView commit_sha,
const fs::path& subpath,
@@ -538,7 +540,7 @@ If you wish to silence this error and use classic mode, you can:
// All git commands are run with: --git-dir={dot_git_dir} --work-tree={work_tree_temp}
// git clone --no-checkout --local --no-hardlinks {vcpkg_root} {dot_git_dir}
// note that `--no-hardlinks` is added because otherwise, git fails to clone in some cases
- System::Command clone_cmd_builder = git_cmd_builder(paths, dot_git_dir, work_tree)
+ System::Command clone_cmd_builder = paths.git_cmd_builder(dot_git_dir, work_tree)
.string_arg("clone")
.string_arg("--no-checkout")
.string_arg("--local")
@@ -552,7 +554,7 @@ If you wish to silence this error and use classic mode, you can:
clone_output.output);
// git checkout {commit-sha} -- {subpath}
- System::Command checkout_cmd_builder = git_cmd_builder(paths, dot_git_dir, work_tree)
+ System::Command checkout_cmd_builder = paths.git_cmd_builder(dot_git_dir, work_tree)
.string_arg("checkout")
.string_arg(commit_sha)
.string_arg("--")
@@ -588,7 +590,7 @@ If you wish to silence this error and use classic mode, you can:
ExpectedS<std::string> VcpkgPaths::get_current_git_sha() const
{
- auto cmd = git_cmd_builder(*this, this->root / fs::u8path(".git"), this->root);
+ auto cmd = git_cmd_builder(this->root / fs::u8path(".git"), this->root);
cmd.string_arg("rev-parse").string_arg("HEAD");
auto output = System::cmd_execute_and_capture_output(cmd);
if (output.exit_code != 0)
@@ -617,8 +619,7 @@ If you wish to silence this error and use classic mode, you can:
{
// All git commands are run with: --git-dir={dot_git_dir} --work-tree={work_tree_temp}
// git clone --no-checkout --local {vcpkg_root} {dot_git_dir}
- System::Command showcmd =
- git_cmd_builder(*this, dot_git_dir, dot_git_dir).string_arg("show").string_arg(treeish);
+ System::Command showcmd = git_cmd_builder(dot_git_dir, dot_git_dir).string_arg("show").string_arg(treeish);
auto output = System::cmd_execute_and_capture_output(showcmd);
if (output.exit_code == 0)
@@ -636,7 +637,7 @@ If you wish to silence this error and use classic mode, you can:
const auto local_repo = this->root / fs::u8path(".git");
const auto path_with_separator =
Strings::concat(fs::u8string(this->builtin_ports_directory()), Files::preferred_separator);
- const auto git_cmd = git_cmd_builder(*this, local_repo, this->root)
+ const auto git_cmd = git_cmd_builder(local_repo, this->root)
.string_arg("ls-tree")
.string_arg("-d")
.string_arg("HEAD")
@@ -773,9 +774,7 @@ If you wish to silence this error and use classic mode, you can:
expected_right_tag};
}
- auto tar_cmd_builder = git_cmd_builder(*this, dot_git_dir, dot_git_dir)
- .string_arg("-c")
- .string_arg("core.autocrlf=false")
+ auto tar_cmd_builder = git_cmd_builder(dot_git_dir, dot_git_dir)
.string_arg("archive")
.string_arg(git_tree)
.string_arg("-o")
@@ -832,7 +831,7 @@ If you wish to silence this error and use classic mode, you can:
fs.create_directories(work_tree, VCPKG_LINE_INFO);
auto dot_git_dir = m_pimpl->registries_dot_git_dir;
- System::Command init_registries_git_dir = git_cmd_builder(*this, dot_git_dir, work_tree).string_arg("init");
+ System::Command init_registries_git_dir = git_cmd_builder(dot_git_dir, work_tree).string_arg("init");
auto init_output = System::cmd_execute_and_capture_output(init_registries_git_dir);
if (init_output.exit_code != 0)
{
@@ -847,7 +846,7 @@ If you wish to silence this error and use classic mode, you can:
std::error_code ec;
Files::ExclusiveFileLock guard(Files::ExclusiveFileLock::Wait::Yes, fs, lock_file, ec);
- System::Command fetch_git_ref = git_cmd_builder(*this, dot_git_dir, work_tree)
+ System::Command fetch_git_ref = git_cmd_builder(dot_git_dir, work_tree)
.string_arg("fetch")
.string_arg("--update-shallow")
.string_arg("--")
@@ -869,7 +868,7 @@ If you wish to silence this error and use classic mode, you can:
}
System::Command get_fetch_head =
- git_cmd_builder(*this, dot_git_dir, work_tree).string_arg("rev-parse").string_arg("FETCH_HEAD");
+ git_cmd_builder(dot_git_dir, work_tree).string_arg("rev-parse").string_arg("FETCH_HEAD");
auto fetch_head_output = System::cmd_execute_and_capture_output(get_fetch_head);
if (fetch_head_output.exit_code != 0)
{
@@ -884,8 +883,7 @@ If you wish to silence this error and use classic mode, you can:
const fs::path& relative_path) const
{
auto revision = Strings::format("%s:%s", hash, fs::generic_u8string(relative_path));
- System::Command git_show =
- git_cmd_builder(*this, m_pimpl->registries_dot_git_dir, m_pimpl->registries_work_tree_dir)
+ System::Command git_show = git_cmd_builder(m_pimpl->registries_dot_git_dir, m_pimpl->registries_work_tree_dir)
.string_arg("show")
.string_arg(revision);
@@ -901,7 +899,7 @@ If you wish to silence this error and use classic mode, you can:
{
auto revision = Strings::format("%s:%s", hash, fs::generic_u8string(relative_path));
System::Command git_rev_parse =
- git_cmd_builder(*this, m_pimpl->registries_dot_git_dir, m_pimpl->registries_work_tree_dir)
+ git_cmd_builder(m_pimpl->registries_dot_git_dir, m_pimpl->registries_work_tree_dir)
.string_arg("rev-parse")
.string_arg(revision);
@@ -931,7 +929,7 @@ If you wish to silence this error and use classic mode, you can:
fs.create_directory(git_tree_temp, VCPKG_LINE_INFO);
auto dot_git_dir = m_pimpl->registries_dot_git_dir;
- System::Command git_archive = git_cmd_builder(*this, dot_git_dir, m_pimpl->registries_work_tree_dir)
+ System::Command git_archive = git_cmd_builder(dot_git_dir, m_pimpl->registries_work_tree_dir)
.string_arg("archive")
.string_arg("--format")
.string_arg("tar")

[git] always pass autocrlf=false (#58)