Skip to content

Commit 45a458f

Browse files
temp(submit): try out new commit message format
See arxanas#1462
1 parent f94a071 commit 45a458f

File tree

3 files changed

+40
-20
lines changed

3 files changed

+40
-20
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ pub struct Diff<'repo> {
1515
pub(super) inner: git2::Diff<'repo>,
1616
}
1717

18+
impl Diff<'_> {
19+
/// TODO
20+
pub fn short_stats(&self) -> eyre::Result<String> {
21+
let stats = self.inner.stats()?;
22+
let buf = stats.to_buf(git2::DiffStatsFormat::SHORT, usize::MAX)?;
23+
Ok(buf.as_str().expect("TODO").trim().to_string())
24+
}
25+
}
26+
1827
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
1928
struct GitHunk {
2029
old_start: usize,

git-branchless/src/commands/split.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,18 @@ pub fn split(
203203
}
204204
}
205205
}
206-
let message = message.expect("at least 1 file should have been given");
206+
let message = {
207+
let (effects, _progress) =
208+
effects.start_operation(lib::core::effects::OperationType::CalculateDiff);
209+
let diff = repo.get_diff_between_trees(
210+
&effects,
211+
Some(&commit_to_split.get_tree()?),
212+
&split_tree,
213+
0, // we don't care about the context here
214+
)?;
215+
216+
diff.short_stats()?
217+
};
207218

208219
let split_commit_oid =
209220
commit_to_split.amend_commit(None, None, None, None, Some(&split_tree))?;

git-branchless/tests/test_split.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn test_split_detached_head() -> eyre::Result<()> {
3232
|
3333
@ 2932db7 first commit
3434
|
35-
o c159d6a temp(split): test2.txt
35+
o 753c8a5 temp(split): 1 file changed, 1 deletion(-)
3636
"###);
3737
}
3838

@@ -91,7 +91,7 @@ fn test_split_added_file() -> eyre::Result<()> {
9191
|
9292
@ 2f9e232 first commit
9393
|
94-
o 067feb9 temp(split): test2.txt
94+
o f26ed15 temp(split): 1 file changed, 1 deletion(-)
9595
"###);
9696
}
9797

@@ -148,7 +148,7 @@ fn test_split_modified_file() -> eyre::Result<()> {
148148
|
149149
@ 495b4c0 first commit
150150
|
151-
o 590b05e temp(split): test1.txt
151+
o c41e243 temp(split): 1 file changed, 1 insertion(+), 1 deletion(-)
152152
"###);
153153
}
154154

@@ -215,7 +215,7 @@ fn test_split_deleted_file() -> eyre::Result<()> {
215215
|
216216
@ 495b4c0 first commit
217217
|
218-
o bfc063a temp(split): test1.txt
218+
o 7cf0fa0 temp(split): 1 file changed, 1 insertion(+)
219219
"###);
220220
}
221221

@@ -268,7 +268,7 @@ fn test_split_multiple_files() -> eyre::Result<()> {
268268
|
269269
@ 8e5c74b first commit
270270
|
271-
o 0b1f3c6 temp(split): 2 files
271+
o a3072f1 temp(split): 2 files changed, 2 deletions(-)
272272
"###);
273273
}
274274

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

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

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)