bin/commit: move parent checking code higher up
authorJonathan Lebon <jlebon@redhat.com>
Tue, 9 Jan 2018 20:00:24 +0000 (20:00 +0000)
committerAtomic Bot <atomic-devel@projectatomic.io>
Wed, 10 Jan 2018 01:42:56 +0000 (01:42 +0000)
No functional change. Prep for the next commit.

Closes: #1402
Approved by: cgwalters

src/ostree/ot-builtin-commit.c

index 9c05428e6288f0e9c9413a04187887e2a3d55d77..842d07d1f7a6540fede8a8060067907a060f742b 100644 (file)
@@ -466,6 +466,38 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio
         goto out;
     }
 
+  if (!(opt_branch || opt_orphan))
+    {
+      g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                           "A branch must be specified with --branch, or use --orphan");
+      goto out;
+    }
+
+  if (opt_parent)
+    {
+      if (g_str_equal (opt_parent, "none"))
+        parent = NULL;
+      else
+        {
+          if (!ostree_validate_checksum_string (opt_parent, error))
+            goto out;
+          parent = g_strdup (opt_parent);
+        }
+    }
+  else if (!opt_orphan)
+    {
+      if (!ostree_repo_resolve_rev (repo, opt_branch, TRUE, &parent, error))
+        {
+          if (g_error_matches (*error, G_IO_ERROR, G_IO_ERROR_IS_DIRECTORY))
+            {
+              /* A folder exists with the specified ref name,
+                 * which is handled by _ostree_repo_write_ref */
+              g_clear_error (error);
+            }
+          else goto out;
+        }
+    }
+
   if (opt_metadata_strings || opt_metadata_variants)
     {
       g_autoptr(GVariantBuilder) builder =
@@ -493,13 +525,6 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio
       detached_metadata = g_variant_ref_sink (g_variant_builder_end (builder));
     }
 
-  if (!(opt_branch || opt_orphan))
-    {
-      g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
-                           "A branch must be specified with --branch, or use --orphan");
-      goto out;
-    }
-
   if (opt_no_xattrs)
     flags |= OSTREE_REPO_COMMIT_MODIFIER_FLAGS_SKIP_XATTRS;
   if (opt_consume)
@@ -543,31 +568,6 @@ ostree_builtin_commit (int argc, char **argv, OstreeCommandInvocation *invocatio
         }
     }
 
-  if (opt_parent)
-    {
-      if (g_str_equal (opt_parent, "none"))
-        parent = NULL;
-      else
-        {
-          if (!ostree_validate_checksum_string (opt_parent, error))
-            goto out;
-          parent = g_strdup (opt_parent);
-        }
-    }
-  else if (!opt_orphan)
-    {
-      if (!ostree_repo_resolve_rev (repo, opt_branch, TRUE, &parent, error))
-        {
-          if (g_error_matches (*error, G_IO_ERROR, G_IO_ERROR_IS_DIRECTORY))
-            {
-              /* A folder exists with the specified ref name,
-                 * which is handled by _ostree_repo_write_ref */
-              g_clear_error (error);
-            }
-          else goto out;
-        }
-    }
-
   if (opt_editor)
     {
       if (!commit_editor (repo, opt_branch, &opt_subject, &commit_body, cancellable, error))