1- use snapbox:: str;
2-
31use crate :: utils:: { Sandbox , setup_metadata} ;
2+ use gitbutler_commit:: commit_ext:: CommitExt ;
3+ use snapbox:: str;
44
55#[ test]
66fn describe_commit_with_message_flag ( ) -> anyhow:: Result < ( ) > {
@@ -22,43 +22,17 @@ Updated commit message for [..] (now [..])
2222
2323"# ] ] ) ;
2424
25- // Verify the commit message was updated
26- let log = env. git_log ( ) ?;
27- assert ! ( log. contains( "Updated commit message" ) ) ;
28- assert ! ( !log. contains( "add A" ) ) ;
29-
30- Ok ( ( ) )
31- }
32-
33- // Note: Branch rename test is omitted because the test scenario uses single-character
34- // branch names ("A") which don't meet the 2-character minimum requirement for CLI IDs.
35- // The branch rename functionality with -m flag is tested manually and works correctly.
36-
37- #[ test]
38- fn describe_with_empty_message_fails ( ) -> anyhow:: Result < ( ) > {
39- let env = Sandbox :: init_scenario_with_target_and_default_settings ( "one-stack" ) ?;
4025 insta:: assert_snapshot!( env. git_log( ) ?, @r"
41- * edd3eb7 (HEAD -> gitbutler/workspace) GitButler Workspace Commit
42- * 9477ae7 (A) add A
43- * 0dc3733 (origin/main, origin/HEAD, main) add M
26+ * d84f3c4 (HEAD -> gitbutler/workspace) GitButler Workspace Commit
27+ * 2f7c570 (A) Updated commit message
28+ * 0dc3733 (origin/main, origin/HEAD, main, gitbutler/target ) add M
4429 " ) ;
4530
46- setup_metadata ( & env, & [ "A" ] ) ?;
47-
48- // Try to describe commit with empty message
49- env. but ( "describe 9477ae7 -m ''" )
50- . assert ( )
51- . failure ( )
52- . stderr_eq ( str![ [ r#"
53- Error: Aborting due to empty commit message
54-
55- "# ] ] ) ;
56-
5731 Ok ( ( ) )
5832}
5933
6034#[ test]
61- fn describe_with_whitespace_only_message_fails ( ) -> anyhow:: Result < ( ) > {
35+ fn describe_commit_with_multiline_message ( ) -> anyhow:: Result < ( ) > {
6236 let env = Sandbox :: init_scenario_with_target_and_default_settings ( "one-stack" ) ?;
6337 insta:: assert_snapshot!( env. git_log( ) ?, @r"
6438 * edd3eb7 (HEAD -> gitbutler/workspace) GitButler Workspace Commit
@@ -68,66 +42,40 @@ fn describe_with_whitespace_only_message_fails() -> anyhow::Result<()> {
6842
6943 setup_metadata ( & env, & [ "A" ] ) ?;
7044
71- // Try to describe commit with whitespace-only message
72- env. but ( "describe 9477ae7 -m ' '" )
45+ // Use describe with multiline message
46+ env. but ( "describe 9477ae7 -m 'First line \n \n \t Second paragraph with details '" )
7347 . assert ( )
74- . failure ( )
75- . stderr_eq ( str![ [ r#"
76- Error: Aborting due to empty commit message
48+ . success ( )
49+ . stdout_eq ( str![ [ r#"
50+ Updated commit message for [..] (now [..])
7751
7852"# ] ] ) ;
7953
80- Ok ( ( ) )
81- }
82-
83- #[ test]
84- fn describe_commit_with_same_message_fails ( ) -> anyhow:: Result < ( ) > {
85- let env = Sandbox :: init_scenario_with_target_and_default_settings ( "one-stack" ) ?;
54+ // Verify the commit message was updated with multiline content
8655 insta:: assert_snapshot!( env. git_log( ) ?, @r"
87- * edd3eb7 (HEAD -> gitbutler/workspace) GitButler Workspace Commit
88- * 9477ae7 (A) add A
89- * 0dc3733 (origin/main, origin/HEAD, main) add M
56+ * f2c2b50 (HEAD -> gitbutler/workspace) GitButler Workspace Commit
57+ * cdf2c74 (A) First line
58+ * 0dc3733 (origin/main, origin/HEAD, main, gitbutler/target ) add M
9059 " ) ;
9160
92- setup_metadata ( & env, & [ "A" ] ) ?;
93-
94- // Try to describe with the same message
95- env. but ( "describe 9477ae7 -m 'add A'" )
96- . assert ( )
97- . failure ( )
98- . stderr_eq ( str![ [ r#"
99- Error: No changes to commit message.
100-
101- "# ] ] ) ;
61+ let repo = env. open_repo ( ) ?;
62+ assert_eq ! (
63+ repo. rev_parse_single( ":/First line" ) ?
64+ . object( ) ?
65+ . into_commit( )
66+ . message_bstr( ) ,
67+ "First line\n \n \t Second paragraph with details"
68+ ) ;
10269
10370 Ok ( ( ) )
10471}
10572
106- #[ test]
107- fn describe_nonexistent_target_fails ( ) -> anyhow:: Result < ( ) > {
108- let env = Sandbox :: init_scenario_with_target_and_default_settings ( "one-stack" ) ?;
109- insta:: assert_snapshot!( env. git_log( ) ?, @r"
110- * edd3eb7 (HEAD -> gitbutler/workspace) GitButler Workspace Commit
111- * 9477ae7 (A) add A
112- * 0dc3733 (origin/main, origin/HEAD, main) add M
113- " ) ;
114-
115- setup_metadata ( & env, & [ "A" ] ) ?;
116-
117- // Try to describe a nonexistent target
118- env. but ( "describe nonexistent -m 'new message'" )
119- . assert ( )
120- . failure ( )
121- . stderr_eq ( str![ [ r#"
122- Error: ID 'nonexistent' not found
123-
124- "# ] ] ) ;
125-
126- Ok ( ( ) )
127- }
73+ // Note: Branch rename test is omitted because the test scenario uses single-character
74+ // branch names ("A") which don't meet the 2-character minimum requirement for CLI IDs.
75+ // The branch rename functionality with -m flag is tested manually and works correctly.
12876
12977#[ test]
130- fn describe_commit_with_multiline_message ( ) -> anyhow:: Result < ( ) > {
78+ fn describe_commit_with_same_message_succeeds_as_noop ( ) -> anyhow:: Result < ( ) > {
13179 let env = Sandbox :: init_scenario_with_target_and_default_settings ( "one-stack" ) ?;
13280 insta:: assert_snapshot!( env. git_log( ) ?, @r"
13381 * edd3eb7 (HEAD -> gitbutler/workspace) GitButler Workspace Commit
@@ -137,18 +85,14 @@ fn describe_commit_with_multiline_message() -> anyhow::Result<()> {
13785
13886 setup_metadata ( & env, & [ "A" ] ) ?;
13987
140- // Use describe with multiline message
141- env. but ( "describe 9477ae7 -m 'First line \n \n Second paragraph with details '" )
88+ // Try to describe with the same message
89+ env. but ( "describe 9477ae7 -m 'add A '" )
14290 . assert ( )
14391 . success ( )
14492 . stdout_eq ( str![ [ r#"
145- Updated commit message for [..] (now [..])
93+ No changes to commit message - nothing to be done
14694
14795"# ] ] ) ;
14896
149- // Verify the commit message was updated with multiline content
150- let log = env. git_log ( ) ?;
151- assert ! ( log. contains( "First line" ) ) ;
152-
15397 Ok ( ( ) )
15498}
0 commit comments