Skip to content

Commit

Permalink
temp(submit): try out new commit message format
Browse files Browse the repository at this point in the history
  • Loading branch information
claytonrcarter committed Dec 16, 2024
1 parent f94a071 commit 45a458f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 20 deletions.
9 changes: 9 additions & 0 deletions git-branchless-lib/src/git/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ pub struct Diff<'repo> {
pub(super) inner: git2::Diff<'repo>,
}

impl Diff<'_> {
/// TODO
pub fn short_stats(&self) -> eyre::Result<String> {
let stats = self.inner.stats()?;
let buf = stats.to_buf(git2::DiffStatsFormat::SHORT, usize::MAX)?;
Ok(buf.as_str().expect("TODO").trim().to_string())
}
}

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
struct GitHunk {
old_start: usize,
Expand Down
13 changes: 12 additions & 1 deletion git-branchless/src/commands/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,18 @@ pub fn split(
}
}
}
let message = message.expect("at least 1 file should have been given");
let message = {
let (effects, _progress) =
effects.start_operation(lib::core::effects::OperationType::CalculateDiff);
let diff = repo.get_diff_between_trees(
&effects,
Some(&commit_to_split.get_tree()?),
&split_tree,
0, // we don't care about the context here
)?;

diff.short_stats()?
};

let split_commit_oid =
commit_to_split.amend_commit(None, None, None, None, Some(&split_tree))?;
Expand Down
38 changes: 19 additions & 19 deletions git-branchless/tests/test_split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn test_split_detached_head() -> eyre::Result<()> {
|
@ 2932db7 first commit
|
o c159d6a temp(split): test2.txt
o 753c8a5 temp(split): 1 file changed, 1 deletion(-)
"###);
}

Expand Down Expand Up @@ -91,7 +91,7 @@ fn test_split_added_file() -> eyre::Result<()> {
|
@ 2f9e232 first commit
|
o 067feb9 temp(split): test2.txt
o f26ed15 temp(split): 1 file changed, 1 deletion(-)
"###);
}

Expand Down Expand Up @@ -148,7 +148,7 @@ fn test_split_modified_file() -> eyre::Result<()> {
|
@ 495b4c0 first commit
|
o 590b05e temp(split): test1.txt
o c41e243 temp(split): 1 file changed, 1 insertion(+), 1 deletion(-)
"###);
}

Expand Down Expand Up @@ -215,7 +215,7 @@ fn test_split_deleted_file() -> eyre::Result<()> {
|
@ 495b4c0 first commit
|
o bfc063a temp(split): test1.txt
o 7cf0fa0 temp(split): 1 file changed, 1 insertion(+)
"###);
}

Expand Down Expand Up @@ -268,7 +268,7 @@ fn test_split_multiple_files() -> eyre::Result<()> {
|
@ 8e5c74b first commit
|
o 0b1f3c6 temp(split): 2 files
o a3072f1 temp(split): 2 files changed, 2 deletions(-)
"###);
}

Expand Down Expand Up @@ -324,7 +324,7 @@ fn test_split_detached_branch() -> eyre::Result<()> {
|
@ 2932db7 (branch-name) first commit
|
o c159d6a temp(split): test2.txt
o 753c8a5 temp(split): 1 file changed, 1 deletion(-)
"###);
}

Expand Down Expand Up @@ -368,7 +368,7 @@ fn test_split_attached_branch() -> eyre::Result<()> {
|
o 2932db7 first commit
|
@ c159d6a (> branch-name) temp(split): test2.txt
@ 753c8a5 (> branch-name) temp(split): 1 file changed, 1 deletion(-)
"###);

let (stdout, _stderr) = git.run(&["status", "--short"])?;
Expand Down Expand Up @@ -407,17 +407,17 @@ fn test_split_restacks_descendents() -> eyre::Result<()> {
let (stdout, _stderr) = git.branchless("split", &["HEAD~", "test2.txt"])?;
insta::assert_snapshot!(&stdout, @r###"
Attempting rebase in-memory...
[1/1] Committed as: 71d03a3 create test3.txt
[1/1] Committed as: 86f12ce create test3.txt
branchless: processing 1 rewritten commit
branchless: running command: <git-executable> checkout 71d03a33c534eda4253fc8772a4c0d5e9515127c
branchless: running command: <git-executable> checkout 86f12ceba66a3bfc888cbdd090af9a4a581b6f2a
In-memory rebase succeeded.
O f777ecc (master) create initial.txt
|
o 2932db7 first commit
|
o c159d6a temp(split): test2.txt
o 753c8a5 temp(split): 1 file changed, 1 deletion(-)
|
@ 71d03a3 create test3.txt
@ 86f12ce create test3.txt
"###);
}

Expand Down Expand Up @@ -468,17 +468,17 @@ fn test_split_undo_works() -> eyre::Result<()> {
let (stdout, _stderr) = git.branchless("split", &["HEAD~", "test2.txt"])?;
insta::assert_snapshot!(&stdout, @r###"
Attempting rebase in-memory...
[1/1] Committed as: 71d03a3 create test3.txt
[1/1] Committed as: 86f12ce create test3.txt
branchless: processing 1 rewritten commit
branchless: running command: <git-executable> checkout 71d03a33c534eda4253fc8772a4c0d5e9515127c
branchless: running command: <git-executable> checkout 86f12ceba66a3bfc888cbdd090af9a4a581b6f2a
In-memory rebase succeeded.
O f777ecc (master) create initial.txt
|
o 2932db7 first commit
|
o c159d6a temp(split): test2.txt
o 753c8a5 temp(split): 1 file changed, 1 deletion(-)
|
@ 71d03a3 create test3.txt
@ 86f12ce create test3.txt
"###);
}

Expand Down Expand Up @@ -561,7 +561,7 @@ fn test_split_supports_absolute_relative_and_repo_relative_paths() -> eyre::Resu
|
@ d9d41a3 first commit
|
o fc76a91 temp(split): subdir/test3.txt
o 9dd1584 temp(split): 1 file changed, 1 deletion(-)
"###);

let (stdout, _stderr) = git.run(&["show", "--pretty=format:", "--stat", "HEAD"])?;
Expand Down Expand Up @@ -593,7 +593,7 @@ fn test_split_supports_absolute_relative_and_repo_relative_paths() -> eyre::Resu
|
@ 0cb8154 first commit
|
o 5d2c1d0 temp(split): subdir/test1.txt
o e75ab8c temp(split): 1 file changed, 1 deletion(-)
"###);

let (stdout, _stderr) = git.run(&["show", "--pretty=format:", "--stat", "HEAD"])?;
Expand Down Expand Up @@ -625,7 +625,7 @@ fn test_split_supports_absolute_relative_and_repo_relative_paths() -> eyre::Resu
|
@ 9122046 first commit
|
o ba3abaf temp(split): test2.txt
o a3c3b69 temp(split): 1 file changed, 1 deletion(-)
"###);

let (stdout, _stderr) = git.run(&["show", "--pretty=format:", "--stat", "HEAD"])?;
Expand Down Expand Up @@ -657,7 +657,7 @@ fn test_split_supports_absolute_relative_and_repo_relative_paths() -> eyre::Resu
|
@ 6d0cd9b first commit
|
o 2f03a38 temp(split): test1.txt
o df7bd3a temp(split): 1 file changed, 1 deletion(-)
"###);

let (stdout, _stderr) = git.run(&["show", "--pretty=format:", "--stat", "HEAD"])?;
Expand Down

0 comments on commit 45a458f

Please sign in to comment.