Skip to content

Commit

Permalink
Merge branch 'main' into filter-refs-by-spec
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Aug 31, 2022
2 parents 55eb965 + ce01093 commit 56ba481
Show file tree
Hide file tree
Showing 24 changed files with 396 additions and 257 deletions.
385 changes: 186 additions & 199 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Please see _'Development Status'_ for a listing of all crates and their capabili
* **mailmap**
* [x] **entries** - display all entries of the aggregated mailmap git would use for substitution
* **revision**
* [x] **list** - list plain revision hashes from a starting point, similar to a very simple version of `git rev-list`.
* [x] **explain** - show what would be done while parsing a revision specification like `HEAD~1`
* [x] **resolve** - show which objects a revspec resolves to, similar to `git rev-parse` but faster and with much better error handling
* [x] **previous-branches** - list all previously checked out branches, powered by the ref-log.
Expand Down
107 changes: 82 additions & 25 deletions cargo-smart-release/CHANGELOG.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions cargo-smart-release/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-smart-release"
version = "0.12.0"
version = "0.12.1"
authors = ["Sebastian Thiel <[email protected]>"]
repository = "https://github.com/Byron/gitoxide"
description = "Cargo subcommand for fearlessly releasing crates in workspaces."
Expand Down Expand Up @@ -32,7 +32,7 @@ cargo_metadata = "0.14.0"
log = "0.4.14"
toml_edit = "0.14.0"
semver = "1.0.4"
crates-index = "0.18.1"
crates-index = "0.18.9"
cargo_toml = "0.11.4"
nom = { version = "7", default-features = false, features = ["std"]}
git-conventional = "0.11.1"
Expand Down
2 changes: 2 additions & 0 deletions cargo-smart-release/src/changelog/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pub mod init;
mod merge;
mod parse;
pub mod section;
#[cfg(test)]
mod tests;
pub mod write;

