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

Make x-add-version not require changes be committed first. #1616

Merged
merged 8 commits into from
Mar 20, 2025
14 changes: 4 additions & 10 deletions azure-pipelines/end-to-end-tests-dir/ci-verify-versions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ git -C "$TestingRoot/ci-verify-versions-registry" @gitConfigOptions commit -m te
Move-Item "$TestingRoot/ci-verify-versions-registry/old-port-versions/has-local-edits" "$TestingRoot/ci-verify-versions-registry/ports"

$expected = @"
$TestingRoot/ci-verify-versions-registry/ports/malformed/vcpkg.json:4:3: error: Unexpected character; expected property name
on expression: ~broken
^
$TestingRoot/ci-verify-versions-registry/versions/b-/bad-git-tree.json: error: [email protected] git tree 000000070c5f496fcf1a97cf654d5e81f0d2685a does not match the port directory
$TestingRoot/ci-verify-versions-registry/ports/bad-git-tree: note: the port directory has git tree 6528b2c70c5f496fcf1a97cf654d5e81f0d2685a
$TestingRoot/ci-verify-versions-registry/ports/bad-git-tree/vcpkg.json: note: if [email protected] is already published, update this file with a new version or port-version, commit it, then add the new version by running:
Expand Down Expand Up @@ -60,15 +57,12 @@ note: the dependency is in the feature named add-things
$TestingRoot/ci-verify-versions-registry/ports/good: message: [email protected] is correctly in the version database (0f3d67db0dbb6aa5499bc09367a606b495e16d35)
$TestingRoot/ci-verify-versions-registry/versions/baseline.json: message: [email protected] matches the current baseline
$TestingRoot/ci-verify-versions-registry/ports/good/vcpkg.json: message: all version constraints are consistent with the version database
$TestingRoot/ci-verify-versions-registry/ports/has-local-edits/vcpkg.json: error: the git tree of the port directory could not be determined. This is usually caused by uncommitted changes.
note: you can commit your changes and add them to the version database by running:
git add "$TestingRoot/ci-verify-versions-registry/ports/has-local-edits"
git commit -m wip
vcpkg x-add-version has-local-edits
git add versions
git commit --amend -m "[has-local-edits] Add new port"
$TestingRoot/ci-verify-versions-registry/ports/has-local-edits: message: [email protected] is correctly in the version database (b1d7f6030942b329a200f16c931c01e2ec9e1e79)
$TestingRoot/ci-verify-versions-registry/versions/baseline.json: message: [email protected] matches the current baseline
$TestingRoot/ci-verify-versions-registry/ports/has-local-edits/vcpkg.json: message: all version constraints are consistent with the version database
$TestingRoot/ci-verify-versions-registry/ports/malformed/vcpkg.json:4:3: error: Unexpected character; expected property name
on expression: ~broken
^
$TestingRoot/ci-verify-versions-registry/versions/m-/mismatch-git-tree.json: error: [email protected] git tree 41d20d2a02d75343b0933b624faf9f061b112dad does not match the port directory
$TestingRoot/ci-verify-versions-registry/ports/mismatch-git-tree: note: the port directory has git tree 34b3289caaa7a97950828905d354dc971c3c15a7
$TestingRoot/ci-verify-versions-registry/ports/mismatch-git-tree/vcpkg.json: note: if [email protected] is already published, update this file with a new version or port-version, commit it, then add the new version by running:
Expand Down
7 changes: 0 additions & 7 deletions include/vcpkg/base/git.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,13 @@ namespace vcpkg
std::string old_path;
};

// Try to extract a port name from a path.
// The path should start with the "ports/" prefix
std::string try_extract_port_name_from_path(StringView path);

// Attempts to parse the git status output returns a parsing error message on failure
ExpectedL<std::vector<GitStatusLine>> parse_git_status_output(StringView git_status_output,
StringView git_command_line);

// Run git status on a repository, optionaly a specific subpath can be queried
ExpectedL<std::vector<GitStatusLine>> git_status(const GitConfig& config, StringView path = "");

// Returns a list of ports that have uncommitted/unmerged changes
ExpectedL<std::set<std::string>> git_ports_with_uncommitted_changes(const GitConfig& config);

