Skip to content

Commit

Permalink
Merge branch 'main' into feat/hook-shell
Browse files Browse the repository at this point in the history
  • Loading branch information
oknozor committed Oct 5, 2023
2 parents b07425c + 5b34ee4 commit 16d1896
Show file tree
Hide file tree
Showing 12 changed files with 184 additions and 32 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
All notable changes to this project will be documented in this file. See [conventional commits](https://www.conventionalcommits.org/) for commit guidelines.

- - -
## [5.6.0](https://github.com/cocogitto/cocogitto/compare/5.5.0..5.6.0) - 2023-09-27
#### Bug Fixes
- **(bump)** option to disable untracked changes error - ([da459de](https://github.com/cocogitto/cocogitto/commit/da459decff9a84bb5bde471f5d64f577df28df11)) - [@Wassim-AB](https://github.com/Wassim-AB)
#### Documentation
- fix discord invite link - ([5d11d5a](https://github.com/cocogitto/cocogitto/commit/5d11d5aec58b4d88b2606c3f8b2ca4e7688590c2)) - [@oknozor](https://github.com/oknozor)
#### Features
- **(bump)** added skip untracked as cli argument - ([fb6a7e6](https://github.com/cocogitto/cocogitto/commit/fb6a7e667cdcddc185e02894b03b3b623610ca77)) - [@Wassim-AB](https://github.com/Wassim-AB)
#### Miscellaneous Chores
- edited contributors list - ([eca20b8](https://github.com/cocogitto/cocogitto/commit/eca20b8a4cd602225e5a386a06e1f22c39e4fddd)) - [@Wassim-AB](https://github.com/Wassim-AB)
- bump yanked crates - ([89149ad](https://github.com/cocogitto/cocogitto/commit/89149adfb9e45fc3b236fb2bf44d92843be30047)) - [@tranzystorek-io](https://github.com/tranzystorek-io)

- - -

## [5.5.0](https://github.com/cocogitto/cocogitto/compare/5.4.0..5.5.0) - 2023-08-17
#### Documentation
- **(README)** fix links to cocogitto docs - ([d62a83c](https://github.com/cocogitto/cocogitto/commit/d62a83c5613dc51a5b8201a0d2747493f148a758)) - [@lukehsiao](https://github.com/lukehsiao)
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cocogitto"
version = "5.5.0"
version = "5.6.0"
authors = ["Paul Delafosse <paul.delafosse@protonmail.com>"]
edition = "2021"
readme = "README.md"
Expand Down
3 changes: 2 additions & 1 deletion cog.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,6 @@ authors = [
{ signature = "Racci", username = "DaRacci" },
{ signature = "Conrad Hoffmann", username = "bitfehler" },
{ signature = "andre161292", username = "andre161292" },
{ signature = "Sanchith Hegde", username = "SanchithHegde" }
{ signature = "Sanchith Hegde", username = "SanchithHegde" },
{ signature = "Wassim Ahmed-Belkacem", username = "Wassim-AB" },
]
8 changes: 8 additions & 0 deletions src/bin/cog/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ enum Command {
/// Specify a "Skip CI" string to append to the end of the commit
#[arg(long = "skip-ci")]
skip_ci: Option<String>,

/// Don't fail if there are untracked or uncommited files
#[arg(long = "skip-untracked")]
skip_untracked: bool,
},

/// Install cog config files
Expand Down Expand Up @@ -363,6 +367,7 @@ fn main() -> Result<()> {
annotated,
dry_run,
skip_ci,
skip_untracked,
} => {
let mut cocogitto = CocoGitto::get()?;
let is_monorepo = !SETTINGS.packages.is_empty();
Expand Down Expand Up @@ -398,6 +403,7 @@ fn main() -> Result<()> {
annotated,
dry_run,
skip_ci,
skip_untracked,
)?
}
None => cocogitto.create_monorepo_version(
Expand All @@ -407,6 +413,7 @@ fn main() -> Result<()> {
annotated,
dry_run,
skip_ci,
skip_untracked,
)?,
}
} else {
Expand All @@ -417,6 +424,7 @@ fn main() -> Result<()> {
annotated,
dry_run,
skip_ci,
skip_untracked,
)?
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/command/bump/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl CocoGitto {
}
}

fn pre_bump_checks(&mut self) -> Result<()> {
fn pre_bump_checks(&mut self, skip_untracked: bool) -> Result<()> {
if *SETTINGS == Settings::default() {
let part1 = "Warning: using".yellow();
let part2 = "with the default configuration. \n".yellow();
Expand All @@ -143,8 +143,11 @@ impl CocoGitto {
}
let statuses = self.repository.get_statuses()?;

// Fail if repo contains un-staged or un-committed changes
ensure!(statuses.0.is_empty(), "{}", self.repository.get_statuses()?);
if skip_untracked || SETTINGS.skip_untracked {
eprintln!("{}", self.repository.get_statuses()?);
} else {
ensure!(statuses.0.is_empty(), "{}", self.repository.get_statuses()?);
}

if !SETTINGS.branch_whitelist.is_empty() {
if let Some(branch) = self.repository.get_branch_shorthand() {
Expand Down
15 changes: 12 additions & 3 deletions src/command/bump/monorepo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct PackageData {
}

impl CocoGitto {
#[allow(clippy::too_many_arguments)]
pub fn create_monorepo_version(
&mut self,
increment: IncrementCommand,
Expand All @@ -46,6 +47,7 @@ impl CocoGitto {
annotated: Option<String>,
dry_run: bool,
skip_ci: Option<String>,
skip_untracked: bool,
) -> Result<()> {
match increment {
IncrementCommand::Auto => {
Expand All @@ -56,6 +58,7 @@ impl CocoGitto {
annotated,
dry_run,
skip_ci,
skip_untracked,
)
} else {
if annotated.is_some() {
Expand All @@ -66,6 +69,7 @@ impl CocoGitto {
hooks_config,
dry_run,
skip_ci,
skip_untracked,
)
}
}
Expand All @@ -76,6 +80,7 @@ impl CocoGitto {
annotated,
dry_run,
skip_ci,
skip_untracked,
),
}
}
Expand All @@ -86,8 +91,9 @@ impl CocoGitto {
hooks_config: Option<&str>,
dry_run: bool,
skip_ci: Option<String>,
skip_untracked: bool,
) -> Result<()> {
self.pre_bump_checks()?;
self.pre_bump_checks(skip_untracked)?;
// Get package bumps
let bumps = self.get_packages_bumps(pre_release)?;

Expand Down Expand Up @@ -151,8 +157,9 @@ impl CocoGitto {
annotated: Option<String>,
dry_run: bool,
skip_ci: Option<String>,
skip_untracked: bool,
) -> Result<()> {
self.pre_bump_checks()?;
self.pre_bump_checks(skip_untracked)?;
// Get package bumps
let bumps = self.get_packages_bumps(pre_release)?;

Expand Down Expand Up @@ -298,6 +305,7 @@ impl CocoGitto {
Ok(())
}

#[allow(clippy::too_many_arguments)]
fn create_monorepo_version_manual(
&mut self,
increment: IncrementCommand,
Expand All @@ -306,8 +314,9 @@ impl CocoGitto {
annotated: Option<String>,
dry_run: bool,
skip_ci: Option<String>,
skip_untracked: bool,
) -> Result<()> {
self.pre_bump_checks()?;
self.pre_bump_checks(skip_untracked)?;
// Get package bumps
let bumps = self.get_current_packages()?;

Expand Down
3 changes: 2 additions & 1 deletion src/command/bump/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ impl CocoGitto {
annotated: Option<String>,
dry_run: bool,
skip_ci: Option<String>,
skip_untracked: bool,
) -> Result<()> {
self.pre_bump_checks()?;
self.pre_bump_checks(skip_untracked)?;

let current_tag = self.repository.get_latest_package_tag(package_name);
let current_tag = tag_or_fallback_to_zero(current_tag)?;
Expand Down
4 changes: 3 additions & 1 deletion src/command/bump/standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use semver::Prerelease;
use tera::Tera;

impl CocoGitto {
#[allow(clippy::too_many_arguments)]
pub fn create_version(
&mut self,
increment: IncrementCommand,
Expand All @@ -22,8 +23,9 @@ impl CocoGitto {
annotated: Option<String>,
dry_run: bool,
skip_ci: Option<String>,
skip_untracked: bool,
) -> Result<()> {
self.pre_bump_checks()?;
self.pre_bump_checks(skip_untracked)?;

let current_tag = self.repository.get_latest_tag();
let current_tag = tag_or_fallback_to_zero(current_tag)?;
Expand Down
2 changes: 2 additions & 0 deletions src/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub struct Settings {
pub tag_prefix: Option<String>,
pub skip_ci: Option<String>,
pub shell: Option<HookShell>,
pub skip_untracked: bool,
pub pre_bump_hooks: Vec<String>,
pub post_bump_hooks: Vec<String>,
pub pre_package_bump_hooks: Vec<String>,
Expand All @@ -60,6 +61,7 @@ impl Default for Settings {
tag_prefix: None,
skip_ci: None,
shell: None,
skip_untracked: false,
pre_bump_hooks: vec![],
post_bump_hooks: vec![],
pre_package_bump_hooks: vec![],
Expand Down
47 changes: 47 additions & 0 deletions tests/cog_tests/bump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::helpers::*;

use anyhow::Result;
use assert_cmd::prelude::*;
use cmd_lib::run_cmd;
use cocogitto::settings::Settings;
use indoc::indoc;
use sealed_test::prelude::*;
Expand Down Expand Up @@ -333,3 +334,49 @@ fn package_dry_run() -> Result<()> {
assert_tag_does_not_exist("1.1.0")?;
Ok(())
}

#[sealed_test]
fn uncommited_changes_should_throw_error_by_default() -> Result<()> {
init_monorepo(&mut Settings::default())?;

run_cmd!(
echo two > two;
)?;

Command::cargo_bin("cog")?
.arg("bump")
.arg("--auto")
.arg("--dry-run")
.assert()
.failure();

Ok(())
}

#[sealed_test]
fn uncommited_changes_should_not_throw_error_with_option() -> Result<()> {
let mut settings = Settings {
skip_untracked: true,
..Default::default()
};

init_monorepo(&mut settings)?;

run_cmd!(
echo two > two;
echo "other changes" > one/file;
)?;

Command::cargo_bin("cog")?
.arg("bump")
.arg("--auto")
.arg("--dry-run")
.assert()
.success()
.stderr(indoc!("Untracked files :\n\tmodified: one/file\n\tnew: two\n\nnothing added to commit but untracked files present (use \"git add\" to track)\n\n"))
.stdout(indoc!("one-0.1.0\n0.1.0\n"));

assert_that!(Path::new("CHANGELOG.md")).does_not_exist();
assert_tag_does_not_exist("1.1.0")?;
Ok(())
}
Loading

0 comments on commit 16d1896

Please sign in to comment.