Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[versioning] Add message when vcpkg is cloned to a shallow repository #737

Merged
merged 5 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/vcpkg/base/messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -1379,6 +1379,11 @@ namespace vcpkg
"An example of env_var is \"HTTP(S)_PROXY\""
"'--' at the beginning must be preserved",
"-- Setting \"{env_var}\" environment variables to \"{url}\".");
DECLARE_MESSAGE(ShallowRepositoryDetected,
(msg::path),
"",
"vcpkg was cloned as a shallow repository in: {path}\n"
"Try again with a full vcpkg clone.");
DECLARE_MESSAGE(ShaPassedAsArgAndOption,
(),
"",
Expand Down
1 change: 1 addition & 0 deletions include/vcpkg/vcpkgpaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ namespace vcpkg
std::string get_current_git_sha_baseline_message() const;
ExpectedS<Path> git_checkout_port(StringView port_name, StringView git_tree, const Path& dot_git_dir) const;
ExpectedL<std::string> git_show(StringView treeish, const Path& dot_git_dir) const;
bool git_is_shallow_clone(const Path& dot_git_dir) const;
vicroms marked this conversation as resolved.
Show resolved Hide resolved

const DownloadManager& get_download_manager() const;

Expand Down
1 change: 1 addition & 0 deletions locales/messages.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@
"SettingEnvVar": "-- Setting \"{env_var}\" environment variables to \"{url}\".",
"ShaPassedAsArgAndOption": "SHA512 passed as both an argument and as an option. Only pass one of these.",
"ShaPassedWithConflict": "SHA512 passed, but --skip-sha512 was also passed; only do one or the other.",
"ShallowRepositoryDetected": "vcpkg was cloned as a shallow repository in: {path}\nTry again with a full vcpkg clone.",
"SkipClearingInvalidDir": "Skipping clearing contents of {path} because it was not a directory.",
"SourceFieldPortNameMismatch": "The 'Source' field inside the CONTROL file, or \"name\" field inside the vcpkg.json file has the name {package_name} and does not match the port directory \"{path}\".",
"SpecifiedFeatureTurnedOff": "'{command_name}' feature specifically turned off, but --{option} was specified.",
Expand Down
2 changes: 2 additions & 0 deletions locales/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,8 @@
"_SettingEnvVar.comment": "An example of env_var is \"HTTP(S)_PROXY\"'--' at the beginning must be preserved An example of {env_var} is VCPKG_DEFAULT_TRIPLET. An example of {url} is https://github.com/microsoft/vcpkg.",
"ShaPassedAsArgAndOption": "SHA512 passed as both an argument and as an option. Only pass one of these.",
"ShaPassedWithConflict": "SHA512 passed, but --skip-sha512 was also passed; only do one or the other.",
"ShallowRepositoryDetected": "vcpkg was cloned as a shallow repository in: {path}\nTry again with a full vcpkg clone.",
"_ShallowRepositoryDetected.comment": "An example of {path} is /foo/bar.",
"SkipClearingInvalidDir": "Skipping clearing contents of {path} because it was not a directory.",
"_SkipClearingInvalidDir.comment": "An example of {path} is /foo/bar.",
"SourceFieldPortNameMismatch": "The 'Source' field inside the CONTROL file, or \"name\" field inside the vcpkg.json file has the name {package_name} and does not match the port directory \"{path}\".",
Expand Down
1 change: 1 addition & 0 deletions src/vcpkg/base/messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@ namespace vcpkg
REGISTER_MESSAGE(ResultsHeader);
REGISTER_MESSAGE(SerializedBinParagraphHeader);
REGISTER_MESSAGE(SettingEnvVar);
REGISTER_MESSAGE(ShallowRepositoryDetected);
REGISTER_MESSAGE(ShaPassedAsArgAndOption);
REGISTER_MESSAGE(ShaPassedWithConflict);
REGISTER_MESSAGE(SkipClearingInvalidDir);
Expand Down
31 changes: 29 additions & 2 deletions src/vcpkg/vcpkgpaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -971,8 +971,14 @@ namespace vcpkg
}
return ret;
}

std::string VcpkgPaths::get_current_git_sha_baseline_message() const
{
if (git_is_shallow_clone(this->root / ".git"))
{
return msg::format(msgShallowRepositoryDetected, msg::path = this->root / ".git").to_string();
}

auto maybe_cur_sha = get_current_git_sha();
if (auto p_sha = maybe_cur_sha.get())
{
Expand All @@ -993,6 +999,19 @@ namespace vcpkg
return flatten_out(cmd_execute_and_capture_output(showcmd), Tools::GIT);
}

bool VcpkgPaths::git_is_shallow_clone(const Path& dot_git_dir) const
{
auto cmd =
git_cmd_builder(dot_git_dir, dot_git_dir).string_arg("rev-parse").string_arg("--is-shallow-repository");
auto output = flatten_out(cmd_execute_and_capture_output(cmd), Tools::GIT);
if (!output)
{
Debug::println(output.error());
return false;
}
return Strings::case_insensitive_ascii_equals("true", Strings::trim(*output.get()));
}

ExpectedS<std::map<std::string, std::string, std::less<>>> VcpkgPaths::git_get_local_port_treeish_map() const
{
const auto local_repo = this->root / ".git";
Expand Down Expand Up @@ -1080,9 +1099,17 @@ namespace vcpkg
auto maybe_tar_output = flatten(cmd_execute_and_capture_output(tar_cmd_builder), Tools::TAR);
if (!maybe_tar_output)
{
auto message =
Strings::concat(PRELUDE, "Error: Failed to tar port directory\n", std::move(maybe_tar_output).error());
if (git_is_shallow_clone(this->root / ".git"))
{
message.push_back('\n');
message.append(msg::format(msgShallowRepositoryDetected, msg::path = this->root / ".git").to_string());
}
return {
Strings::concat(PRELUDE, "Error: Failed to tar port directory\n", std::move(maybe_tar_output).error()),
expected_right_tag};
std::move(message),
expected_right_tag,
};
}

extract_tar_cmake(this->get_tool_exe(Tools::CMAKE, stdout_sink), destination_tar, destination_tmp);
Expand Down