From 7ddb1119a58c37a711e08968dbeaac27052f20bc Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Fri, 8 Mar 2024 10:03:59 +0000 Subject: [PATCH] cli: show revision on rad patch checkout Help the user know which revision they currently have checked out when running `rad patch checkout`. Signed-off-by: Fintan Halpenny X-Clacks-Overhead: GNU Terry Pratchett --- .../examples/rad-patch-checkout-force.md | 4 ++-- .../examples/rad-patch-checkout-revision.md | 2 +- radicle-cli/examples/rad-patch-checkout.md | 4 ++-- radicle-cli/examples/rad-patch-pull-update.md | 2 +- radicle-cli/examples/rad-patch.md | 2 +- .../examples/rad-push-and-pull-patches.md | 2 +- .../examples/workflow/5-patching-maintainer.md | 2 +- radicle-cli/src/commands/patch/checkout.rs | 18 +++++++++++------- 8 files changed, 20 insertions(+), 16 deletions(-) diff --git a/radicle-cli/examples/rad-patch-checkout-force.md b/radicle-cli/examples/rad-patch-checkout-force.md index 852d3c84..c08c0373 100644 --- a/radicle-cli/examples/rad-patch-checkout-force.md +++ b/radicle-cli/examples/rad-patch-checkout-force.md @@ -27,7 +27,7 @@ $ rad sync -f ✓ Fetching rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji from z6MknSL…StBU8Vi.. ✓ Fetched repository from 1 seed(s) $ rad patch checkout aa45913 --name alice-init -✓ Switched to branch alice-init +✓ Switched to branch alice-init at revision aa45913 ✓ Branch alice-init setup to track rad/patches/aa45913e757cacd46972733bddee5472c78fa32a ``` @@ -81,7 +81,7 @@ $ rad patch checkout aa45913 --name alice-init ``` ~bob $ rad patch checkout aa45913 -f --name alice-init -✓ Switched to branch alice-init +✓ Switched to branch alice-init at revision 3156bed $ git status On branch alice-init Your branch is up to date with 'rad/patches/aa45913e757cacd46972733bddee5472c78fa32a'. diff --git a/radicle-cli/examples/rad-patch-checkout-revision.md b/radicle-cli/examples/rad-patch-checkout-revision.md index 5d9b6236..ef48a2e2 100644 --- a/radicle-cli/examples/rad-patch-checkout-revision.md +++ b/radicle-cli/examples/rad-patch-checkout-revision.md @@ -40,7 +40,7 @@ So, let's checkout the previous revision, `0c0942e2`: ``` $ rad patch checkout aa45913 --revision 3156bed9d64d4675d6cf56612d217fc5f4e8a53a -f -✓ Switched to branch patch/aa45913 +✓ Switched to branch patch/aa45913 at revision 3156bed ``` And we can confirm that the current commit corresponds to `27857ec`: diff --git a/radicle-cli/examples/rad-patch-checkout.md b/radicle-cli/examples/rad-patch-checkout.md index f266b5ba..eadb67fc 100644 --- a/radicle-cli/examples/rad-patch-checkout.md +++ b/radicle-cli/examples/rad-patch-checkout.md @@ -31,7 +31,7 @@ Now, let's checkout the patch that we just created: ``` $ rad patch checkout aa45913e757cacd46972733bddee5472c78fa32a -✓ Switched to branch patch/aa45913 +✓ Switched to branch patch/aa45913 at revision aa45913 ✓ Branch patch/aa45913 setup to track rad/patches/aa45913e757cacd46972733bddee5472c78fa32a ``` @@ -41,7 +41,7 @@ as long as we haven't made changes to it. ``` $ git checkout master -q $ rad patch checkout aa45913 -✓ Switched to branch patch/aa45913 +✓ Switched to branch patch/aa45913 at revision aa45913 ``` Now, let's add a README too! diff --git a/radicle-cli/examples/rad-patch-pull-update.md b/radicle-cli/examples/rad-patch-pull-update.md index fcb08b5f..9f93cfa8 100644 --- a/radicle-cli/examples/rad-patch-pull-update.md +++ b/radicle-cli/examples/rad-patch-pull-update.md @@ -67,7 +67,7 @@ Alice checks it out. ``` ~alice $ rad patch checkout 55b9721ed7f6bfec38f43729e9b6631c5dc812fb -✓ Switched to branch patch/55b9721 +✓ Switched to branch patch/55b9721 at revision 55b9721 ✓ Branch patch/55b9721 setup to track rad/patches/55b9721ed7f6bfec38f43729e9b6631c5dc812fb $ git show commit bdcdb30b3c0f513620dd0f1c24ff8f4f71de956b diff --git a/radicle-cli/examples/rad-patch.md b/radicle-cli/examples/rad-patch.md index 1ff17470..23fa0e44 100644 --- a/radicle-cli/examples/rad-patch.md +++ b/radicle-cli/examples/rad-patch.md @@ -147,7 +147,7 @@ Now, let's checkout the patch that we just created: ``` $ rad patch checkout aa45913 -✓ Switched to branch patch/aa45913 +✓ Switched to branch patch/aa45913 at revision 6e5a3b7 ✓ Branch patch/aa45913 setup to track rad/patches/aa45913e757cacd46972733bddee5472c78fa32a ``` diff --git a/radicle-cli/examples/rad-push-and-pull-patches.md b/radicle-cli/examples/rad-push-and-pull-patches.md index dd31db11..8c5f2e1e 100644 --- a/radicle-cli/examples/rad-push-and-pull-patches.md +++ b/radicle-cli/examples/rad-push-and-pull-patches.md @@ -13,7 +13,7 @@ $ git rev-parse HEAD f2de534b5e81d7c6e2dcaf58c3dd91573c0a0354 $ git checkout master -q $ rad patch checkout d004b67 -✓ Switched to branch patch/d004b67 +✓ Switched to branch patch/d004b67 at revision d004b67 ✓ Branch patch/d004b67 setup to track rad/patches/d004b67355456c46de10c0d287e4a791ad1a6945 $ rad remote add z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk ✓ Follow policy updated for z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk diff --git a/radicle-cli/examples/workflow/5-patching-maintainer.md b/radicle-cli/examples/workflow/5-patching-maintainer.md index e78a4c25..90c9bc79 100644 --- a/radicle-cli/examples/workflow/5-patching-maintainer.md +++ b/radicle-cli/examples/workflow/5-patching-maintainer.md @@ -52,7 +52,7 @@ changes. ``` $ rad patch checkout e4934b6d9dbe01ce3c7fbb5b77a80d5f1dacdc46 -✓ Switched to branch patch/e4934b6 +✓ Switched to branch patch/e4934b6 at revision 773b9aa ✓ Branch patch/e4934b6 setup to track rad/patches/e4934b6d9dbe01ce3c7fbb5b77a80d5f1dacdc46 $ git mv REQUIREMENTS REQUIREMENTS.md $ git commit -m "Use markdown for requirements" diff --git a/radicle-cli/src/commands/patch/checkout.rs b/radicle-cli/src/commands/patch/checkout.rs index 815bfae3..9f3e3c2c 100644 --- a/radicle-cli/src/commands/patch/checkout.rs +++ b/radicle-cli/src/commands/patch/checkout.rs @@ -42,11 +42,14 @@ pub fn run( .get(patch_id)? .ok_or_else(|| anyhow!("Patch `{patch_id}` not found"))?; - let revision = match revision_id { - Some(id) => patch - .revision(&id) - .ok_or_else(|| anyhow!("Patch revision `{id}` not found"))?, - None => patch.latest().1, + let (revision_id, revision) = match revision_id { + Some(id) => ( + id, + patch + .revision(&id) + .ok_or_else(|| anyhow!("Patch revision `{id}` not found"))?, + ), + None => patch.latest(), }; let mut spinner = term::spinner("Performing checkout..."); @@ -88,8 +91,9 @@ pub fn run( working.set_head(&git::refs::workdir::branch(&patch_branch))?; spinner.message(format!( - "Switched to branch {}", - term::format::highlight(&patch_branch) + "Switched to branch {} at revision {}", + term::format::highlight(&patch_branch), + term::format::secondary(term::format::oid(revision_id)), )); spinner.finish();