A peer-to-peer stack for code collaboration
Verify patch is on top of origin/master (#529)
Merle Breitkreuz6c687633d81a
diff --git a/bin/rad-diff b/bin/rad-diffindex a5017c4..9b86c8e 100755--- a/bin/rad-diff+++ b/bin/rad-diff@@ -99,6 +99,14 @@(fn [commit](string/unlines (process-with-stdout! "git" ["rev-parse" "--short" commit] ""))))+(def get-commit-parent!+ (fn [commit]+ (string/unlines (process-with-stdout! "git" ["rev-parse" (string-append commit "^")] ""))))++(def get-head-origin-master!+ (fn []+ (string/unlines (process-with-stdout! "git" ["rev-parse" "origin/master"] ""))))+(def apply-patch!"Given a patch, apply it to the current branch"(fn [patch msg]@@ -133,10 +141,21 @@["push"](error/push-diff-failure))))++(def verify-patch+ "Verify that the patch is on top of origin/master"+ (fn [commit]+ (if (eq? (get-commit-parent! commit) (get-head-origin-master!))+ commit+ (do+ (put-str! (error/parent-commit-not-master commit))+ (exit! 1)))))+(def new-diff!"Creates a new diff on `machine` with a patch from the given `commit`."(fn [machine commit](verify-commit commit)+ (verify-patch commit)(def patch (get-patch! commit))(def author-name (get-author-name! commit))(def author-email (get-author-name! commit))diff --git a/rad/prelude/error-messages.rad b/rad/prelude/error-messages.radindex 11a98de..769b9fd 100644--- a/rad/prelude/error-messages.rad+++ b/rad/prelude/error-messages.rad@@ -8,9 +8,9 @@invalid-opt-for-cmd dir-already-exists git-clone-failure upstream-commit-failureupstream-push-failure item-not-found whole-item-number missing-item-numberstate-change-failure no-number-returned unknown-command unknown-commit- checkout-new-branch-failure checkout-master-failure applying-patch-failure- applying-accepted-patch-failure push-diff-failure missing-key-file- rad-ipfs-name-publish-failure rad-ipfs-key-gen-failure+ parent-commit-not-master checkout-new-branch-failure checkout-master-failure+ applying-patch-failure applying-accepted-patch-failure push-diff-failure+ missing-key-file rad-ipfs-name-publish-failure rad-ipfs-key-gen-failure]}(import prelude/strings :unqualified)@@ -144,6 +144,17 @@ Set the upstream branch manually and rerun 'rad project init'"])(:test "unknown-commit"[(unknown-commit "12345") ==> "Commit 12345 can't be found."])+(def parent-commit-not-master+ "`rad diff propose` aborts if the provided commit is unknown."+ (fn [commit]+ (string-append+ "Commit " commit " is not on top of origin/master.\n"+ "Squash all commits on your branch and rebase if necessary.")))++(:test "parent-commit-not-master"+ [(parent-commit-not-master "12345") ==> "Commit 12345 is not on top of origin/master.+Squash all commits on your branch and rebase if necessary."])+(def checkout-new-branch-failure"`rad diff checkout` aborts if creating and switching to the diff branch fails."(fn [branch]