// Check whether a repository is a shallow clone
ExpectedL<bool> is_shallow_clone(const GitConfig& config);
}
22 changes: 0 additions & 22 deletions include/vcpkg/base/message-data.inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ DECLARE_MESSAGE(AddVersionArtifactsOnly,
"--version is artifacts only and can't be used with vcpkg add port")
DECLARE_MESSAGE(AddVersionAddedVersionToFile, (msg::version, msg::path), "", "added version {version} to {path}")
DECLARE_MESSAGE(AddVersionCommitChangesReminder, (), "", "Did you remember to commit your changes?")
DECLARE_MESSAGE(AddVersionDetectLocalChangesError,
(),
"",
"skipping detection of local changes due to unexpected format in git status output")
DECLARE_MESSAGE(AddVersionFileNotFound, (msg::path), "", "couldn't find required file {path}")
DECLARE_MESSAGE(AddVersionFormatPortSuggestion, (msg::command_line), "", "Run `{command_line}` to format the file")
DECLARE_MESSAGE(AddVersionIgnoringOptionAll,
Expand Down Expand Up @@ -112,10 +108,6 @@ DECLARE_MESSAGE(
"actually semantic parts do not apply.\n"
"If versions for this port are not ordered by these rules, disable this check by rerunning this command and adding "
"--skip-version-format-check .")
DECLARE_MESSAGE(AddVersionUncommittedChanges,
(msg::package_name),
"",
"there are uncommitted changes for {package_name}")
DECLARE_MESSAGE(AddVersionUpdateVersionReminder, (), "", "Did you remember to update the version or port version?")
DECLARE_MESSAGE(AddVersionUseOptionAll,
(msg::command_name, msg::option),
Expand Down Expand Up @@ -3240,20 +3232,6 @@ DECLARE_MESSAGE(VersionShaMismatch4,
(msg::version_spec),
"",
"if {version_spec} is not yet published, overwrite the previous git tree by running:")
DECLARE_MESSAGE(
VersionShaMissing1,
(),
"",
"the git tree of the port directory could not be determined. This is usually caused by uncommitted changes.")
DECLARE_MESSAGE(VersionShaMissing2,
(),
"",
"you can commit your changes and add them to the version database by running:")
DECLARE_MESSAGE(VersionShaMissing3,
(),
"This is short for 'work in progress' and must be enclosed in \" quotes if it is more than 1 word",
"wip")
DECLARE_MESSAGE(VersionShaMissing4, (msg::package_name), "", "[{package_name}] Add new port")
DECLARE_MESSAGE(VersionSharpMustBeFollowedByPortVersion,
(),
"",
Expand Down
4 changes: 4 additions & 0 deletions include/vcpkg/base/strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,12 @@ namespace vcpkg::Strings

void inplace_trim(std::string& s);

void inplace_trim_end(std::string& s);

[[nodiscard]] StringView trim(StringView sv);

[[nodiscard]] StringView trim_end(StringView sv);

void inplace_trim_all_and_remove_whitespace_strings(std::vector<std::string>& strings);

[[nodiscard]] std::vector<std::string> split(StringView s, const char delimiter);
Expand Down
4 changes: 3 additions & 1 deletion include/vcpkg/vcpkgpaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <vcpkg/fwd/vcpkgcmdarguments.h>
#include <vcpkg/fwd/vcpkgpaths.h>

#include <vcpkg/base/diagnostics.h>
#include <vcpkg/base/optional.h>
#include <vcpkg/base/path.h>

Expand Down Expand Up @@ -121,7 +122,8 @@ namespace vcpkg
ExpectedL<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;

ExpectedL<std::map<std::string, std::string, std::less<>>> git_get_local_port_treeish_map() const;
Optional<std::map<std::string, std::string, std::less<>>> git_get_local_port_treeish_map(
DiagnosticContext& context) const;

// Git manipulation for remote registries
// runs `git fetch {uri} {treeish}`, and returns the hash of FETCH_HEAD.
Expand Down
9 changes: 0 additions & 9 deletions locales/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
"AddVersionArtifactsOnly": "--version is artifacts only and can't be used with vcpkg add port",
"_AddVersionArtifactsOnly.comment": "'--version', and 'vcpkg add port' are command lines that must not be localized",
"AddVersionCommitChangesReminder": "Did you remember to commit your changes?",
"AddVersionDetectLocalChangesError": "skipping detection of local changes due to unexpected format in git status output",
"AddVersionFileNotFound": "couldn't find required file {path}",
"_AddVersionFileNotFound.comment": "An example of {path} is /foo/bar.",
"AddVersionFormatPortSuggestion": "Run `{command_line}` to format the file",
Expand Down Expand Up @@ -101,8 +100,6 @@
"_AddVersionSuggestVersionDate.comment": "\"version-string\" and \"version-date\" are JSON keys, and --skip-version-format-check is a command line switch. They should not be translated An example of {package_name} is zlib.",
"AddVersionSuggestVersionRelaxed": "The version format of \"{package_name}\" uses \"version-string\", but the format is acceptable as a \"version\". If the versions for this port are orderable using relaxed-version rules, change the format to \"version\", and rerun this command. Relaxed-version rules order versions by each numeric component. Then, versions with dash suffixes are sorted lexcographically before. Plus'd build tags are ignored. Examples:\n1.0 < 1.1-alpha < 1.1-b < 1.1 < 1.1.1 < 1.2+build = 1.2 < 2.0\nNote in particular that dashed suffixes sort *before*, not after. 1.0-anything < 1.0\nNote that this sort order is the same as chosen in Semantic Versioning (see https://semver.org), even though the actually semantic parts do not apply.\nIf versions for this port are not ordered by these rules, disable this check by rerunning this command and adding --skip-version-format-check .",
"_AddVersionSuggestVersionRelaxed.comment": "\"version-string\" and \"version\" are JSON keys, and --skip-version-format-check is a command line switch. They should not be translated An example of {package_name} is zlib.",
"AddVersionUncommittedChanges": "there are uncommitted changes for {package_name}",
"_AddVersionUncommittedChanges.comment": "An example of {package_name} is zlib.",
"AddVersionUpdateVersionReminder": "Did you remember to update the version or port version?",
"AddVersionUseOptionAll": "{command_name} with no arguments requires passing --{option} to update all port versions at once",
"_AddVersionUseOptionAll.comment": "The -- before {option} must be preserved as they're part of the help message for the user. An example of {command_name} is install. An example of {option} is editable.",
Expand Down Expand Up @@ -1703,12 +1700,6 @@
"_VersionShaMismatch3.comment": "An example of {version_spec} is zlib:[email protected].",
"VersionShaMismatch4": "if {version_spec} is not yet published, overwrite the previous git tree by running:",
"_VersionShaMismatch4.comment": "An example of {version_spec} is zlib:[email protected].",
"VersionShaMissing1": "the git tree of the port directory could not be determined. This is usually caused by uncommitted changes.",
"VersionShaMissing2": "you can commit your changes and add them to the version database by running:",
"VersionShaMissing3": "wip",
"_VersionShaMissing3.comment": "This is short for 'work in progress' and must be enclosed in \" quotes if it is more than 1 word",
"VersionShaMissing4": "[{package_name}] Add new port",
"_VersionShaMissing4.comment": "An example of {package_name} is zlib.",
"VersionSharpMustBeFollowedByPortVersion": "'#' in version text must be followed by a port version",
"VersionSharpMustBeFollowedByPortVersionNonNegativeInteger": "'#' in version text must be followed by a port version (a non-negative integer)",
"VersionSpecMismatch": "Failed to load port because versions are inconsistent. The file \"{path}\" contains the version {actual_version}, but the version database indicates that it should be {expected_version}.",
Expand Down
15 changes: 0 additions & 15 deletions src/vcpkg-test/git.parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,3 @@ TEST_CASE ("Parse git status output", "[git]")
auto maybe_bad_results3 = parse_git_status_output(bad_output3, "git status");
REQUIRE(!maybe_bad_results3.has_value());
}

TEST_CASE ("Extract port name from path", "[git]")
{
// should be empty cases
CHECK(try_extract_port_name_from_path("ports/").empty());
CHECK(try_extract_port_name_from_path("ports/README.md").empty());
CHECK(try_extract_port_name_from_path("versions/test/test.json").empty());
CHECK(try_extract_port_name_from_path("overlays/ports/test/portfile.cmake").empty());

// should have port name cases
CHECK(try_extract_port_name_from_path("ports/t/CONTROL") == "t");
CHECK(try_extract_port_name_from_path("ports/test/vcpkg.json") == "test");
CHECK(try_extract_port_name_from_path("ports/ports/a/README.md") == "ports");
CHECK(try_extract_port_name_from_path("ports/ports/a/ports/b/ports/c.json") == "ports");
}
35 changes: 0 additions & 35 deletions src/vcpkg/base/git.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,6 @@ namespace

namespace vcpkg
{
std::string try_extract_port_name_from_path(StringView path)
{
static constexpr StringLiteral prefix = "ports/";
static constexpr size_t min_path_size = sizeof("ports/*/") - 1;
if (path.size() >= min_path_size && Strings::starts_with(path, prefix))
{
auto no_prefix = path.substr(prefix.size());
auto slash = std::find(no_prefix.begin(), no_prefix.end(), '/');
if (slash != no_prefix.end())
{
return std::string(no_prefix.begin(), slash);
}
}
return {};
}

ExpectedL<std::vector<GitStatusLine>> parse_git_status_output(StringView output, StringView cmd_line)
{
// Output of git status --porcelain=v1 is in the form:
Expand Down Expand Up @@ -173,25 +157,6 @@ namespace vcpkg
.append_raw(maybe_output.error().to_string());
}

ExpectedL<std::set<std::string>> git_ports_with_uncommitted_changes(const GitConfig& config)
{
auto maybe_results = git_status(config, "ports");
if (auto results = maybe_results.get())
{
std::set<std::string> ret;
for (auto&& result : *results)
{
auto&& port_name = try_extract_port_name_from_path(result.path);
if (!port_name.empty())
{
ret.emplace(port_name);
}
}
return ret;
}
return std::move(maybe_results).error();
}

ExpectedL<bool> is_shallow_clone(const GitConfig& config)
{
return flatten_out(cmd_execute_and_capture_output(
Expand Down
15 changes: 13 additions & 2 deletions src/vcpkg/base/strings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ namespace
// To disambiguate between two overloads
constexpr struct
{
bool operator()(char c) const noexcept { return std::isspace(static_cast<unsigned char>(c)) != 0; }
bool operator()(char c) const noexcept { return c == ' ' || c == '\t' || c == '\r' || c == '\n'; }
} is_space_char;

constexpr struct
Expand Down Expand Up @@ -271,17 +271,28 @@ void Strings::inplace_replace_all(std::string& s, char search, char rep) noexcep

void Strings::inplace_trim(std::string& s)
{
s.erase(std::find_if_not(s.rbegin(), s.rend(), is_space_char).base(), s.end());
inplace_trim_end(s);
s.erase(s.begin(), std::find_if_not(s.begin(), s.end(), is_space_char));
}

void Strings::inplace_trim_end(std::string& s)
{
s.erase(std::find_if_not(s.rbegin(), s.rend(), is_space_char).base(), s.end());
}

StringView Strings::trim(StringView sv)
{
auto last = std::find_if_not(sv.rbegin(), sv.rend(), is_space_char).base();
auto first = std::find_if_not(sv.begin(), sv.end(), is_space_char);
return StringView(first, last);
}

StringView Strings::trim_end(StringView sv)
{
auto last = std::find_if_not(sv.rbegin(), sv.rend(), is_space_char).base();
return StringView(sv.begin(), last);
}

void Strings::inplace_trim_all_and_remove_whitespace_strings(std::vector<std::string>& strings)
{
for (std::string& s : strings)
Expand Down
17 changes: 1 addition & 16 deletions src/vcpkg/commands.add-version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,17 +457,11 @@ namespace vcpkg
}();

// Get tree-ish from local repository state.
auto maybe_git_tree_map = paths.git_get_local_port_treeish_map();
auto maybe_git_tree_map = paths.git_get_local_port_treeish_map(console_diagnostic_context);
auto& git_tree_map = maybe_git_tree_map.value_or_exit(VCPKG_LINE_INFO);

// Find ports with uncommitted changes
auto git_config = paths.git_builtin_config();
auto maybe_changes = git_ports_with_uncommitted_changes(git_config);
if (!maybe_changes.has_value() && verbose)
{
msg::println_warning(msgAddVersionDetectLocalChangesError);
}

for (auto&& port_name : port_names)
{
auto port_dir = paths.builtin_ports_directory() / port_name;
Expand Down Expand Up @@ -514,15 +508,6 @@ namespace vcpkg
}
}

// find local uncommitted changes on port
if (auto changed_ports = maybe_changes.get())
{
if (Util::Sets::contains(*changed_ports, port_name))
{
msg::println_warning(msgAddVersionUncommittedChanges, msg::package_name = port_name);
}
}

auto schemed_version = scfl->source_control_file->to_schemed_version();
auto git_tree_it = git_tree_map.find(port_name);
if (git_tree_it == git_tree_map.end())
Expand Down
Loading