From 23d26d5f65a79d77afba515afd45a46ad3a80209 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 29 Mar 2016 10:53:50 -0400 Subject: [PATCH] commit: Support writing orphans The API supports this, and it's not hard for us to do in the command line as well. One possible use case is separating "content generation" in a separate server. Related: https://github.com/ostreedev/ostree/pull/223 Closes: #227 Approved by: jlebon --- src/ostree/ot-builtin-commit.c | 15 ++++++++++----- tests/basic-test.sh | 12 +++++++++++- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/ostree/ot-builtin-commit.c b/src/ostree/ot-builtin-commit.c index 517ea70e..2c74d4d7 100644 --- a/src/ostree/ot-builtin-commit.c +++ b/src/ostree/ot-builtin-commit.c @@ -33,6 +33,7 @@ static char *opt_subject; static char *opt_body; static char *opt_parent; +static gboolean opt_orphan; static char *opt_branch; static char *opt_statoverride_file; static char **opt_metadata_strings; @@ -72,6 +73,7 @@ static GOptionEntry options[] = { { "subject", 's', 0, G_OPTION_ARG_STRING, &opt_subject, "One line subject", "SUBJECT" }, { "body", 'm', 0, G_OPTION_ARG_STRING, &opt_body, "Full description", "BODY" }, { "branch", 'b', 0, G_OPTION_ARG_STRING, &opt_branch, "Branch", "BRANCH" }, + { "orphan", 0, 0, G_OPTION_ARG_NONE, &opt_orphan, "Create a commit without writing a ref", NULL }, { "tree", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_trees, "Overlay the given argument as a tree", "dir=PATH or tar=TARFILE or ref=COMMIT" }, { "add-metadata-string", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_metadata_strings, "Add a key/value pair to metadata", "KEY=VALUE" }, { "add-detached-metadata-string", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_detached_metadata_strings, "Add a key/value pair to detached metadata", "KEY=VALUE" }, @@ -340,10 +342,10 @@ ostree_builtin_commit (int argc, char **argv, GCancellable *cancellable, GError goto out; } - if (!opt_branch) + if (!(opt_branch || opt_orphan)) { g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "A branch must be specified with --branch"); + "A branch must be specified with --branch, or use --orphan"); goto out; } @@ -374,13 +376,13 @@ ostree_builtin_commit (int argc, char **argv, GCancellable *cancellable, GError parent = g_strdup (opt_parent); } } - else + else if (!opt_orphan) { if (!ostree_repo_resolve_rev (repo, opt_branch, TRUE, &parent, error)) goto out; } - if (!opt_subject && !opt_body) + if (!opt_subject && !opt_body && !opt_orphan) { if (!commit_editor (repo, opt_branch, &opt_subject, &opt_body, cancellable, error)) goto out; @@ -563,7 +565,10 @@ ostree_builtin_commit (int argc, char **argv, GCancellable *cancellable, GError } } - ostree_repo_transaction_set_ref (repo, NULL, opt_branch, commit_checksum); + if (opt_branch) + ostree_repo_transaction_set_ref (repo, NULL, opt_branch, commit_checksum); + else + g_assert (opt_orphan); if (!ostree_repo_commit_transaction (repo, &stats, cancellable, error)) goto out; diff --git a/tests/basic-test.sh b/tests/basic-test.sh index 4b46fc10..1ae7e7a4 100755 --- a/tests/basic-test.sh +++ b/tests/basic-test.sh @@ -19,7 +19,7 @@ set -euo pipefail -echo "1..52" +echo "1..53" $OSTREE checkout test2 checkout-test2 echo "ok checkout" @@ -113,6 +113,16 @@ $OSTREE commit -b test2-custom-parent -s '' --parent=${prevparent} $test_tmpdir/ assert_streq $($OSTREE log test2-custom-parent |grep '^commit' | wc -l) "3" echo "ok commit custom parent" +cd ${test_tmpdir} +orphaned_rev=$($OSTREE commit --orphan -s '' $test_tmpdir/checkout-test2-4) +$OSTREE ls ${orphaned_rev} >/dev/null +$OSTREE prune --refs-only +if $OSTREE ls ${orphaned_rev} 2>err.txt; then + assert_not_reached "Found orphaned commit" +fi +assert_file_has_content err.txt "No such metadata object" +echo "ok commit orphaned" + cd ${test_tmpdir} $OSTREE diff test2^ test2 > diff-test2 assert_file_has_content diff-test2 'D */a/5'