Skip to content

Commit 30fb916

Browse files
feat(record): add --new to create empty commits
1 parent cee2300 commit 30fb916

8 files changed

Lines changed: 478 additions & 125 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
- (#1464): created `git split` command to extract changes from a commit
1616
- (#1603): added `git move --dry-run` to test in-memory rebases
1717
- (#1604): `git record` and `git amend` can now automatically detect and begin tracking new files (optional, disabled by default)
18+
- (#1612): added `git record --new` to create new, empty commits
1819
- (#1632): added `git record --fixup` option, to create a fixup commit (similar to `reword --fixup`)
1920

2021
### Changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

git-branchless-lib/src/git/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ pub use reference::{
2323
};
2424
pub use repo::{
2525
AmendFastOptions, CherryPickFastOptions, CreateCommitFastError, Error as RepoError,
26-
GitErrorCode, GitVersion, PatchId, Repo, ResolvedReferenceInfo, Result as RepoResult, Time,
27-
message_prettify,
26+
GitErrorCode, GitVersion, PatchId, Repo, ResolvedReferenceInfo, Result as RepoResult,
27+
Signature, Time, message_prettify,
2828
};
2929
pub use run::{GitRunInfo, GitRunOpts, GitRunResult};
3030
pub use snapshot::{WorkingCopyChangesType, WorkingCopySnapshot};

git-branchless-lib/src/git/repo.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,6 +1646,18 @@ impl std::fmt::Debug for Signature<'_> {
16461646
}
16471647

16481648
impl<'repo> Signature<'repo> {
1649+
/// Create a new signature.
1650+
#[instrument]
1651+
pub fn new(name: &str, email: &str, now: &SystemTime) -> Result<Self> {
1652+
Ok({
1653+
Signature {
1654+
inner: git2::Signature::now(name, email).map_err(Error::CreateSignature)?,
1655+
}
1656+
.update_timestamp(*now)?
1657+
})
1658+
}
1659+
1660+
/// Create an automated signature, for internal use.
16491661
#[instrument]
16501662
pub fn automated() -> Result<Self> {
16511663
Ok(Signature {
@@ -1695,10 +1707,12 @@ impl<'repo> Signature<'repo> {
16951707
}
16961708
}
16971709

1710+
/// Get the name applied to this signature.
16981711
pub fn get_name(&self) -> Option<&str> {
16991712
self.inner.name()
17001713
}
17011714

1715+
/// Get the email applied to this signature.
17021716
pub fn get_email(&self) -> Option<&str> {
17031717
self.inner.email()
17041718
}

git-branchless-opts/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,10 @@ pub struct RecordArgs {
344344
#[clap(action, short = 's', long = "stash", conflicts_with_all(&["create", "detach"]))]
345345
pub stash: bool,
346346

347+
/// Create an empty commit, leaving any changes uncommitted.
348+
#[clap(action, long = "new", conflicts_with("stash"))]
349+
pub new: bool,
350+
347351
/// How should newly encountered, untracked files be handled?
348352
#[clap(value_parser, long = "untracked", conflicts_with_all(&["interactive"]))]
349353
pub untracked_file_strategy: Option<UntrackedFileStrategy>,

git-branchless-record/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ repository = "https://github.com/arxanas/git-branchless"
77
version = "0.10.0"
88

99
[dependencies]
10+
chrono = { workspace = true }
1011
cursive = { version = "0.21.1", default-features = false, features = [
1112
"crossterm-backend",
1213
] }

0 commit comments

Comments
 (0)