mirror of
https://github.com/ostreedev/ostree.git
synced 2025-03-19 22:50:35 +03:00
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
This commit is contained in:
parent
c6b4ecd474
commit
23d26d5f65
@ -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;
|
||||
|
@ -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'
|
||||
|
Loading…
x
Reference in New Issue
Block a user