@@ -2868,20 +2868,19 @@ impl GitPanel {
28682868 if ops. staged ( ) {
28692869 self . single_staged_entry = single_staged_entry;
28702870 }
2871+ } else {
2872+ self . single_staged_entry = single_staged_entry;
28712873 }
2872- } else if repo. pending_ops_summary ( ) . item_summary . staging_count == 1 {
2873- self . single_staged_entry = repo. pending_ops ( ) . find_map ( |ops| {
2874- if ops. staging ( ) {
2875- repo. status_for_path ( & ops. repo_path )
2876- . map ( |status| GitStatusEntry {
2877- repo_path : ops. repo_path . clone ( ) ,
2878- status : status. status ,
2879- staging : StageStatus :: Staged ,
2880- } )
2881- } else {
2882- None
2883- }
2884- } ) ;
2874+ } else if repo. pending_ops_summary ( ) . item_summary . staging_count == 1
2875+ && let Some ( ops) = repo. pending_ops ( ) . find ( |ops| ops. staging ( ) )
2876+ {
2877+ self . single_staged_entry =
2878+ repo. status_for_path ( & ops. repo_path )
2879+ . map ( |status| GitStatusEntry {
2880+ repo_path : ops. repo_path . clone ( ) ,
2881+ status : status. status ,
2882+ staging : StageStatus :: Staged ,
2883+ } ) ;
28852884 }
28862885 }
28872886
@@ -5942,4 +5941,197 @@ mod tests {
59425941 " } ;
59435942 assert_eq ! ( result, expected) ;
59445943 }
5944+
5945+ #[ gpui:: test]
5946+ async fn test_suggest_commit_message ( cx : & mut TestAppContext ) {
5947+ init_test ( cx) ;
5948+
5949+ let fs = FakeFs :: new ( cx. background_executor . clone ( ) ) ;
5950+ fs. insert_tree (
5951+ path ! ( "/project" ) ,
5952+ json ! ( {
5953+ ".git" : { } ,
5954+ "tracked" : "tracked\n " ,
5955+ "untracked" : "\n " ,
5956+ } ) ,
5957+ )
5958+ . await ;
5959+
5960+ fs. set_head_and_index_for_repo (
5961+ path ! ( "/project/.git" ) . as_ref ( ) ,
5962+ & [ ( "tracked" , "old tracked\n " . into ( ) ) ] ,
5963+ ) ;
5964+
5965+ let project = Project :: test ( fs. clone ( ) , [ Path :: new ( path ! ( "/project" ) ) ] , cx) . await ;
5966+ let workspace =
5967+ cx. add_window ( |window, cx| Workspace :: test_new ( project. clone ( ) , window, cx) ) ;
5968+ let cx = & mut VisualTestContext :: from_window ( * workspace, cx) ;
5969+ let panel = workspace. update ( cx, GitPanel :: new) . unwrap ( ) ;
5970+
5971+ let handle = cx. update_window_entity ( & panel, |panel, _, _| {
5972+ std:: mem:: replace ( & mut panel. update_visible_entries_task , Task :: ready ( ( ) ) )
5973+ } ) ;
5974+ cx. executor ( ) . advance_clock ( 2 * UPDATE_DEBOUNCE ) ;
5975+ handle. await ;
5976+
5977+ let entries = panel. read_with ( cx, |panel, _| panel. entries . clone ( ) ) ;
5978+
5979+ // GitPanel
5980+ // - Tracked:
5981+ // - [] tracked
5982+ // - Untracked
5983+ // - [] untracked
5984+ //
5985+ // The commit message should now read:
5986+ // "Update tracked"
5987+ let message = panel. update ( cx, |panel, cx| panel. suggest_commit_message ( cx) ) ;
5988+ assert_eq ! ( message, Some ( "Update tracked" . to_string( ) ) ) ;
5989+
5990+ let first_status_entry = entries[ 1 ] . clone ( ) ;
5991+ panel. update_in ( cx, |panel, window, cx| {
5992+ panel. toggle_staged_for_entry ( & first_status_entry, window, cx) ;
5993+ } ) ;
5994+
5995+ cx. read ( |cx| {
5996+ project
5997+ . read ( cx)
5998+ . worktrees ( cx)
5999+ . next ( )
6000+ . unwrap ( )
6001+ . read ( cx)
6002+ . as_local ( )
6003+ . unwrap ( )
6004+ . scan_complete ( )
6005+ } )
6006+ . await ;
6007+
6008+ cx. executor ( ) . run_until_parked ( ) ;
6009+
6010+ let handle = cx. update_window_entity ( & panel, |panel, _, _| {
6011+ std:: mem:: replace ( & mut panel. update_visible_entries_task , Task :: ready ( ( ) ) )
6012+ } ) ;
6013+ cx. executor ( ) . advance_clock ( 2 * UPDATE_DEBOUNCE ) ;
6014+ handle. await ;
6015+
6016+ // GitPanel
6017+ // - Tracked:
6018+ // - [x] tracked
6019+ // - Untracked
6020+ // - [] untracked
6021+ //
6022+ // The commit message should still read:
6023+ // "Update tracked"
6024+ let message = panel. update ( cx, |panel, cx| panel. suggest_commit_message ( cx) ) ;
6025+ assert_eq ! ( message, Some ( "Update tracked" . to_string( ) ) ) ;
6026+
6027+ let second_status_entry = entries[ 3 ] . clone ( ) ;
6028+ panel. update_in ( cx, |panel, window, cx| {
6029+ panel. toggle_staged_for_entry ( & second_status_entry, window, cx) ;
6030+ } ) ;
6031+
6032+ cx. read ( |cx| {
6033+ project
6034+ . read ( cx)
6035+ . worktrees ( cx)
6036+ . next ( )
6037+ . unwrap ( )
6038+ . read ( cx)
6039+ . as_local ( )
6040+ . unwrap ( )
6041+ . scan_complete ( )
6042+ } )
6043+ . await ;
6044+
6045+ cx. executor ( ) . run_until_parked ( ) ;
6046+
6047+ let handle = cx. update_window_entity ( & panel, |panel, _, _| {
6048+ std:: mem:: replace ( & mut panel. update_visible_entries_task , Task :: ready ( ( ) ) )
6049+ } ) ;
6050+ cx. executor ( ) . advance_clock ( 2 * UPDATE_DEBOUNCE ) ;
6051+ handle. await ;
6052+
6053+ // GitPanel
6054+ // - Tracked:
6055+ // - [x] tracked
6056+ // - Untracked
6057+ // - [x] untracked
6058+ //
6059+ // The commit message should now read:
6060+ // "Enter commit message"
6061+ // (which means we should see None returned).
6062+ let message = panel. update ( cx, |panel, cx| panel. suggest_commit_message ( cx) ) ;
6063+ assert ! ( message. is_none( ) ) ;
6064+
6065+ panel. update_in ( cx, |panel, window, cx| {
6066+ panel. toggle_staged_for_entry ( & first_status_entry, window, cx) ;
6067+ } ) ;
6068+
6069+ cx. read ( |cx| {
6070+ project
6071+ . read ( cx)
6072+ . worktrees ( cx)
6073+ . next ( )
6074+ . unwrap ( )
6075+ . read ( cx)
6076+ . as_local ( )
6077+ . unwrap ( )
6078+ . scan_complete ( )
6079+ } )
6080+ . await ;
6081+
6082+ cx. executor ( ) . run_until_parked ( ) ;
6083+
6084+ let handle = cx. update_window_entity ( & panel, |panel, _, _| {
6085+ std:: mem:: replace ( & mut panel. update_visible_entries_task , Task :: ready ( ( ) ) )
6086+ } ) ;
6087+ cx. executor ( ) . advance_clock ( 2 * UPDATE_DEBOUNCE ) ;
6088+ handle. await ;
6089+
6090+ // GitPanel
6091+ // - Tracked:
6092+ // - [] tracked
6093+ // - Untracked
6094+ // - [x] untracked
6095+ //
6096+ // The commit message should now read:
6097+ // "Update untracked"
6098+ let message = panel. update ( cx, |panel, cx| panel. suggest_commit_message ( cx) ) ;
6099+ assert_eq ! ( message, Some ( "Create untracked" . to_string( ) ) ) ;
6100+
6101+ panel. update_in ( cx, |panel, window, cx| {
6102+ panel. toggle_staged_for_entry ( & second_status_entry, window, cx) ;
6103+ } ) ;
6104+
6105+ cx. read ( |cx| {
6106+ project
6107+ . read ( cx)
6108+ . worktrees ( cx)
6109+ . next ( )
6110+ . unwrap ( )
6111+ . read ( cx)
6112+ . as_local ( )
6113+ . unwrap ( )
6114+ . scan_complete ( )
6115+ } )
6116+ . await ;
6117+
6118+ cx. executor ( ) . run_until_parked ( ) ;
6119+
6120+ let handle = cx. update_window_entity ( & panel, |panel, _, _| {
6121+ std:: mem:: replace ( & mut panel. update_visible_entries_task , Task :: ready ( ( ) ) )
6122+ } ) ;
6123+ cx. executor ( ) . advance_clock ( 2 * UPDATE_DEBOUNCE ) ;
6124+ handle. await ;
6125+
6126+ // GitPanel
6127+ // - Tracked:
6128+ // - [] tracked
6129+ // - Untracked
6130+ // - [] untracked
6131+ //
6132+ // The commit message should now read:
6133+ // "Update tracked"
6134+ let message = panel. update ( cx, |panel, cx| panel. suggest_commit_message ( cx) ) ;
6135+ assert_eq ! ( message, Some ( "Update tracked" . to_string( ) ) ) ;
6136+ }
59456137}
0 commit comments