KiCad PCB EDA Suite
Loading...
Searching...
No Matches
git_advanced_dialog.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 3
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
21
22#include <bitmap_store.h>
23#include <bitmaps.h>
34
35#include <memory>
36
37#include <wx/bitmap.h>
38#include <wx/bmpbndl.h>
39#include <wx/filename.h>
40#include <wx/panel.h>
41#include <wx/sizer.h>
42#include <wx/splitter.h>
43#include <wx/treectrl.h>
44
45#include <confirm.h>
46#include <eda_base_frame.h>
50#include <kiplatform/ui.h>
51#include <kiway.h>
52#include <pgm_base.h>
53#include <project.h>
56#include <thread>
57#include <utility>
59#include <widgets/ui_common.h>
60#include <widgets/wx_treebook.h>
61
62
64{
65 for( wxWindow* child : aWindow->GetChildren() )
66 {
67 if( dynamic_cast<wxTextEntry*>( child ) )
68 OptOut( child );
69
71 }
72}
73
74
76 DIALOG_GIT_ADVANCED_BASE( aParent ),
77 m_parent( aParent ),
78 m_pane( aPane ),
79 m_historyPage( nullptr ),
80 m_branchesPage( nullptr ),
81 m_remotesPage( nullptr ),
82 m_stashesPage( nullptr ),
83 m_tagsPage( nullptr ),
84 m_repositoryPage( nullptr ),
85 m_changesSplitter( nullptr ),
86 m_changesPane( nullptr ),
87 m_workingDiff( nullptr )
88{
89 m_hash_key = "GitAdvancedDialog";
90
91 m_book->SetFont( KIUI::GetControlFont( this ) );
92
93 m_repoName->SetFont( KIUI::GetControlFont( this ).Bold() );
94
95 // The window's minimum must fit every page, not only the one open when it is built
96 m_book->SetFitToCurrentPage( false );
97
98 setIcons();
99
100 m_book->AddPage( buildChangesPage( m_book ), _( "Changes" ), true, 0 );
102 m_book->AddPage( m_historyPage, _( "History" ), false, 1 );
103
105 m_book->AddPage( m_branchesPage, _( "Branches" ), false, 2 );
106
108 m_book->AddPage( m_remotesPage, _( "Remotes" ), false, 3 );
109
111 m_book->AddPage( m_stashesPage, _( "Stashes" ), false, 4 );
112
114 m_book->AddPage( m_tagsPage, _( "Tags" ), false, 5 );
115
117 m_book->AddPage( m_repositoryPage, _( "Repository" ), false, 6 );
118
119 // Pull and Push run through the docked panel, which owns the merge and its conflict handling.
120 m_fetchButton->Bind( wxEVT_BUTTON,
121 [this]( wxCommandEvent& )
122 {
124 onFetch();
125 } );
126 // The choice is empty until the repository is read, so without a floor the top bar lays
127 // it out at the width of nothing and the branch name arrives too late to widen it.
128 m_branchChoice->SetMinSize( FromDIP( wxSize( 110, -1 ) ) );
130
131 m_pane->SetBusyChangedHandler(
132 [this]( bool aBusy )
133 {
134 m_pullButton->Enable( !aBusy );
135 m_pushButton->Enable( !aBusy );
136 } );
137
138 m_pullButton->Bind( wxEVT_BUTTON,
139 [this]( wxCommandEvent& )
140 {
141 m_pane->Pull();
142 } );
143 m_pushButton->Bind( wxEVT_BUTTON,
144 [this]( wxCommandEvent& )
145 {
146 m_pane->Push();
147 } );
148
149 m_branchChoice->Bind( wxEVT_CHOICE,
150 [this]( wxCommandEvent& )
151 {
152 SwitchToBranch( m_branchChoice->GetStringSelection() );
153
154 // A refused switch leaves the choice on a branch the tree is not
155 // on, so put it back on the real one.
156 ReloadPages();
157 } );
158
159 SetupStandardButtons( { { wxID_CANCEL, _( "Close" ) } } );
160
161 // Every box here is filled from the repository. DIALOG_SHIM would otherwise put back the
162 // text a previous session left, keyed by where the control sits in the window, so a value
163 // saved from one page reappears in whichever page now has a box in the same place.
165
166 // The sidebar tree does not invalidate its best size when pages are added, so lay it
167 // out and pin its width, matching how PAGED_DIALOG builds its navigation.
168 m_book->GetTreeCtrl()->InvalidateBestSize();
169
170 for( size_t i = 0; i < m_book->GetPageCount(); ++i )
171 m_book->GetPage( i )->Layout();
172
173 m_book->Layout();
174 m_book->Fit();
175
176 wxSize treeSize = m_book->GetTreeCtrl()->GetSize();
177 treeSize.x += 20;
178 m_book->GetTreeCtrl()->SetMinSize( treeSize );
179
180 // A page is a bare list whose natural size is a few rows, so without a floor the first
181 // open is a stamp. A saved size still wins once there is one. The fitted size keeps the
182 // widest page's right-hand controls inside the window.
183 wxSize bookMin = FromDIP( wxSize( 800, 600 ) );
184 m_book->InvalidateBestSize();
185 bookMin.IncTo( m_book->GetBestSize() );
186 m_book->SetMinSize( bookMin );
187 m_book->Layout();
188
189 Bind(
190 wxEVT_BUTTON,
191 [this]( wxCommandEvent& )
192 {
193 Close();
194 },
195 wxID_CANCEL );
196
197 ReloadPages();
198
199 // A commit, push or pull from any surface broadcasts a change, so the window never goes stale.
200 syncListener();
201
202 Bind( wxEVT_SYS_COLOUR_CHANGED,
203 [this]( wxSysColourChangedEvent& aEvent )
204 {
205 setIcons();
206 aEvent.Skip();
207 } );
208
210}
211
212
213// One window per process. KiCad has one project open at a time and every frame shares it.
218
219
221{
223}
224
225
230
231
233 std::optional<GIT_ADVANCED_PAGE> aPage )
234{
235 if( !activeDialog() )
236 {
237 GIT_ADVANCED_DIALOG* dialog = new GIT_ADVANCED_DIALOG( aParent, aPane );
238
239 dialog->Bind( wxEVT_CLOSE_WINDOW,
240 [dialog]( wxCloseEvent& )
241 {
242 if( activeDialog() == dialog )
243 setActiveDialog( nullptr );
244
245 // Hiding through DIALOG_SHIM records the size for the next open. This
246 // handler takes the close event, so the base class's own save never
247 // runs.
248 dialog->Show( false );
249 dialog->Destroy();
250 } );
251
252 setActiveDialog( dialog );
253 }
254
255 if( aPage )
256 activeDialog()->selectPage( *aPage );
257
258 activeDialog()->Show( true );
259 activeDialog()->Raise();
260}
261
262
264{
265 // Destroy() only schedules the delete, so the pointer is dropped here. Reopening before the
266 // event loop gets round to it then builds a new window instead of raising a dying one.
267 if( GIT_ADVANCED_DIALOG* dialog = activeDialog() )
268 {
269 setActiveDialog( nullptr );
270 dialog->Destroy();
271 }
272}
273
274
276{
277 if( activeDialog() && activeDialog()->m_pane == aPane )
278 {
279 aPane->SetBusyChangedHandler( nullptr );
280 aPane->SetMessageChangedHandler( nullptr );
281 activeDialog()->m_pane = nullptr;
282 CloseActive();
283 }
284}
285
286
288{
289 m_reloadQuery.Cancel();
290 m_actionQuery.Cancel();
291 m_fetchQuery.Cancel();
292
293 // The panel usually outlives this window, so it must not be left calling into it. When the
294 // panel went first it cleared this and dropped the pointer.
296
297 // A replacement opened before this deferred delete already owns the panel's handlers
298 if( m_pane && ( !current || current == this || current->m_pane.get() != m_pane.get() ) )
299 {
300 m_pane->SetBusyChangedHandler( nullptr );
301 m_pane->SetMessageChangedHandler( nullptr );
302 }
303
304 // A transfer's completion finds this window gone, so release its holds before the panels'
305 // Cancel can reach it
306 m_fetchBusy.Release();
307
308 if( activeDialog() == this )
309 setActiveDialog( nullptr );
310
311 // A push or fetch outlives this window, and its completion refreshes the other windows, so
312 // nothing has to be reported here. The transfers stop themselves as they go.
313 m_branchesPage->StopTransfer();
314
315 if( std::shared_ptr<KIGIT_COMMON> session = m_listenerSession.lock() )
316 session->RemoveRefreshListener( this );
317}
318
319
321{
322 std::shared_ptr<KIGIT_COMMON> common = m_parent->Prj().GetGitCommon();
323
325 {
326 // Pending reads belong to the original session just as much as the displayed rows do.
327 // Never rebind this window and accept an old result into a new project's controls.
328 if( m_listenerSession.lock() != common )
330
331 return;
332 }
333
334 common->AddRefreshListener( this,
335 [this]()
336 {
337 ReloadPages();
338 } );
339 m_listenerSession = common;
340 m_listenerAttached = true;
341}
342
343
344void GIT_ADVANCED_DIALOG::ShowTransferProgress( const wxString& aText )
345{
346 if( m_changesPane )
347 m_changesPane->ShowTransferProgress( aText );
348 else if( m_pane )
349 m_pane->ShowTransferProgress( aText );
350}
351
352
354{
355 syncListener();
356
357 if( !SessionStillCurrent() )
358 return;
359
361 m_historyPage->Populate();
362 m_branchesPage->Populate();
363 m_remotesPage->Populate();
364 m_stashesPage->Populate();
365 m_tagsPage->Populate();
366 m_repositoryPage->Populate();
367}
368
369
370void GIT_ADVANCED_DIALOG::ShowHistoryForFile( EDA_BASE_FRAME* aParent, GIT_COMMIT_PANE* aPane, const wxString& aPath )
371{
372 ShowForFrame( aParent, aPane, GIT_ADVANCED_PAGE::HISTORY );
374}
375
376
377void GIT_ADVANCED_DIALOG::ShowHistoryForFile( const wxString& aPath )
378{
380 m_historyPage->ShowHistoryForFile( aPath );
381}
382
383
384void GIT_ADVANCED_DIALOG::ShowAmend( const wxString& aCommitHash )
385{
386 if( !SessionStillCurrent() )
387 return;
388
390 m_changesPane->BeginAmend( aCommitHash );
391}
392
393
395{
396 // One icon per page, in page order, as the About dialog does for its tabs.
397 wxVector<wxBitmapBundle> pageIcons;
398 pageIcons.push_back( KiBitmapBundleDef( BITMAPS::git_changes, 16 ) );
399 pageIcons.push_back( KiBitmapBundleDef( BITMAPS::git_history, 16 ) );
400 pageIcons.push_back( KiBitmapBundleDef( BITMAPS::git_branches, 16 ) );
401 pageIcons.push_back( KiBitmapBundleDef( BITMAPS::git_remotes, 16 ) );
402 pageIcons.push_back( KiBitmapBundleDef( BITMAPS::git_stashes, 16 ) );
403 pageIcons.push_back( KiBitmapBundleDef( BITMAPS::git_tags, 16 ) );
404 pageIcons.push_back( KiBitmapBundleDef( BITMAPS::git_repository, 16 ) );
405 m_book->SetImages( pageIcons );
406
410}
411
412
414{
415 m_book->SetSelection( static_cast<size_t>( aPage ) );
416}
417
418
419wxWindow* GIT_ADVANCED_DIALOG::buildChangesPage( wxWindow* aBook )
420{
421 wxPanel* panel = new wxPanel( aBook );
422 wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
423
424 // The commit controls above, and once a file is picked, its changes below.
425 m_changesSplitter = new wxSplitterWindow( panel, wxID_ANY, wxDefaultPosition, wxDefaultSize,
426 wxSP_LIVE_UPDATE | wxSP_3DSASH );
427 m_changesSplitter->SetMinimumPaneSize( panel->FromDIP( 120 ) );
428 m_changesSplitter->SetSashGravity( 0.5 );
429 m_changesSashPos = panel->FromDIP( 260 );
430
433
434 m_changesSplitter->Initialize( m_changesPane );
435 m_workingDiff->Hide();
436
437 sizer->Add( m_changesSplitter, 1, wxEXPAND | wxALL, 4 );
438 panel->SetSizer( sizer );
439
440 // The docked panel and this page are two forms on one project, so the message starts from
441 // what the panel already holds and goes back to it as the user types. This window closes
442 // with the panel, so the panel is always there to write to.
443 if( m_pane )
444 {
445 m_changesPane->SetCommitMessage( m_pane->GetCommitMessage() );
446
447 m_changesPane->SetMessageChangedHandler(
448 [this]()
449 {
450 m_pane->SetCommitMessage( m_changesPane->GetCommitMessage() );
451 } );
452
453 // SetCommitMessage writes with ChangeValue, so neither form echoes back into the other.
454 m_pane->SetMessageChangedHandler(
455 [this]()
456 {
457 m_changesPane->SetCommitMessage( m_pane->GetCommitMessage() );
458 } );
459 }
460
461 m_changesPane->SetFileSelectedHandler(
462 [this]( const wxString& aPath )
463 {
464 showWorkingDiff( aPath );
465 } );
466
467 return panel;
468}
469
470
476
477
478void GIT_ADVANCED_DIALOG::showWorkingDiff( const wxString& aPath )
479{
480 if( aPath.IsEmpty() || !m_parent->Prj().GetGitCommon()->GetRepo() )
481 {
483 return;
484 }
485
486 // The top bar already names the branch the working tree is on.
487 wxString branch = m_branchChoice->GetStringSelection();
488 wxString baseLabel = branch.IsEmpty() ? _( "BASE (HEAD)" ) : wxString::Format( _( "BASE (%s)" ), branch );
489
490 m_workingDiff->ShowFile(
491 m_parent->Prj().GetGitCommon(),
492 [path = aPath]( KIGIT_COMMON& aCommon, GIT_DIFF_WORKSPACE& aWorkspace, GIT_FILE_SIDES& aSides )
493 {
494 return MaterializeWorkingFile( aCommon, aWorkspace, path, aSides );
495 },
496 baseLabel, _( "WORKING (changes)" ) );
497
498 if( !m_changesSplitter->IsSplit() )
500}
501
502
503void GIT_ADVANCED_DIALOG::SwitchToBranch( const wxString& aBranch )
504{
505 if( !SessionStillCurrent() )
506 return;
507
509}
510
511
513{
514 struct RESULT
515 {
516 wxString current;
517 wxString root;
518 std::vector<KIGIT_BRANCH_INFO> branches;
519 };
520
521 std::shared_ptr<KIGIT_COMMON> common = m_parent->Prj().GetGitCommon();
522 auto result = std::make_shared<RESULT>();
523
524 m_reloadQuery.Run(
525 common,
526 [result]( KIGIT_COMMON& aCommon )
527 {
528 result->current = aCommon.GetCurrentBranchName();
529 result->root = aCommon.GetGitRootDirectory();
530 result->branches = aCommon.GetBranches();
532 },
533 [this, common, result]()
534 {
535 if( common != m_parent->Prj().GetGitCommon() || common->IsShuttingDown() )
536 return;
537
538 wxFileName root = wxFileName::DirName( result->root );
539 m_repoName->SetLabel( root.GetDirs().empty() ? root.GetFullPath() : root.GetDirs().Last() );
540 m_branchChoice->Clear();
541
542 // Only a local branch can be checked out here. Remote ones are on the Branches page.
543 for( const KIGIT_BRANCH_INFO& branch : result->branches )
544 {
545 if( !branch.isRemote )
546 m_branchChoice->Append( branch.name );
547 }
548
549 m_branchChoice->SetStringSelection( result->current );
550 m_historyPage->SetBranches( result->branches );
551 m_branchChoice->InvalidateBestSize();
552 Layout();
553 } );
554}
555
556
557void GIT_ADVANCED_DIALOG::onFetch( bool aRetriedAfterTrust )
558{
559 if( !SessionStillCurrent() )
560 return;
561
562 if( m_fetch.IsBusy() || m_fetchQuery.IsBusy() || m_fetchPreflight )
563 {
565 return;
566 }
567
568 std::shared_ptr<KIGIT_COMMON> common = m_parent->Prj().GetGitCommon();
569 auto hasRemote = std::make_shared<bool>( false );
570
571 m_fetchButton->SetLabel( _( "Fetching..." ) );
572 m_fetchButton->Disable();
573 m_fetchBusy.Begin( common, _( "Fetching..." ),
574 [this]()
575 {
576 if( !abandonFetchPreflight() )
577 m_fetch.Cancel();
578 } );
579 Layout();
580
581 m_fetchPreflight = true;
583 m_fetchQuery.Run(
584 common,
585 [hasRemote]( KIGIT_COMMON& aCommon )
586 {
587 *hasRemote = aCommon.HasPushAndPullRemote();
588 },
589 [this, common, hasRemote, aRetriedAfterTrust]()
590 {
591 if( !SessionStillCurrent() )
592 return;
593
594 if( !*hasRemote )
595 {
597 Layout();
598 DisplayInfoMessage( this, _( "No remote is configured to get changes from." ) );
599 return;
600 }
601
602 startFetch( common, aRetriedAfterTrust );
603 } );
604}
605
606
608{
609 if( !std::exchange( m_fetchPreflight, false ) )
610 return false;
611
612 // The cancelled check never completes, so its reset of the button and the panes happens here
613 m_fetchQuery.Cancel();
614 endFetch( wxEmptyString );
615 return true;
616}
617
618
619void GIT_ADVANCED_DIALOG::endFetch( const wxString& aStatus )
620{
621 m_fetchButton->SetLabel( _( "Fetch" ) );
622 m_fetchButton->Enable();
623 m_fetchBusy.Release();
624 Layout();
625
626 // After the release, whose restore of the panels clears their status line
627 if( !aStatus.IsEmpty() )
628 ShowTransferProgress( aStatus );
629}
630
631
632void GIT_ADVANCED_DIALOG::startFetch( std::shared_ptr<KIGIT_COMMON> aCommon, bool aRetriedAfterTrust )
633{
634 // Read the keyring here, where an unlock prompt can show. The preflight stays open so Cancel still ends it
635 if( KIGIT_COMMON::DeferForSecret( aCommon, m_fetch.Alive(),
636 [this, aCommon, aRetriedAfterTrust, request = m_fetchRequest]()
637 {
638 // A fetch cancelled and started again meanwhile is another request
639 if( request == m_fetchRequest && m_fetchPreflight && SessionStillCurrent() )
640 startFetch( aCommon, aRetriedAfterTrust );
641 } ) )
642 {
643 return;
644 }
645
646 m_fetchPreflight = false;
647 m_fetchButton->SetLabel( _( "Fetching..." ) );
648 m_fetchButton->Disable();
649 Layout();
650
651 // Carried rather than captured by reference, because Start returns before the work runs.
652 struct OUTCOME
653 {
654 bool fetched = false;
655 wxString error;
656 wxString details;
657 bool authFailure = false;
658 bool cancelled = false;
659
660 std::optional<KIGIT::HOST_KEY_FAILURE> hostKey;
661 };
662
663 auto outcome = std::make_shared<OUTCOME>();
664
665 bool started = m_fetch.Start(
666 "git fetch",
667 [aCommon, outcome, alive = m_fetch.Alive(), dialog = this]( const KIGIT_COMMON::CANCEL_TOKEN& aToken )
668 {
669 GIT_PULL_HANDLER handler( aCommon.get() );
670 handler.SetProgressReporter( std::make_unique<KIGIT_STATUS_REPORTER>(
671 alive,
672 [dialog]( const wxString& aText )
673 {
674 dialog->ShowTransferProgress( aText );
675 } ) );
676 handler.SetCancelToken( aToken );
677 handler.SetWaitForActionLock( true );
678 outcome->fetched = handler.PerformFetch();
679 KIGIT_ERROR_MESSAGE error = handler.PopError();
680 outcome->error = error.summary;
681 outcome->details = error.details;
682 outcome->authFailure = handler.WasAuthFailure();
683 outcome->hostKey = handler.GetHostKeyFailure();
684
685 // This operation's own token, so a fetch that never became active cannot
686 // consume a cancel belonging to the transfer that is running.
687 outcome->cancelled = handler.IsThisOperationCancelled();
688
689 // The other surfaces need this even when the window that started it has gone.
690 if( outcome->fetched && !outcome->cancelled )
691 {
693 [aCommon]()
694 {
695 aCommon->NotifyRefreshListeners();
696 } );
697 }
698 },
699 [this, aCommon, outcome, aRetriedAfterTrust]()
700 {
701 if( !SessionStillCurrent() )
702 return;
703
704 if( outcome->fetched && !outcome->cancelled )
705 KIGIT::ClearSyncWarnings( aCommon.get() );
706
707 if( outcome->fetched || outcome->cancelled )
708 {
709 m_credentialPrompts = 0;
710 endFetch( outcome->fetched ? wxString() : wxString( _( "Cancelled." ) ) );
711 return;
712 }
713
715 failure.authFailure = outcome->authFailure;
716 failure.hostKey = outcome->hostKey;
717 failure.error = outcome->error;
718
719 // The Fetch button and the panels stay busy until the prompt is answered
720 switch( KIGIT::AnswerTransferFailure( this, m_fetch.Alive(), aCommon.get(), &m_parent->Prj(), failure,
721 aRetriedAfterTrust, m_credentialPrompts ) )
722 {
723 case KIGIT::TRANSFER_RETRY::RETRY: onFetch( aRetriedAfterTrust ); return;
724
725 case KIGIT::TRANSFER_RETRY::RETRY_TRUSTED: onFetch( true ); return;
726
727 // Declining a prompt is the user's answer, not an error
728 case KIGIT::TRANSFER_RETRY::CANCELLED: endFetch( _( "Cancelled." ) ); return;
729
730 case KIGIT::TRANSFER_RETRY::HOST_DECLINED: endFetch( wxEmptyString ); return;
731
732 case KIGIT::TRANSFER_RETRY::GONE: return;
733
735 }
736
737 endFetch( wxEmptyString );
738
739 wxString error = outcome->error;
740
741 if( error.IsEmpty() )
742 error = KIGIT::UnexplainedFailure( KIGIT_OPERATION::FETCH, aCommon->GetRemote() );
743
744 DisplayErrorMessage( this, error, outcome->details );
745 } );
746
747 if( !started )
748 {
749 endFetch( wxEmptyString );
750 DisplayInfoMessage( this, _( "Could not start the fetch." ) );
751 }
752}
753
754
755void GIT_ADVANCED_DIALOG::RefuseOverUncommittedWork( std::function<void( const GIT_WORKTREE_STATUS& )> aReady )
756{
757 if( !SessionStillCurrent() )
758 return;
759
761 [this, aReady]( const GIT_WORKTREE_STATUS& aStatus )
762 {
763 if( SessionStillCurrent() )
764 aReady( aStatus );
765 } );
766}
767
768
770{
771 if( !SessionStillCurrent() )
772 return false;
773
774 // Save rather than close: this window is parented to the frame hosting the panel, so a close
775 // would destroy that frame and this dialog with it, mid-call.
777 return false;
778
779 if( !SessionStillCurrent() )
780 return false;
781
783 return true;
784}
785
786
788{
789 if( !SessionStillCurrent() || !ProjectSafeToRewrite( m_parent, this, aStatus ) )
790 return false;
791
793 return true;
794}
795
796
798{
799 if( IsBeingDeleted() || m_parent->IsBeingDeleted() )
800 return false;
801
802 std::shared_ptr<KIGIT_COMMON> session = m_listenerSession.lock();
803
804 if( m_listenerAttached && session && !session->IsShuttingDown() && session == m_parent->Prj().GetGitCommon()
805 && Pgm().GetCommonSettings()->m_Git.enableGit && !m_parent->Prj().GetLocalSettings().m_GitIntegrationDisabled )
806 {
807 return true;
808 }
809
810 // A window and its pending reads belong to the session it opened with. Once it changes,
811 // close rather than act on identically named branches or files in another project.
812 m_reloadQuery.Cancel();
813 m_actionQuery.Cancel();
814 m_fetchQuery.Cancel();
815 Close();
816 return false;
817}
818
819
820void GIT_ADVANCED_DIALOG::RunGitAction( const std::function<bool( KIGIT_COMMON& )>& aFn, const wxString& aError,
821 bool aRewritesWorkingTree )
822{
824 [&aFn]( KIGIT_COMMON& aCommon, wxString& )
825 {
826 return aFn( aCommon );
827 },
828 aError, aRewritesWorkingTree );
829}
830
831
832void GIT_ADVANCED_DIALOG::RunGitAction( const std::function<bool( KIGIT_COMMON&, wxString& )>& aFn,
833 const wxString& aError, bool aRewritesWorkingTree )
834{
835 if( !SessionStillCurrent() )
836 return;
837
838 std::shared_ptr<KIGIT_COMMON> common = m_parent->Prj().GetGitCommon();
839 bool ok = false;
840 wxString detail;
841
842 {
843 // Release the lock before reloading editors and refreshing other Git views.
844 std::unique_lock<std::mutex> lock = KIGIT::WaitForActionLock( *common, this );
845
846 if( !lock.owns_lock() )
847 return;
848
849 ok = aFn( *common, detail );
850 }
851
852 if( !ok )
853 {
854 // A failed action can still have written files, so the editors and the panels are
855 // brought up to date first. Nothing reloads when nothing changed on disk.
856 if( aRewritesWorkingTree )
857 {
859 common->NotifyRefreshListeners();
860 }
861
862 DisplayErrorMessage( this, aError, detail.IsEmpty() ? KIGIT_COMMON::GetLastGitError() : detail );
863 return;
864 }
865
866 if( aRewritesWorkingTree )
867 {
868 // The files the editors have open were just rewritten, so pull them back in from disk.
870 }
871
872 common->NotifyRefreshListeners();
873}
874
875
wxBitmapBundle KiBitmapBundleDef(BITMAPS aBitmap, int aDefHeight)
Construct and return a bitmap bundle for the given icon ID, with the default bitmap size being aDefHe...
Definition bitmap.cpp:112
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:106
DIALOG_GIT_ADVANCED_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Advanced Git"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
bool Show(bool show) override
void OptOut(wxWindow *aWindow)
Opt out of control state saving.
void SetupStandardButtons(std::map< int, wxString > aLabels={})
std::string m_hash_key
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
The base frame for deriving all KiCad main window classes.
The advanced Git window: a non-modal dialog with a top bar naming the repository and branch and a sid...
EDA_BASE_FRAME * m_parent
bool abandonFetchPreflight()
Stop a pending remote check and release what the fetch holds. False when none is pending.
GIT_ADVANCED_DIALOG(EDA_BASE_FRAME *aParent, GIT_COMMIT_PANE *aPane)
int m_credentialPrompts
Keyring reads and credential prompts the current fetch has shown, reset when it ends.
static void ShowHistoryForFile(EDA_BASE_FRAME *aParent, GIT_COMMIT_PANE *aPane, const wxString &aPath)
Open the window on its History page, narrowed to the commits that changed aPath.
PANEL_GIT_BRANCHES * m_branchesPage
void RefuseOverUncommittedWork(std::function< void(const GIT_WORKTREE_STATUS &)> aReady)
Check the working tree and LFS on a worker, then continue on the UI thread only when nothing is uncom...
void ShowTransferProgress(const wxString &aText)
Show a line of transfer progress on the hosted commit panel's status line.
void showWorkingDiff(const wxString &aPath)
Show the working copy of aPath against its committed version, or hide that area.
GIT_FILE_DIFF_AREA * m_workingDiff
void SwitchToBranch(const wxString &aBranch)
Switch the working tree to the named branch, after confirming, then refresh.
static void CloseForPane(GIT_COMMIT_PANE *aPane)
Close the live window if the given pane opened it, for when that pane goes away.
PANEL_GIT_REPOSITORY * m_repositoryPage
PANEL_GIT_HISTORY * m_historyPage
PANEL_GIT_REMOTES * m_remotesPage
EDITOR_SNAPSHOT m_docsBeforeChange
On-disk identity of the open documents, taken by ConfirmWorkingTreeChange() so only the documents an ...
void selectPage(GIT_ADVANCED_PAGE aPage)
bool ConfirmWorkingTreeChange()
After the asynchronous LFS check, save the open editors and snapshot their documents before an action...
static void CloseActive()
Close the live window, for when the project it was filled from goes away.
wxSplitterWindow * m_changesSplitter
void endFetch(const wxString &aStatus)
Restore the Fetch button and release the fetch's hold, then show aStatus on the commit panel.
KIGIT_QUERY m_reloadQuery
Reads the top bar and history branch choices without holding up the UI.
std::weak_ptr< KIGIT_COMMON > m_listenerSession
static GIT_ADVANCED_DIALOG * Active()
The live window, or null when none is open.
void RunGitAction(const std::function< bool(KIGIT_COMMON &)> &aFn, const wxString &aError, bool aRewritesWorkingTree=false)
Run a repository write under the action lock, then refresh every surface on success.
PANEL_GIT_STASHES * m_stashesPage
void syncListener()
Attach once to the project's session.
bool m_fetchPreflight
The fetch is checking its remote, before its transfer starts, and holds the panes busy.
KIGIT_QUERY m_actionQuery
Preflight reads for actions that may replace the working tree.
bool SessionStillCurrent()
True while the frame's git session is still the one this window's lists were filled from.
GIT_TRANSFER_BUSY::HOLD m_fetchBusy
The top bar fetch's hold on its repository, from its remote check until it ends.
static void ShowForFrame(EDA_BASE_FRAME *aParent, GIT_COMMIT_PANE *aPane, std::optional< GIT_ADVANCED_PAGE > aPage=std::nullopt)
Raise the one window for this session, creating it on first use.
unsigned m_fetchRequest
Counts the fetches begun, so a keyring read finishing late starts only its own.
wxWindow * buildChangesPage(wxWindow *aBook)
The Changes page: the docked panel's commit controls with the selected file's diff below.
GIT_COMMIT_PANE * m_changesPane
int m_changesSashPos
Where the user left the sash between the Changes page's list and its diff area.
wxWeakRef< GIT_COMMIT_PANE > m_pane
Weak because the pane can be destroyed before this dialog's deferred delete runs.
void optOutOfTextPersistence(wxWindow *aWindow)
Keep every text box in aWindow out of the dialog's saved control state.
void setIcons()
The page and toolbar icons, again after a light or dark switch.
void onFetch(bool aRetriedAfterTrust=false)
Fetch from the remote on a worker, then refresh every surface.
void startFetch(std::shared_ptr< KIGIT_COMMON > aCommon, bool aRetriedAfterTrust)
void ShowAmend(const wxString &aCommitHash)
Open the Changes page to amend the selected history commit.
KIGIT_TRANSFER m_fetch
The fetch the top bar started.
PANEL_GIT_TAGS * m_tagsPage
void populateTopBar()
Fill the top bar's repository name and branch list.
Docked panel for committing: the branch to commit to, a summary and description, the commit options,...
void SetBusyChangedHandler(std::function< void(bool)> aHandler)
Called when a transfer starts and when it ends, so an owning window can follow along.
void SetMessageChangedHandler(std::function< void()> aHandler)
Called when the user edits the message, so another form can follow along.
A private scratch directory for extracting committed file versions to diff, removed when this object ...
Shows what changed in one file: the old and new drawing side by side for a schematic or board,...
The project's git session.
static bool DeferForSecret(const std::shared_ptr< KIGIT_COMMON > &aCommon, const std::weak_ptr< bool > &aOwner, std::function< void()> aRetry)
Read the remote's secret from the keyring on the UI thread without blocking it, so an unlock prompt c...
std::shared_ptr< std::atomic< bool > > CANCEL_TOKEN
One token per operation.
wxString GetCurrentBranchName() const
wxString GetGitRootDirectory() const
bool HasPushAndPullRemote() const
static wxString GetLastGitError()
libgit2's last message, without credentials from any URL it quotes, so it is safe to show or trace.
std::vector< KIGIT_BRANCH_INFO > GetBranches() const
Local and remote branches with their tip commits.
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
The advanced git window's Branches page: a searchable list beside the selected branch's detail,...
The advanced git window's History page: filters above a list of commits beside the selected commit's ...
The advanced git window's Remotes page: the list beside the selected remote's detail,...
Show the repository's author and open the shared identity editor.
The advanced git window's Stashes page: the list beside the selected stash's detail,...
The advanced git window's Tags page: the list beside the selected tag's detail, with the actions that...
virtual std::shared_ptr< KIGIT_COMMON > GetGitCommon() const
This project's Git session, created empty on first use.
Definition project.cpp:85
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition confirm.cpp:245
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition confirm.cpp:217
This file is part of the common library.
#define _(s)
Base window classes and related definitions.
static void setActiveDialog(GIT_ADVANCED_DIALOG *aDialog)
static GIT_ADVANCED_DIALOG * activeDialog()
GIT_ADVANCED_PAGE
The advanced window's pages, in the order its sidebar lists them.
bool PrepareEditorsForGitOperation(EDA_BASE_FRAME *aFrame, GIT_EDITOR_PREP aPurpose, bool *aSavedEditors)
Offer to save unsaved schematic and board edits before a git operation.
EDITOR_SNAPSHOT CaptureOpenEditorDocs(KIWAY &aKiway)
Record the on-disk identity of the open documents, before an operation that may rewrite them.
void ReloadOpenEditors(KIWAY &aKiway, const EDITOR_SNAPSHOT &aBefore)
Tell the open board and schematic editors to reload from disk.
void ProjectClearOfUncommittedWork(EDA_BASE_FRAME *aFrame, wxWindow *aParent, KIGIT_QUERY &aQuery, std::function< void(const GIT_WORKTREE_STATUS &)> aReady)
Check the working tree and Git LFS on a worker, then run aReady on the UI thread when the operation c...
bool ProjectSafeToRewrite(EDA_BASE_FRAME *aFrame, wxWindow *aParent, const GIT_WORKTREE_STATUS &aStatus, bool aAllowTrackedChanges)
Combine the repository snapshot with live editor state and explain any refusal.
void SwitchProjectToBranch(EDA_BASE_FRAME *aFrame, wxWindow *aParent, const wxString &aBranch, KIGIT_QUERY &aQuery, std::function< void()> aFinished)
Check the working tree on a worker, then confirm switching to aBranch and recheck unsaved editors.
@ WORKING_TREE
The working files are about to be rewritten, by a pull, branch switch or stash.
void ClearSyncWarnings(wxWindow *aWindow)
Clear the background fetch's warnings from the frame holding aWindow.
void SortBranchesForDisplay(std::vector< KIGIT_BRANCH_INFO > &aBranches)
Put the current branch first, then local and remote branches with the newest tips first.
std::unique_lock< std::mutex > WaitForActionLock(KIGIT_COMMON &aCommon, wxWindow *aParent)
TryLockAction that first waits a moment for a status read or fetch to let go.
void UnsplitKeepingSash(wxSplitterWindow *aSplitter, wxWindow *aPane, int &aSashPos)
Close a splitter's second pane, keeping the sash where the user left it for next time.
void ShowBusyMessage(wxWindow *aParent)
Show a busy message for a user action. UI thread only.
TRANSFER_RETRY AnswerTransferFailure(wxWindow *aParent, const std::weak_ptr< bool > &aAlive, KIGIT_COMMON *aCommon, PROJECT *aProject, const TRANSFER_FAILURE &aFailure, bool aRetriedAfterTrust, int &aPrompts)
Answer a failed transfer the way every window does.
APIEXPORT wxWindow *& ActiveAdvancedGitWindow()
The advanced git window, or null when none is open.
@ RETRY_TRUSTED
Run it again, now that the server's key is trusted.
@ GONE
The window closed during a prompt, so the caller must not touch it.
@ CANCELLED
Stop and say so, the user cancelled the transfer or a prompt.
@ RETRY
Run the transfer again.
@ HOST_DECLINED
Stop without a message, the user chose not to trust the server.
APIEXPORT wxString UnexplainedFailure(KIGIT_OPERATION aOperation, const wxString &aUrl)
The summary for an operation that failed without saying why, naming the server it was talking to.
void CallOnUi(std::function< void()> aFn)
Run aFn on the UI thread.
void EllipsizeChoiceBox(wxChoice *aChoice)
Configure a wxChoice control to ellipsize the shown text in the button with the ellipses placed at th...
Definition wxgtk/ui.cpp:436
KICOMMON_API wxFont GetControlFont(wxWindow *aWindow)
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
The two sides of one file, written out for a comparison.
Repository state used before an operation that requires a clean working tree.
Why a transfer to a remote failed.
std::optional< HOST_KEY_FAILURE > hostKey
The server's key is unknown or has changed.
bool authFailure
The remote refused every credential offered.
wxString error
Shown above the credential fields.
A summary the user can act on, with the raw text that explains it kept apart for the details.
std::string path
wxString result
Test unit parsing edge cases and error handling.
Functions to provide common constants and other functions to assist in making a consistent UI.