pub const DEFAULT_HEADING_LEVEL: usize = 2;
Expand Down
22 changes: 22 additions & 0 deletions cargo-smart-release/src/changelog/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
mod repository_url {
use crate::changelog::write::RepositoryUrl;
use git_repository as git;

#[test]
fn github_https_url() {
for input in [
"https://github.com/byron/gitoxide",
"https://github.com/byron/gitoxide.git",
"git://github.com/byron/gitoxide",
"git://github.com/byron/gitoxide.git",
"[email protected]:byron/gitoxide.git",
"[email protected]:byron/gitoxide",
] {
let url = RepositoryUrl::from(git::url::parse(input.into()).unwrap());
assert_eq!(
url.github_https().expect("possible"),
"https://github.com/byron/gitoxide"
)
}
}
}
10 changes: 6 additions & 4 deletions cargo-smart-release/src/changelog/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ impl RepositoryUrl {
Scheme::Ssh => self
.inner
.user()
.map(|user| format!("https://github.com{}/{}", user, self.cleaned_path())),
Scheme::Ext(_) | Scheme::File => None,
.filter(|user| *user == "git")
.map(|_git| format!("https://github.com{}", self.cleaned_path())),
_ => None,
},
None | Some(_) => None,
}
Expand Down Expand Up @@ -320,9 +321,10 @@ impl section::Segment {
}
writeln!(
out,
" - {} {} where understood as [conventional](https://www.conventionalcommits.org).",
" - {} {} {} understood as [conventional](https://www.conventionalcommits.org).",
conventional_count,
if *conventional_count == 1 { "commit" } else { "commits" }
if *conventional_count == 1 { "commit" } else { "commits" },
if *conventional_count == 1 { "was" } else { "were" }
)?;
if unique_issues.is_empty() {
writeln!(out, " - 0 issues like '(#ID)' where seen in commit messages")?;
Expand Down
2 changes: 1 addition & 1 deletion cargo-smart-release/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub(crate) fn bump_package_with_spec(
let desired_release = v;
let (latest_release, next_release) = match ctx.crates_index.crate_(&package.name) {
Some(published_crate) => {
let latest_release = semver::Version::parse(published_crate.latest_version().version())
let latest_release = semver::Version::parse(published_crate.most_recent_version().version())
.expect("valid version in crate index");
let next_release = if latest_release >= desired_release {
desired_release.clone()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
---
source: cargo-smart-release/tests/changelog/write_and_parse/mod.rs
assertion_line: 183
expression: buf

---
* hello world
this
Expand All @@ -15,7 +13,7 @@ expression: buf

- 100 commits contributed to the release over the course of 32 calendar days.
- 60 days passed between releases.
- 20 commits where understood as [conventional](https://www.conventionalcommits.org).
- 20 commits were understood as [conventional](https://www.conventionalcommits.org).
- 3 unique issues were worked on: #1, Uncategorized, #42

##### Commit Details
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
---
source: cargo-smart-release/tests/changelog/write_and_parse/mod.rs
assertion_line: 169
expression: md

---
# Changelog

Expand Down Expand Up @@ -32,7 +30,7 @@ world

- 100 commits contributed to the release over the course of 32 calendar days.
- 60 days passed between releases.
- 20 commits where understood as [conventional](https://www.conventionalcommits.org).
- 20 commits were understood as [conventional](https://www.conventionalcommits.org).
- 3 unique issues were worked on: [#1](https://github.com/user/repo/issues/1), Uncategorized, [#42](https://github.com/user/repo/issues/42)

##### Commit Details
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
---
source: cargo-smart-release/tests/changelog/write_and_parse/mod.rs
assertion_line: 183
expression: buf

---
* hello world
this
Expand All @@ -15,7 +13,7 @@ expression: buf

- 100 commits contributed to the release over the course of 32 calendar days.
- 60 days passed between releases.
- 20 commits where understood as [conventional](https://www.conventionalcommits.org).
- 20 commits were understood as [conventional](https://www.conventionalcommits.org).
- 3 unique issues were worked on: #1, Uncategorized, #42

##### Commit Details
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
---
source: cargo-smart-release/tests/changelog/write_and_parse/mod.rs
assertion_line: 183
expression: buf

---
#### 1.0.2-beta.2 (1970-01-01)

Expand All @@ -21,7 +19,7 @@ expression: buf

- 100 commits contributed to the release over the course of 32 calendar days.
- 60 days passed between releases.
- 20 commits where understood as [conventional](https://www.conventionalcommits.org).
- 20 commits were understood as [conventional](https://www.conventionalcommits.org).
- 3 unique issues were worked on: #1, Uncategorized, #42

##### Commit Details
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
---
source: cargo-smart-release/tests/changelog/write_and_parse/mod.rs
assertion_line: 169
expression: md

---
# Changelog

Expand Down Expand Up @@ -32,7 +30,7 @@ world

- 100 commits contributed to the release over the course of 32 calendar days.
- 60 days passed between releases.
- 20 commits where understood as [conventional](https://www.conventionalcommits.org).
- 20 commits were understood as [conventional](https://www.conventionalcommits.org).
- 3 unique issues were worked on: #1, Uncategorized, #42

##### Commit Details
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
<csr-read-only-do-not-edit/>

- 1 commit contributed to the release.
- 0 commits where understood as [conventional](https://www.conventionalcommits.org).
- 0 commits were understood as [conventional](https://www.conventionalcommits.org).
- 0 issues like '(#ID)' where seen in commit messages

### Commit Details
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
<csr-read-only-do-not-edit/>

- 1 commit contributed to the release.
- 0 commits where understood as [conventional](https://www.conventionalcommits.org).
- 0 commits were understood as [conventional](https://www.conventionalcommits.org).
- 0 issues like '(#ID)' where seen in commit messages

### Commit Details
Expand All @@ -22,7 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
<details><summary>view details</summary>

* **Uncategorized**
- initial (0189fce)
- initial (515b164)
</details>

## v0.8.0 (2021-09-09)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
<csr-read-only-do-not-edit/>

- 1 commit contributed to the release.
- 0 commits where understood as [conventional](https://www.conventionalcommits.org).
- 0 commits were understood as [conventional](https://www.conventionalcommits.org).
- 0 issues like '(#ID)' where seen in commit messages

### Commit Details
Expand Down
2 changes: 1 addition & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ allow = [
"BSD-3-Clause",
"MIT",
"ISC",
"CC-PDDC",
"Unicode-DFS-2016",
]
# Lint level for licenses considered copyleft
copyleft = "allow"
Expand Down
34 changes: 34 additions & 0 deletions gitoxide-core/src/repository/revision/list.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use anyhow::{bail, Context};
use git_repository as git;
use git_repository::prelude::ObjectIdExt;
use std::ffi::OsString;

use crate::OutputFormat;

pub fn list(
mut repo: git::Repository,
spec: OsString,
mut out: impl std::io::Write,
format: OutputFormat,
) -> anyhow::Result<()> {
if format != OutputFormat::Human {
bail!("Only human output is currently supported");
}
repo.object_cache_size_if_unset(4 * 1024 * 1024);

let spec = git::path::os_str_into_bstr(&spec)?;
let id = repo
.rev_parse(spec)?
.single()
.context("Only single revisions are currently supported")?;
let commit_id = id
.object()?
.peel_to_kind(git::object::Kind::Commit)
.context("Need commitish as starting point")?
.id
.attach(&repo);
for commit in commit_id.ancestors().all()? {
writeln!(out, "{}", commit?.to_hex())?;
}
Ok(())
}
4 changes: 3 additions & 1 deletion gitoxide-core/src/repository/revision/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
mod list;
pub use list::list;
mod explain;
pub use explain::explain;

pub mod resolve;
pub use resolve::function::resolve;

mod previous_branches;
pub use previous_branches::function as previous_branches;
pub use previous_branches::previous_branches;
6 changes: 5 additions & 1 deletion gitoxide-core/src/repository/revision/previous_branches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ use git_repository as git;

use crate::OutputFormat;

pub fn function(repo: git::Repository, mut out: impl std::io::Write, format: OutputFormat) -> anyhow::Result<()> {
pub fn previous_branches(
repo: git::Repository,
mut out: impl std::io::Write,
format: OutputFormat,
) -> anyhow::Result<()> {
let branches = repo
.head()?
.prior_checked_out_branches()?
Expand Down
10 changes: 10 additions & 0 deletions src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,16 @@ pub fn main() -> Result<()> {
},
),
Subcommands::Revision(cmd) => match cmd {
revision::Subcommands::List { spec } => prepare_and_run(
"revision-list",
verbose,
progress,
progress_keep_open,
None,
move |_progress, out, _err| {
core::repository::revision::list(repository(Mode::Lenient)?, spec, out, format)
},
),
revision::Subcommands::PreviousBranches => prepare_and_run(
"revision-previousbranches",
verbose,
Expand Down
3 changes: 3 additions & 0 deletions src/plumbing/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ pub mod revision {
#[derive(Debug, clap::Subcommand)]
#[clap(visible_alias = "rev", visible_alias = "r")]
pub enum Subcommands {
/// List all commits reachable from the given rev-spec.
#[clap(visible_alias = "l")]
List { spec: std::ffi::OsString },
/// Provide the revision specification like `@~1` to explain.
#[clap(visible_alias = "e")]
Explain { spec: std::ffi::OsString },
Expand Down
3 changes: 3 additions & 0 deletions tests/tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ license = "MIT OR Apache-2.0"
name = "jtt"
path = "src/main.rs"

[lib]
doctest = false

[dependencies]
git-hash = { version = "^0.9.8", path = "../../git-hash" }
git-lock = { version = "^2.0.0", path = "../../git-lock" }
Expand Down
30 changes: 26 additions & 4 deletions tests/tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,12 @@ fn parse_git_version() -> Result<(u8, u8, u8)> {
let git_program = cfg!(windows).then(|| "git.exe").unwrap_or("git");
let output = std::process::Command::new(git_program).arg("--version").output()?;

let mut numbers = output
.stdout
.split(|b| *b == b' ')
git_version_from_bytes(&output.stdout)
}

fn git_version_from_bytes(bytes: &[u8]) -> Result<(u8, u8, u8)> {
let mut numbers = bytes
.split(|b| *b == b' ' || *b == b'\n')
.nth(2)
.expect("git version <version>")
.split(|b| *b == b'.')
Expand All @@ -115,7 +118,7 @@ fn parse_git_version() -> Result<(u8, u8, u8)> {
.map_err(|err| {
format!(
"Could not parse version from output of 'git --version' ({:?}) with error: {}",
output.stdout.to_str_lossy(),
bytes.to_str_lossy(),
err
)
})?)
Expand Down Expand Up @@ -540,3 +543,22 @@ impl<'a> Drop for Env<'a> {
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn parse_version() {
assert_eq!(git_version_from_bytes(b"git version 2.37.2").unwrap(), (2, 37, 2));
assert_eq!(
git_version_from_bytes(b"git version 2.32.1 (Apple Git-133)").unwrap(),
(2, 32, 1)
);
}

#[test]
fn parse_version_with_trailing_newline() {
assert_eq!(git_version_from_bytes(b"git version 2.37.2\n").unwrap(), (2, 37, 2));
}
}

0 comments on commit 56ba481

Please sign in to comment.