@@ -266,20 +266,29 @@ namespace vcpkg::Commands::AddVersion
266
266
static constexpr StringLiteral OPTION_ALL = " all" ;
267
267
static constexpr StringLiteral OPTION_OVERWRITE_VERSION = " overwrite-version" ;
268
268
static constexpr StringLiteral OPTION_SKIP_FORMATTING_CHECK = " skip-formatting-check" ;
269
+ static constexpr StringLiteral OPTION_COMMIT = " commit" ;
270
+ static constexpr StringLiteral OPTION_COMMIT_AMEND = " amend" ;
271
+ static constexpr StringLiteral OPTION_COMMIT_MESSAGE = " commit-message" ;
269
272
static constexpr StringLiteral OPTION_VERBOSE = " verbose" ;
270
273
271
274
const CommandSwitch COMMAND_SWITCHES[] = {
272
275
{OPTION_ALL, " Process versions for all ports." },
273
276
{OPTION_OVERWRITE_VERSION, " Overwrite `git-tree` of an existing version." },
274
277
{OPTION_SKIP_FORMATTING_CHECK, " Skips the formatting check of vcpkg.json files." },
278
+ {OPTION_COMMIT, " Commits the results." },
279
+ {OPTION_COMMIT_AMEND, " Amend the result to the last commit instead of creating a new one." },
275
280
{OPTION_VERBOSE, " Print success messages instead of just errors." },
276
281
};
277
282
283
+ const CommandSetting COMMAND_SETTINGS[] = {
284
+ {OPTION_COMMIT_MESSAGE, " The commit message when creating a new commit." },
285
+ };
286
+
278
287
const CommandStructure COMMAND_STRUCTURE{
279
288
create_example_string (R"###( x-add-version <port name>)###" ),
280
289
0 ,
281
290
1 ,
282
- {{COMMAND_SWITCHES}, {}, {}},
291
+ {{COMMAND_SWITCHES}, {COMMAND_SETTINGS }, {}},
283
292
nullptr ,
284
293
};
285
294
@@ -290,6 +299,29 @@ namespace vcpkg::Commands::AddVersion
290
299
const bool overwrite_version = Util::Sets::contains (parsed_args.switches , OPTION_OVERWRITE_VERSION);
291
300
const bool skip_formatting_check = Util::Sets::contains (parsed_args.switches , OPTION_SKIP_FORMATTING_CHECK);
292
301
const bool verbose = Util::Sets::contains (parsed_args.switches , OPTION_VERBOSE);
302
+ const bool commit = Util::Sets::contains (parsed_args.switches , OPTION_COMMIT);
303
+ const bool amend = Util::Sets::contains (parsed_args.switches , OPTION_COMMIT_AMEND);
304
+
305
+ std::optional<std::string> commit_message;
306
+ const auto iter_commit_message = parsed_args.settings .find (OPTION_COMMIT_MESSAGE);
307
+ if (iter_commit_message != parsed_args.settings .end ())
308
+ {
309
+ commit_message.emplace (iter_commit_message->second );
310
+ if (commit_message.value ().empty ())
311
+ {
312
+ System::print2 (System::Color::error, " Error: The specified commit message must be not empty.\n ." );
313
+ Checks::exit_fail (VCPKG_LINE_INFO);
314
+ }
315
+ }
316
+
317
+ if ((amend || commit_message) && !commit)
318
+ {
319
+ System::printf (System::Color::warning,
320
+ " Warning: `--%s` or `--%s` was specified, assuming `--%s`\n " ,
321
+ OPTION_COMMIT_AMEND,
322
+ OPTION_COMMIT_MESSAGE,
323
+ OPTION_COMMIT);
324
+ }
293
325
294
326
auto & fs = paths.get_filesystem ();
295
327
auto baseline_path = paths.current_registry_versions / fs::u8path (" baseline.json" );
@@ -341,6 +373,7 @@ namespace vcpkg::Commands::AddVersion
341
373
// Get tree-ish from local repository state.
342
374
auto maybe_git_tree_map = paths.git_get_port_treeish_map (paths.current_registry_ports );
343
375
auto git_tree_map = maybe_git_tree_map.value_or_exit (VCPKG_LINE_INFO);
376
+ std::vector<fs::path> updated_files;
344
377
345
378
for (auto && port_name : port_names)
346
379
{
@@ -394,10 +427,26 @@ namespace vcpkg::Commands::AddVersion
394
427
395
428
auto port_versions_path = paths.current_registry_versions / fs::u8path ({port_name[0 ], ' -' }) /
396
429
fs::u8path (Strings::concat (port_name, " .json" ));
430
+ updated_files.push_back (port_versions_path);
397
431
update_version_db_file (
398
432
paths, port_name, schemed_version, git_tree, port_versions_path, overwrite_version, verbose, add_all);
399
433
update_baseline_version (paths, port_name, schemed_version.versiont , baseline_path, baseline_map, verbose);
400
434
}
435
+ if (!updated_files.empty ()) updated_files.push_back (baseline_path);
436
+ if (commit)
437
+ {
438
+ const auto result = paths.git_commit (paths.current_registry_dot_git_dir ,
439
+ std::move (updated_files),
440
+ commit_message.value_or (amend ? " " : " Add version files" ),
441
+ amend);
442
+ if (result.exit_code != 0 )
443
+ {
444
+ System::printf (System::Color::error,
445
+ " Error: Failed to commit the changes. The git output is: %s\n " ,
446
+ result.output );
447
+ Checks::exit_fail (VCPKG_LINE_INFO);
448
+ }
449
+ }
401
450
Checks::exit_success (VCPKG_LINE_INFO);
402
451
}
403
452
0 commit comments