File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -287,15 +287,14 @@ pub fn update_branch_name_with_perm(
287287 branch_name : String ,
288288 new_name : String ,
289289 perm : & mut RepoExclusive ,
290- ) -> Result < ( ) > {
290+ ) -> Result < String > {
291291 gitbutler_branch_actions:: stack:: update_branch_name_with_perm (
292292 ctx,
293293 stack_id,
294294 branch_name,
295295 new_name,
296296 perm,
297- ) ?;
298- Ok ( ( ) )
297+ )
299298}
300299
301300#[ but_api]
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ use bstr::{BString, ByteSlice};
33use but_api:: diff:: ComputeLineStats ;
44use but_core:: sync:: RepoExclusive ;
55use but_ctx:: Context ;
6+ use colored:: Colorize ;
67use gix:: prelude:: ObjectIdExt ;
78
89use super :: {
@@ -95,15 +96,23 @@ fn edit_branch_name(
9596 if let Some ( sid) = stack_entry. id {
9697 let new_name = prepare_provided_message ( message, "branch name" )
9798 . unwrap_or_else ( || get_branch_name_from_editor ( branch_name) ) ?;
98- but_api:: legacy:: stack:: update_branch_name_with_perm (
99+ let normalized_name = but_api:: legacy:: stack:: update_branch_name_with_perm (
99100 ctx,
100101 sid,
101102 branch_name. to_owned ( ) ,
102103 new_name. clone ( ) ,
103104 perm,
104105 ) ?;
105106 if let Some ( out) = out. for_human ( ) {
106- writeln ! ( out, "Renamed branch '{branch_name}' to '{new_name}'" ) ?;
107+ if normalized_name != new_name {
108+ writeln ! (
109+ out,
110+ "New branch name normalized: {} -> {}" ,
111+ new_name. dimmed( ) ,
112+ normalized_name. yellow( )
113+ ) ?;
114+ }
115+ writeln ! ( out, "Renamed branch '{branch_name}' to '{normalized_name}'" ) ?;
107116 }
108117 return Ok ( ( ) ) ;
109118 }
Original file line number Diff line number Diff line change @@ -100,6 +100,40 @@ Renamed branch 'branch-to-rename-123' to 'renamed-branch'
100100 Ok ( ( ) )
101101}
102102
103+ #[ test]
104+ fn reword_branch_normalizes_name ( ) -> anyhow:: Result < ( ) > {
105+ let env = Sandbox :: init_scenario_with_target_and_default_settings ( "one-stack" ) ?;
106+
107+ env. setup_metadata ( & [ "A" ] ) ?;
108+ env. but ( "branch new branch-to-rename" ) . assert ( ) . success ( ) ;
109+
110+ env. file (
111+ "editor.sh" ,
112+ "#!/usr/bin/env bash\n printf 'renamed-branch\\ n\\ n' > \" $1\" \n " ,
113+ ) ;
114+ env. but ( "reword branch-to-rename -m trailing-hyphen-stripped-" )
115+ . assert ( )
116+ . success ( )
117+ . stdout_eq ( str![ [ r#"
118+ New branch name normalized: trailing-hyphen-stripped- -> trailing-hyphen-stripped
119+ Renamed branch 'branch-to-rename' to 'trailing-hyphen-stripped'
120+
121+ "# ] ] ) ;
122+
123+ env. but ( "show trailing-hyphen-stripped" )
124+ . assert ( )
125+ . success ( )
126+ . stderr_eq ( str ![ ] )
127+ . stdout_eq ( str![ [ r#"
128+ Branch: trailing-hyphen-stripped
129+
130+ No commits on this branch.
131+
132+ "# ] ] ) ;
133+
134+ Ok ( ( ) )
135+ }
136+
103137#[ test]
104138fn reword_commit_with_same_message_succeeds_as_noop ( ) -> anyhow:: Result < ( ) > {
105139 let env = Sandbox :: init_scenario_with_target_and_default_settings ( "one-stack" ) ?;
You can’t perform that action at this time.
0 commit comments