34#include <wx/aui/floatpane.h>
35#include <wx/aui/framemanager.h>
37#include <wx/dataview.h>
40#include <wx/filename.h>
41#include <wx/hyperlink.h>
44#include <wx/settings.h>
46#include <wx/statbox.h>
47#include <wx/stattext.h>
48#include <wx/textctrl.h>
50#include <wx/weakref.h>
52#include <wx/choicdlg.h>
92 ID_OPEN_ADVANCED = wxID_HIGHEST + 1,
102 std::pair<wxString, wxString> state;
103 git_reference* head =
nullptr;
105 if( git_reference_lookup( &head, aRepo,
"HEAD" ) == GIT_OK )
107 if(
const char* target = git_reference_symbolic_target( head ) )
108 state.first = wxString::FromUTF8( target );
110 git_reference_free( head );
115 if( git_reference_name_to_id( &oid, aRepo,
"HEAD" ) == GIT_OK )
116 state.second = wxString::FromUTF8( git_oid_tostr_s( &oid ) );
125 if( aExpectedHead.second.IsEmpty() || aExpectedHead !=
commitHead( aCommon.
GetRepo() ) )
126 return _(
"The branch or its last commit changed. Select the commit to amend again." );
129 return _(
"Switch to a branch before amending its last commit." );
132 return _(
"Finish or abandon the current Git operation before amending a commit." );
135 return _(
"Only an unpushed commit can be amended." );
137 return wxEmptyString;
152 aError = wxString::Format(
_(
"Could not start branch '%s'." ), aName );
162 aError = wxString::Format(
_(
"Could not create branch '%s'." ), aName );
171 aError = switchError.
summary.IsEmpty()
172 ? wxString::Format(
_(
"Could not switch to the new branch '%s'." ), aName )
189 if( aPrevious.IsEmpty() )
215 m_summary->SetHint(
_(
"Summarize your changes..." ) );
224 m_summaryCount->SetToolTip(
_(
"Git tools show up to 72 characters of the summary on one line." ) );
228 m_descriptionHint =
new wxStaticText(
this, wxID_ANY,
_(
"Extended Description (optional)" ) );
230 [
this]( wxMouseEvent& )
240 auto commitOnEnter = [
this]( wxKeyEvent& aEvent )
242 bool enter = aEvent.GetKeyCode() == WXK_RETURN || aEvent.GetKeyCode() == WXK_NUMPAD_ENTER;
244 if( enter && ( aEvent.CmdDown() || aEvent.ControlDown() ) )
246 if( aEvent.ShiftDown() )
264 m_summary->Bind( wxEVT_CHAR_HOOK, commitOnEnter );
274 [
this]( wxCommandEvent& )
283 [
this]( wxCommandEvent& )
287 m_showDiffButton->SetToolTip(
_(
"Show what changed in the selected file. Pick a file in the list first." ) );
289 [
this]( wxCommandEvent& )
297 m_checklist->SetToolTip(
_(
"Double click a file to see what changed in it. Right click for more." ) );
300 m_checklist->Bind( wxEVT_DATAVIEW_SELECTION_CHANGED,
301 [
this]( wxDataViewEvent& )
315 m_historyLink =
new wxHyperlinkCtrl(
this, wxID_ANY,
_(
"History..." ), wxEmptyString, wxDefaultPosition,
316 wxDefaultSize, wxHL_ALIGN_RIGHT | wxNO_BORDER );
317 m_historyLink->SetToolTip(
_(
"Show the commits made to this project" ) );
321 [
this]( wxHyperlinkEvent& )
325 GetSizer()->Add(
m_historyLink, 0, wxALIGN_RIGHT | wxLEFT | wxRIGHT | wxBOTTOM, 4 );
328 m_checklist->SetMinSize( FromDIP( wxSize( -1, 100 ) ) );
339 m_minDockWidth = GetSizer()->CalcMin().x + wxSystemSettings::GetMetric( wxSYS_VSCROLL_X,
this );
346 SetScrollRate( 0, FromDIP( 10 ) );
355 wxSizer* column = GetSizer();
362 column->SetMinSize( FromDIP( wxSize( 280, -1 ) ) );
368 wxStaticText* heading =
new wxStaticText(
this, wxID_ANY,
_(
"Commit Message" ) );
369 heading->SetFont( heading->GetFont().Bold() );
370 column->Insert( 0, heading, 0, wxLEFT | wxRIGHT | wxTOP, 8 );
372 wxStaticBoxSizer* summary =
new wxStaticBoxSizer( wxVERTICAL,
this,
_(
"Summary" ) );
373 wxWindow* box = summary->GetStaticBox();
375 m_summaryFiles =
new wxStaticText( box, wxID_ANY, wxEmptyString );
376 m_summaryAdded =
new wxStaticText( box, wxID_ANY, wxEmptyString );
379 wxBoxSizer* lines =
new wxBoxSizer( wxHORIZONTAL );
383 summary->Add( lines, 0, wxALL, 4 );
386 size_t afterOptions = column->GetItemCount();
388 for(
size_t ii = 0; ii < column->GetItemCount(); ++ii )
391 afterOptions = ii + 1;
394 column->Insert( afterOptions, summary, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 8 );
396 wxBoxSizer* files =
new wxBoxSizer( wxVERTICAL );
397 files->Add(
m_changesRow, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 8 );
399 files->Add(
m_trustRow, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 8 );
404 m_checklist->SetMinSize( FromDIP( wxSize( -1, 120 ) ) );
406 wxBoxSizer* row =
new wxBoxSizer( wxHORIZONTAL );
407 row->Add( files, 1, wxEXPAND );
408 row->Add( column, 0, wxEXPAND );
411 SetSizer( row,
false );
437 common->RemoveRefreshListener(
this );
443 std::shared_ptr<KIGIT_COMMON> common =
m_frame->Prj().GetGitCommon();
450 previous->RemoveRefreshListener(
this );
464 setBusy(
false, wxEmptyString );
478 common->AddRefreshListener(
this,
502 std::pair<wxString, wxString>
head;
518 if( !
Pgm().GetCommonSettings()->m_Git.enableGit )
525 std::shared_ptr<KIGIT_COMMON> common =
m_frame->Prj().GetGitCommon();
526 wxString projectPath =
m_frame->Prj().GetProjectPath();
529 auto status = std::make_shared<STATUS>();
530 status->attachError = common->GetAttachError();
531 status->attachTrustCommand = common->GetAttachTrustCommand();
535 [status, projectPath, dark, countLines](
KIGIT_COMMON& aCommon )
537 status->hasRepo =
true;
544 if( std::optional<KIGIT_UPSTREAM_STATUS> upstream = aCommon.
UpstreamStatus() )
546 status->hasLocalCommits = upstream->HasLocalCommits();
547 status->upstreamAhead = upstream->divergence.behind;
548 status->unpushed = upstream->divergence.ahead;
559 std::set<wxString> changed;
562 changed.insert( entry.
path );
567 [
this, common, status]()
569 if(
m_frame->Prj().GetGitCommon() == common && !common->IsShuttingDown()
570 &&
Pgm().GetCommonSettings()->m_Git.enableGit )
580 std::vector<FILE_CHECKLIST_ENTRY> entries = aStatus.
entries;
604 std::set<wxString> stillChecked;
607 stillChecked.insert(
path );
611 if( (
m_shownPaths.count( entry.path ) && !stillChecked.count( entry.path ) )
613 entry.checked =
false;
624 bool hasChanges = !entries.empty();
625 wxString trustCommand;
636 setStatusText( wxString::Format(
_(
"This project is in the middle of a %s that was started outside "
637 "KiCad or interrupted. Abandon it to go back to the last commit, "
638 "or finish it with the program that started it." ),
644 setStatusText(
_(
"This project is showing an old snapshot rather than a branch, so it cannot be "
645 "committed or pushed from here. In the Advanced Git window, choose Branches "
646 "and double click a branch to go back to it." ) );
649 else if( hasChanges )
655 if( !
Pgm().GetCommonSettings()->m_Git.enableGit )
656 setStatusText(
_(
"Version control is turned off in Preferences." ) );
663 setStatusText(
_(
"This project is not under version control. To set it up, right click "
664 "the project in the project manager and choose Version Control." ) );
666 setStatusText( wxString::Format( wxPLURAL(
"The tracked branch has %zu commit this project does not. "
667 "Get Changes brings it in.",
668 "The tracked branch has %zu commits this project does not. "
669 "Get Changes brings them in.",
673 setStatusText( wxString::Format( wxPLURAL(
"%zu commit is waiting to be pushed.",
677 setStatusText(
_(
"Committed changes are waiting to be pushed." ) );
697 dialog->ReloadPages();
715 setBusy(
false, wxEmptyString );
743 setStatusText(
_(
"Version control is turned off in Preferences." ) );
770 if( GetBestVirtualSize() != GetVirtualSize() )
776 const int height = GetSizer()->CalcMin().y;
792 bool done = GIT_COMMIT_PANE_BASE::Layout();
800 const int available = column == GetSizer() ? GetClientSize().GetWidth() : column->GetSize().GetWidth();
803 const int width = std::max( 40, available - 2 * column->GetItem(
m_emptyLabel )->GetBorder() );
814 return GIT_COMMIT_PANE_BASE::Layout();
820 wxAuiManager* manager = wxAuiManager::GetManager(
this );
825 wxAuiPaneInfo& pane = manager->GetPane(
this );
836 if( wxAuiFloatingFrame* floating = wxDynamicCast( pane.frame, wxAuiFloatingFrame ) )
838 wxAuiManager& inner = floating->GetAuiManager();
839 wxAuiPaneInfo& innerPane = inner.GetPane(
this );
841 if( innerPane.min_size != pane.min_size )
843 innerPane.MinSize( pane.min_size );
848 const wxSize minimum = floating->GetSizer()->GetMinSize();
849 const wxSize size = floating->GetClientSize();
851 floating->SetMinClientSize( minimum );
853 if( size.x < minimum.x || size.y < minimum.y )
854 floating->SetClientSize( wxSize( std::max( size.x, minimum.x ), std::max( size.y, minimum.y ) ) );
856 else if( changed && pane.IsShown() )
866 m_descriptionHint->SetForegroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
909 || !IsShownOnScreen() )
926 menu.Append( ID_OPEN_ADVANCED,
_(
"Open Advanced Git Window..." ) );
927 menu.Bind( wxEVT_MENU,
928 [
this]( wxCommandEvent& )
937 menu.Append( ID_SET_AUTHOR,
_(
"Set Author..." ) );
938 menu.Bind( wxEVT_MENU,
939 [
this]( wxCommandEvent& )
951 std::shared_ptr<KIGIT_COMMON> common =
m_frame->Prj().GetGitCommon();
952 auto identity = std::make_shared<KIGIT::GIT_IDENTITY>();
960 [
this, common, identity]()
964 _(
"Reading author..." ) );
997 default:
return _(
"git operation" );
1010 default:
return _(
"Abandon Operation" );
1053 m_pullButton->SetToolTip(
_(
"The tracked branch has commits this project does not have." ) );
1061 bool hasCheckedChanges = !
m_checklist->GetCheckedPaths().empty();
1064 bool hasMessage = !
m_summary->GetValue().Trim().IsEmpty();
1065 bool hasBranchName = !newBranch || !
m_newBranchName->GetValue().Trim().IsEmpty();
1071 wxString mainLabel =
_(
"Commit" );
1072 wxString menuLabel =
_(
"Commit and Push" );
1073 bool mainEnabled =
false;
1074 bool menuEnabled =
false;
1084 mainLabel =
_(
"Amend" );
1085 menuLabel =
_(
"Amend and Push" );
1090 blocked =
_(
"This commit can no longer be amended. Untick Amend to start a new commit." );
1091 else if( !hasMessage )
1092 blocked =
_(
"Write a summary to amend the last commit." );
1097 mainEnabled = hasMessage && hasBranchName;
1098 menuEnabled = hasMessage && hasBranchName;
1101 blocked =
_(
"Write a summary to commit." );
1102 else if( !hasBranchName )
1103 blocked =
_(
"Name the new branch, or untick Create a new branch." );
1110 mainLabel =
_(
"Push" );
1117 blocked =
_(
"Tick a file to commit it." );
1130 reason =
_(
"The open editors have unsaved changes. Committing offers to save them first." );
1136 if( !reason.IsEmpty() )
1137 reason += wxS(
"\n" );
1139 reason +=
_(
"This project has no remote, so there is nothing to get changes from or push to. "
1140 "Add one from the Remotes page of the Advanced Git window." );
1143 if( !blocked.IsEmpty() )
1145 if( !reason.IsEmpty() )
1146 reason += wxS(
"\n" );
1151 if( !reason.IsEmpty() )
1155 bool showReason = !reason.IsEmpty() ||
m_shownPaths.empty();
1171 int left = 72 -
static_cast<int>(
m_summary->GetValue().length() );
1204 wxString description;
1229 if( !
path.IsEmpty() )
1253 if( shown.IsEmpty() )
1271 wxString line =
message.BeforeFirst(
'\n' );
1273 if( line.length() > 40 )
1274 line = line.Left( 37 ) + wxS(
"..." );
1286 wxString summary, description;
1302 wxPoint at =
m_description->GetPosition() + wxPoint( FromDIP( 6 ), FromDIP( 4 ) );
1329 int staged =
static_cast<int>(
m_checklist->GetCheckedPaths().size() );
1330 int unstaged =
static_cast<int>(
m_shownPaths.size() ) - staged;
1332 m_changesLabel->SetLabel( wxString::Format(
_(
"Changes to Commit (%d of %d)" ), staged,
1338 wxString stagedText = wxString::Format(
1339 wxPLURAL(
"%d file will be committed",
"%d files will be committed", staged ), staged );
1340 wxString unstagedText = wxString::Format( wxPLURAL(
"%d left out",
"%d left out", unstaged ), unstaged );
1342 m_summaryFiles->SetLabel( wxString::Format( wxS(
"%s, %s" ), stagedText, unstagedText ) );
1358 if(
path.IsEmpty() )
1365 bool canIgnore =
false;
1368 std::shared_ptr<KIGIT_COMMON> common =
m_frame->Prj().GetGitCommon();
1369 std::unique_lock<std::mutex> lock = common->TryLockAction();
1371 if( lock.owns_lock() )
1373 const std::optional<wxString> prefix = common->GetProjectPrefix();
1375 if( prefix &&
path.StartsWith( *prefix ) )
1376 target.
path =
path.Mid( prefix->length() );
1385 menu.Append( 1,
_(
"Show History for This File" ) );
1386 menu.AppendSeparator();
1387 menu.Append( 2,
_(
"Discard Changes" ) );
1391 menu.AppendSeparator();
1392 menu.Append( 3,
_(
"Ignore This File" ) );
1394 if( !extensionRule.IsEmpty() )
1395 menu.Append( 4, wxString::Format(
_(
"Ignore All '%s' Files" ), extensionRule ) );
1398 switch( GetPopupMenuSelectionFromUser( menu ) )
1403 dialog->ShowHistoryForFile(
path );
1427 bool tracked =
false;
1428 bool conflicted =
false;
1432 auto state = std::make_shared<FILE_STATE>();
1442 [
this, aCommon, aPath, state]()
1444 confirmDiscardFile( aCommon, aPath, state->tracked, state->conflicted, state->root );
1446 _(
"Checking changes..." ) );
1451 bool aConflicted, wxString aRoot )
1456 DisplayInfoMessage(
this,
_(
"An editor has unsaved changes. Save or revert them before discarding "
1457 "files, so the discard is not undone by the next save." ) );
1461 wxString
name = wxFileName( aPath ).GetFullName();
1468 question = wxString::Format(
_(
"Resolve the conflict in '%s' by going back to the version this "
1469 "project was on?\n\n"
1470 "The version that arrived is dropped, and the file no longer needs "
1476 question = wxString::Format(
_(
"Throw away the changes to '%s'?\n\n"
1477 "The file goes back to the last committed version." ),
1482 question = wxString::Format(
_(
"Move '%s' to the trash?\n\n"
1483 "It has never been committed, so there is no version to bring back." ),
1487 wxMessageDialog dlg(
this, question,
_(
"Discard Changes" ), wxYES_NO | wxNO_DEFAULT | wxICON_WARNING );
1488 dlg.SetYesNoLabels( aConflicted ?
_(
"Resolve" )
1489 : aTracked ?
_(
"Discard" )
1490 :
_(
"Move to Trash" ),
1493 if( dlg.ShowModal() != wxID_YES )
1496 if( aCommon !=
m_frame->Prj().GetGitCommon() || aCommon->IsShuttingDown() )
1509 if( !lock.owns_lock() )
1513 if( !aCommon->GetRepo() )
1518 if( !aCommon->DiscardChanges( { aPath }, error ) )
1530 if( !aRoot.EndsWith( wxS(
"/" ) ) )
1531 aRoot += wxS(
"/" );
1533 wxFileName fullPath( aRoot + aPath );
1540 aCommon->NotifyRefreshListeners();
1542 wxString::Format(
_(
"Could not move '%s' to the trash. The file is "
1543 "still on disk, so discard it again to retry." ),
1551 aCommon->NotifyRefreshListeners();
1559 if( !
path.IsEmpty() )
1593 std::shared_ptr<KIGIT_COMMON> common =
m_frame->Prj().GetGitCommon();
1595 if( !common->GetRepo() )
1603 setBusy(
false,
_(
"Cancelled." ) );
1619 m_frame->SetStatusText(
_(
"Cancelling. A stalled connection stops only when it times out." ) );
1644 DisplayInfoMessage(
this, wxString::Format(
_(
"Finish or abandon the %s in progress first." ),
1652 DisplayInfoMessage(
this,
_(
"This project is showing an old snapshot rather than a branch, so it cannot be "
1653 "committed or pushed from here. In the Advanced Git window, choose Branches "
1654 "and double click a branch to go back to it." ) );
1666 std::shared_ptr<KIGIT_COMMON> common =
m_frame->Prj().GetGitCommon();
1686 std::shared_ptr<KIGIT_COMMON> common =
m_frame->Prj().GetGitCommon();
1712 std::vector<wxString> outside;
1716 auto preparation = std::make_shared<PREPARATION>();
1717 const wxString projectPath =
m_frame->Prj().GetProjectPath();
1726 preparation->ready =
true;
1728 [
this, aCommon, preparation]()
1730 if( preparation->ready )
1733 _(
"Checking working files..." ) );
1738 const std::vector<wxString>& aOutside )
1742 auto canAbandon = [
this, aCommon]()
1744 if( aCommon !=
m_frame->Prj().GetGitCommon() || aCommon->IsShuttingDown()
1745 || !
Pgm().GetCommonSettings()->m_Git.enableGit )
1752 DisplayInfoMessage(
this,
_(
"The open editors have unsaved changes. Save or revert them first, so it "
1753 "is clear what is being abandoned." ) );
1763 wxString question = wxString::Format(
_(
"Abandon the %s and go back to the last commit?\n\n"
1764 "Changes made to the files since that commit are discarded." ),
1767 if( !aOutside.empty() )
1771 for(
const wxString&
path : aOutside )
1772 listed += wxS(
"\n " ) +
path;
1774 question += wxString::Format(
_(
"\n\nThis also discards uncommitted changes elsewhere in this "
1779 if( !
IsOK(
this, question ) || !canAbandon() )
1789 if( !lock.owns_lock() )
1792 ok = aCommon->AbandonOperation( error );
1802 aCommon->NotifyRefreshListeners();
1803 setBusy(
false,
_(
"Back at the last commit." ) );
1832 std::shared_ptr<KIGIT_COMMON> common =
m_frame->Prj().GetGitCommon();
1833 git_oid expectedHead;
1835 if( !common->GetRepo() || git_oid_fromstr( &expectedHead,
m_undoHead.second.utf8_string().c_str() ) != GIT_OK )
1845 if( !lock.owns_lock() )
1853 common->NotifyRefreshListeners();
1864 wxString summary, description;
1869 wxWeakRef<GIT_COMMIT_PANE> pane(
this );
1871 if( !draft.IsEmpty() && draft != restored
1872 && !
IsOK(
this,
_(
"Replace the current commit message with the undone commit's message?" ) ) )
1874 if( pane && !pane->IsBeingDeleted() )
1876 setBusy(
false,
_(
"Undid the last commit. Its changes are back in the list, and your message was "
1883 if( !pane || pane->IsBeingDeleted() )
1891 setBusy(
false,
_(
"Undid the last commit. Its changes are back in the list, ready to commit again." ) );
1896 DisplayInfoMessage(
this, wxString::Format(
_(
"This commit is already on the remote branch %s, so undoing "
1897 "it here would rewrite history others may have. Make a new "
1898 "commit that fixes it instead." ),
1903 DisplayInfoMessage(
this,
_(
"The branch or its last commit changed. Review the latest commit and try "
1921 std::pair<wxString, wxString> head;
1926 std::shared_ptr<KIGIT_COMMON> common =
m_frame->Prj().GetGitCommon();
1927 auto info = std::make_shared<AMEND_INFO>();
1936 if( !aExpectedCommit.IsEmpty() && aExpectedCommit !=
info->head.second )
1937 info->refusal =
_(
"The selected commit is no longer the last commit on this branch." );
1939 if(
info->refusal.IsEmpty() )
1941 wxString summary, description;
1946 [
this, common,
info, aExpectedCommit]()
1948 if( !
info->refusal.IsEmpty() )
1958 bool fromHistory = !aExpectedCommit.IsEmpty();
1960 wxWeakRef<GIT_COMMIT_PANE> pane(
this );
1961 wxWeakRef<EDA_BASE_FRAME> frame(
m_frame );
1963 if( fromHistory && !draft.IsEmpty() && draft !=
info->message
1964 && !
IsOK(
this,
_(
"Replace the current commit message with the selected commit's message?" ) ) )
1969 if( !pane || pane->IsBeingDeleted() || !frame || frame->IsBeingDeleted()
1970 || common != frame->Prj().GetGitCommon() || common->IsShuttingDown()
1971 || !
Pgm().GetCommonSettings()->m_Git.enableGit
1972 || frame->Prj().GetLocalSettings().m_GitIntegrationDisabled )
1990 if( fromHistory || draft.IsEmpty() )
2003 _(
"Reading last commit..." ) );
2021 std::pair<wxString, wxString>
head;
2038 std::shared_ptr<KIGIT_COMMON> common =
m_frame->Prj().GetGitCommon();
2040 if( !common->GetRepo() )
2046 branchName.Trim(
true ).Trim(
false );
2058 std::vector<wxString> files =
m_checklist->GetCheckedPaths();
2072 auto request = std::make_shared<COMMIT_REQUEST>();
2073 request->amend = amend;
2075 request->newBranch = newBranch;
2076 request->andPush = aAndPush;
2078 request->branchName = branchName;
2080 request->summary =
m_summary->GetValue();
2082 request->files = std::move( files );
2088 if( request->amend )
2089 request->amendRefusal =
amendRefusal( aCommon, request->head );
2096 [
this, common, request]()
2100 _(
"Checking changes..." ) );
2106 if( !aRequest->amendRefusal.IsEmpty() )
2109 aCommon->NotifyRefreshListeners();
2113 if( !aRequest->displayedBranch.IsEmpty()
2114 && aRequest->head.first != wxS(
"refs/heads/" ) + aRequest->displayedBranch )
2117 "Review the changes and commit again." ) );
2118 aCommon->NotifyRefreshListeners();
2122 if( !aRequest->lfsMessage.IsEmpty() )
2133 if( aCommon !=
m_frame->Prj().GetGitCommon() || aCommon->IsShuttingDown() )
2139 aCommon->NotifyRefreshListeners();
2149 const std::vector<wxString>& files = aRequest.
files;
2150 const bool amend = aRequest.
amend;
2151 const bool newBranch = aRequest.
newBranch;
2152 const wxString& branchName = aRequest.
branchName;
2156 if( files.empty() && !amend )
2158 setBusy(
false,
_(
"Nothing was saved, so there is nothing to commit." ) );
2166 if( common !=
m_frame->Prj().GetGitCommon() || common->IsShuttingDown() )
2171 wxString branchError;
2172 wxString branchDetail;
2173 wxString previousBranch;
2180 if( !lock.owns_lock() )
2186 DisplayInfoMessage(
this,
_(
"The branch or its last commit changed while preparing the commit. "
2187 "Review the changes and commit again." ) );
2188 common->NotifyRefreshListeners();
2200 common->NotifyRefreshListeners();
2216 previousBranch = common->GetCurrentBranchName();
2218 if( !newBranch ||
moveToNewBranch( *common, branchName, branchError, branchDetail ) )
2232 if( newBranch && !committed )
2237 if( !branchError.IsEmpty() )
2265 common->NotifyRefreshListeners();
2273 setBusy(
false,
_(
"Committed." ) );
2278 std::function<
void()> aDone,
const wxString& aStatus )
2284 setBusy(
false, wxEmptyString );
2292 auto read = std::make_shared<bool>(
false );
2296 [read, work = std::move( aWork )](
KIGIT_COMMON& aSession )
2301 [
this, aCommon, read, done = std::move( aDone )]()
2306 setBusy(
false, wxEmptyString );
2314 if( *read && aCommon ==
m_frame->Prj().GetGitCommon() && !aCommon->IsShuttingDown()
2315 && aCommon->GetRepo() &&
Pgm().GetCommonSettings()->m_Git.enableGit )
2326 return m_frame->Prj().GetGitCommon()->Transfers();
2373 m_frame->SetStatusText( aText );
2402 m_frame->SetStatusText( aStatus );
2427 std::function<
void()> aStart )
2429 if( aCommon->SecretRead() )
2444 [
this, aCommon, request, start = std::move( aStart )]()
2446 if( request != m_keyringRequest || !m_keyringWait )
2449 m_keyringWait = false;
2450 m_actionPending = false;
2452 if( aCommon != m_frame->Prj().GetGitCommon()
2453 || aCommon->IsShuttingDown() )
2455 setBusy( false, wxEmptyString );
2462 if( !deferred && request == m_keyringRequest )
2464 m_keyringWait =
false;
2465 m_actionPending =
false;
2489 setBusy(
false,
_(
"Cancelled." ) );
2497 bool hasRemote =
false;
2502 auto target = std::make_shared<TARGET>();
2512 [
this, aCommon, target, aRetriedAfterTrust]()
2514 if( !target->hasRemote )
2516 setBusy(
false,
_(
"Committed. No remote is configured to push to." ) );
2517 aCommon->NotifyRefreshListeners();
2521 startPush( aCommon, target->branch, target->head, aRetriedAfterTrust );
2523 _(
"Checking remote..." ) );
2528 bool aRetriedAfterTrust )
2532 [
this, aCommon, aBranch, aHead, aRetriedAfterTrust]()
2534 startPush( aCommon, aBranch, aHead, aRetriedAfterTrust );
2554 bool authFailure =
false;
2555 bool cancelled =
false;
2557 std::optional<KIGIT::HOST_KEY_FAILURE> hostKey;
2560 auto outcome = std::make_shared<OUTCOME>();
2564 [aCommon, outcome, aBranch, aHead, alive =
m_transfer.Alive(),
2567 GIT_PUSH_HANDLER handler( aCommon.get() );
2568 handler.SetProgressReporter( std::make_unique<KIGIT_STATUS_REPORTER>(
2570 [pane]( const wxString& aText )
2572 pane->ShowTransferProgress( aText );
2574 handler.SetWaitForActionLock(
true );
2575 handler.SetExpectedTarget( aBranch, aHead );
2576 handler.SetCancelToken( aToken );
2577 outcome->result = handler.PerformPush();
2579 outcome->error = error.
summary;
2580 outcome->details = error.
details;
2581 outcome->authFailure = handler.WasAuthFailure();
2582 outcome->hostKey = handler.GetHostKeyFailure();
2586 outcome->cancelled = handler.IsThisOperationCancelled();
2594 aCommon->NotifyRefreshListeners();
2598 [
this, aCommon, outcome, aRetriedAfterTrust]()
2600 onPushDone( aCommon,
static_cast<int>( outcome->result ), outcome->error, outcome->details,
2601 outcome->authFailure, outcome->hostKey, aRetriedAfterTrust, outcome->cancelled );
2605 setBusy(
false,
_(
"Could not start the push." ) );
2610 const wxString& aDetails,
bool aAuthFailure,
2611 const std::optional<KIGIT::HOST_KEY_FAILURE>& aHostKey,
bool aRetriedAfterTrust,
2621 setBusy(
false,
_(
"Pushed to remote." ) );
2628 setBusy(
false, wxEmptyString );
2637 failure.
error = aError;
2661 auto worktree = std::make_shared<GIT_WORKTREE_STATUS>();
2662 wxString projectPath =
m_frame->Prj().GetProjectPath();
2670 [
this, aCommon, worktree]()
2675 if(
IsOK(
this,
_(
"Someone else pushed changes first.\n\n"
2676 "Get their changes and push again?" ) )
2677 && aCommon ==
m_frame->Prj().GetGitCommon() && !aCommon->IsShuttingDown()
2678 &&
Pgm().GetCommonSettings()->m_Git.enableGit )
2683 _(
"Checking working files..." ) );
2688 setBusy(
false,
_(
"Push failed." ) );
2713 auto preparation = std::make_shared<MERGE_PREPARATION>();
2719 preparation->workspace = std::make_unique<GIT_DIFF_WORKSPACE>();
2721 if( !preparation->workspace->IsOk() )
2727 preparation->workspace->Root() + wxFileName::GetPathSeparator() + wxS(
"stages" ),
2728 preparation->headOid, preparation->theirsOid, preparation->conflicts, preparation->error );
2730 [
this, aCommon, aThenPush, preparation]()
2734 _(
"Preparing the merge..." ) );
2739 std::shared_ptr<MERGE_PREPARATION> aPreparation )
2741 if( !aPreparation->workspace || !aPreparation->workspace->IsOk() )
2747 if( !aPreparation->prepared )
2755 auto canResolve = [
this, aCommon]()
2757 if( aCommon !=
m_frame->Prj().GetGitCommon() || aCommon->IsShuttingDown()
2758 || !
Pgm().GetCommonSettings()->m_Git.enableGit )
2765 DisplayInfoMessage(
this,
_(
"The open editors have unsaved changes. Save or revert them before "
2766 "resolving the merge." ) );
2779 if( aPreparation->rebaseConfigured )
2782 _(
"This project is set to rebase when getting changes, but a conflict can only be "
2783 "settled here by merging. Make a merge commit, or cancel and rebase from a git "
2785 wxEmptyString,
_(
"Make Merge Commit" ) )
2788 setBusy(
false,
_(
"Getting changes was cancelled. Your files are unchanged." ) );
2800 setBusy(
false,
_(
"Getting changes was cancelled. Your files are unchanged." ) );
2808 const wxString sep = wxFileName::GetPathSeparator();
2809 const wxString& headOid = aPreparation->headOid;
2810 const wxString& theirsOid = aPreparation->theirsOid;
2811 const std::vector<KIGIT_CONFLICT_SIDES>& conflicts = aPreparation->conflicts;
2814 std::vector<std::pair<wxString, wxString>> resolved;
2821 wxString relativeDest;
2824 std::vector<LOSING_COPY> losingCopies;
2830 std::set<size_t> autoTried;
2832 for(
size_t ii = 0; ii < conflicts.size(); )
2851 wxString mergedOut = workspace.
Root() + sep + wxString::Format( wxS(
"a%zu_" ), ii )
2852 + wxFileName( conflict.
path ).GetFullName();
2855 conflict.
theirsFile, mergedOut,
false,
false,
nullptr )
2858 resolved.emplace_back( conflict.
path, mergedOut );
2864 wxArrayString choices;
2867 choices.Add(
_(
"Open the merge tool" ) );
2870 choices.Add( conflict.
hasOurs ?
_(
"Keep my version" )
2872 :
_(
"Leave it out" ) );
2873 choices.Add( conflict.
hasTheirs ?
_(
"Use the remote version" )
2874 : conflict.
hasAncestor ?
_(
"Delete it, as on the remote" )
2875 :
_(
"Leave it out, as on the remote" ) );
2881 situation =
_(
"'%s' exists only on the remote (%zu of %zu).\n\n"
2882 "How should it be resolved?" );
2886 situation =
_(
"'%s' was deleted here but changed on the remote (%zu of %zu).\n\n"
2887 "How should it be resolved?" );
2891 situation =
_(
"'%s' exists only here (%zu of %zu).\n\n"
2892 "How should it be resolved?" );
2896 situation =
_(
"'%s' was changed here but deleted on the remote (%zu of %zu).\n\n"
2897 "How should it be resolved?" );
2901 situation =
_(
"'%s' was changed both here and on the remote (%zu of %zu).\n\n"
2902 "How should it be resolved?" );
2905 int sel = wxGetSingleChoiceIndex( wxString::Format( situation, conflict.
path, ii + 1, conflicts.size() ),
2906 _(
"Resolve Conflict" ), choices,
this );
2910 wxString warning = handMerged == 1
2911 ?
_(
"Stop resolving? The file you merged by hand is discarded "
2913 : wxString::Format(
_(
"Stop resolving? The %d files you merged by "
2914 "hand are discarded with the rest." ),
2917 if( handMerged > 0 && !
IsOK(
this, warning ) )
2921 setBusy(
false,
_(
"Getting changes was cancelled. Your files are unchanged." ) );
2925 int action = mergeable ? sel : sel + 1;
2929 wxString mergedOut = workspace.
Root() + sep + wxString::Format( wxS(
"m%zu_" ), ii )
2930 + wxFileName( conflict.
path ).GetFullName();
2947 resolved.emplace_back( conflict.
path, mergedOut );
2952 losingCopies.push_back( { conflict.
oursFile, conflict.
path + wxS(
".mine" ) } );
2955 losingCopies.push_back( { conflict.
theirsFile, conflict.
path + wxS(
".theirs" ) } );
2957 else if( action == 1 )
2960 resolved.emplace_back( conflict.
path, conflict.
hasOurs ? conflict.
oursFile : wxString() );
2963 losingCopies.push_back( { conflict.
theirsFile, conflict.
path + wxS(
".theirs" ) } );
2970 losingCopies.push_back( { conflict.
oursFile, conflict.
path + wxS(
".mine" ) } );
2984 if( !losingCopies.empty() )
2987 + wxDateTime::UNow().Format( wxS(
"%Y-%m-%dT%H-%M-%S-%l" ) );
2991 auto discardSavedCopies = [&backupDir]()
2993 if( !backupDir.IsEmpty() )
2994 wxFileName::Rmdir( backupDir, wxPATH_RMDIR_RECURSIVE );
2997 for(
const LOSING_COPY&
copy : losingCopies )
2999 wxFileName dest( backupDir + sep +
copy.relativeDest );
3001 if( !dest.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) || !wxCopyFile(
copy.source, dest.GetFullPath(),
false ) )
3003 discardSavedCopies();
3004 setBusy(
false,
_(
"Getting changes was cancelled. Your files are unchanged." ) );
3005 DisplayErrorMessage(
this, wxString::Format(
_(
"Could not save the version you are replacing "
3006 "as '%s', so the merge was stopped." ),
3007 dest.GetFullPath() ) );
3020 discardSavedCopies();
3024 std::unique_lock<std::mutex> lock;
3032 if( lock.owns_lock() )
3034 result = aCommon->CreateMergedCommit( headOid, theirsOid, resolved, error );
3038 if( !
IsOK(
this,
_(
"Another git operation is in progress. Try again?" ) ) )
3040 discardSavedCopies();
3041 setBusy(
false,
_(
"Getting changes was cancelled. Your files are unchanged." ) );
3049 discardSavedCopies();
3056 aCommon->NotifyRefreshListeners();
3068 else if( backupDir.IsEmpty() )
3069 setBusy(
false,
_(
"Changes merged." ) );
3071 setBusy(
false, wxString::Format(
_(
"Changes merged. The versions you replaced are in '%s'." ), backupDir ) );
3079 if( !aCommon->GetRepo() )
3081 setBusy(
false, wxEmptyString );
3091 auto result = std::make_shared<CHECK>();
3092 wxString projectPath =
m_frame->Prj().GetProjectPath();
3101 [
this, aCommon, aThenPush, aRetriedAfterTrust,
result]()
3111 if( aCommon !=
m_frame->Prj().GetGitCommon() || aCommon->IsShuttingDown() )
3118 startPull( aCommon, aThenPush, aRetriedAfterTrust );
3120 _(
"Checking changes..." ) );
3128 [
this, aCommon, aThenPush, aRetriedAfterTrust]()
3130 startPull( aCommon, aThenPush, aRetriedAfterTrust );
3159 bool authFailure =
false;
3160 bool cancelled =
false;
3162 std::optional<KIGIT::HOST_KEY_FAILURE> hostKey;
3165 auto outcome = std::make_shared<OUTCOME>();
3169 [aCommon, docsBefore, kiway, outcome, alive =
m_transfer.Alive(),
3172 GIT_PULL_HANDLER handler( aCommon.get() );
3173 handler.SetProgressReporter( std::make_unique<KIGIT_STATUS_REPORTER>(
3175 [pane]( const wxString& aText )
3177 pane->ShowTransferProgress( aText );
3179 handler.SetWaitForActionLock(
true );
3180 handler.SetCancelToken( aToken );
3181 outcome->result = handler.PerformPull();
3183 outcome->error = error.
summary;
3184 outcome->details = error.
details;
3185 outcome->authFailure = handler.WasAuthFailure();
3186 outcome->hostKey = handler.GetHostKeyFailure();
3190 outcome->cancelled = handler.IsThisOperationCancelled();
3195 [aCommon, docsBefore,
result, kiway]()
3203 aCommon->NotifyRefreshListeners();
3206 [
this, aCommon, aThenPush, aRetriedAfterTrust, outcome]()
3208 onPullDone( aCommon,
static_cast<int>( outcome->result ), outcome->error, outcome->details,
3209 outcome->authFailure, outcome->hostKey, aRetriedAfterTrust, aThenPush, outcome->cancelled );
3213 setBusy(
false,
_(
"Could not start getting changes." ) );
3218 const wxString& aDetails,
bool aAuthFailure,
3219 const std::optional<KIGIT::HOST_KEY_FAILURE>& aHostKey,
bool aRetriedAfterTrust,
3220 bool aThenPush,
bool aCancelled )
3232 aCommon->NotifyRefreshListeners();
3248 failure.
error = aError;
3280 setBusy(
false,
_(
"Commit your changes first." ) );
3281 aCommon->NotifyRefreshListeners();
3284 if( !aError.IsEmpty() )
3290 DisplayInfoMessage(
this,
_(
"There are changes that are not committed yet, and getting changes "
3291 "would run over them. Commit them first, then get changes again. To "
3292 "set them aside instead, use Stash Changes in the Advanced Git "
3301 setBusy(
false,
_(
"Could not get changes." ) );
3302 aCommon->NotifyRefreshListeners();
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
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...
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.
static void CloseForPane(GIT_COMMIT_PANE *aPane)
Close the live window if the given pane opened it, for when that pane goes away.
static void CloseActive()
Close the live window, for when the project it was filled from goes away.
static GIT_ADVANCED_DIALOG * Active()
The live window, or null when none is open.
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.
BranchResult SwitchToBranch(const wxString &aBranchName)
Switch to the specified branch.
CommitResult PerformCommit(const std::vector< wxString > &aFiles, const wxString &aMessage, const wxString &aAuthorName, const wxString &aAuthorEmail)
CommitResult PerformAmend(const std::vector< wxString > &aFiles, const wxString &aMessage, const wxString &aAuthorName, const wxString &aAuthorEmail)
UndoCommitResult PerformUndoLastCommit(const wxString &aExpectedBranch, const git_oid &aExpectedHead, wxString &aMessage)
wxCheckBox * m_signOffCheckbox
wxTextCtrl * m_newBranchName
wxStaticBoxSizer * m_optionsSizer
wxStaticText * m_summaryCount
STD_BITMAP_BUTTON * m_settingsButton
wxButton * m_showDiffButton
wxButton * m_copyTrustCommand
wxCheckBox * m_amendCheckbox
wxStaticText * m_branchName
wxBoxSizer * m_changesRow
FILE_CHECKLIST_CTRL * m_checklist
wxTextCtrl * m_trustCommand
wxButton * m_undoCommitButton
wxTextCtrl * m_description
wxStaticText * m_changesLabel
GIT_COMMIT_PANE_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(500, 360), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
wxStaticText * m_emptyLabel
SPLIT_BUTTON * m_commitButton
wxCheckBox * m_newBranchCheckbox
wxChoice * m_recentMessages
wxString abandonLabel() const
The label the network button carries while an operation is in progress.
bool othersCanCancel() const
void updateCommitButton()
Set what the commit buttons say, and whether they are enabled, for the current state.
void onPull(wxCommandEvent &aEvent)
int m_credentialPrompts
Keyring reads and credential prompts the current request has shown, reset when it ends.
void onMessageChanged(wxCommandEvent &aEvent)
void resolvePullConflicts(std::shared_ptr< KIGIT_COMMON > aCommon, bool aThenPush)
Resolve a conflicted pull file by file, using the visual merge tool for design files,...
void abandonKeyringWait()
unsigned m_keyringRequest
UTIL::LINK m_transferLink
Follows the transfers other windows run on this pane's repository.
void ShowTransferProgress(const wxString &aText)
Show a line of transfer progress. Called from the UI thread by a KIGIT_STATUS_REPORTER.
wxString m_transferStatus
The status m_transfer began with, shown again once other windows' transfers end before it.
void Pull()
Get changes from the remote, as the Get Changes button does.
wxString GetCommitMessage() const
The message as typed. A second form on the same project shows the same text.
void onNewBranchToggled(wxCommandEvent &aEvent)
std::pair< wxString, wxString > m_undoHead
The branch and commit the last refresh showed, so Undo takes back only the commit the user saw.
void abandonOperation(std::shared_ptr< KIGIT_COMMON > aCommon)
Drop an in-progress merge or rebase and return the project to its last commit.
void BeginAmend(const wxString &aExpectedCommit=wxEmptyString)
Prepare the amend form. A history entry supplies its hash and starts with no files selected.
void finishCommit(std::shared_ptr< KIGIT_COMMON > aCommon, const COMMIT_REQUEST &aRequest)
void onUndoCommit(wxCommandEvent &aEvent)
Take back the last commit while no remote has it, keeping its changes staged and its message.
bool m_showingOthers
The busy state shows another window's transfer, which this pane releases when the last one ends.
bool m_inAdvancedWindow
True on the advanced window's Changes page, false in the docked panel.
std::function< void(const wxString &)> m_fileSelectedHandler
void setDescription(const wxString &aText)
bool m_hasUnpushedCommits
void submitPull(std::shared_ptr< KIGIT_COMMON > aCommon, bool aThenPush, bool aRetriedAfterTrust=false)
aThenPush pushes after a successful pull, which belongs only to the rejected-push recovery flow.
void discardFile(std::shared_ptr< KIGIT_COMMON > aCommon, const wxString &aPath)
KIGIT_QUERY m_refresh
Coalesce refreshes while a repository read is running, and discard stale results.
bool othersBusy() const
The transfers on it that other windows started, leaving out this pane's own.
std::pair< int, int > m_lineStats
Lines the working tree adds and removes against HEAD, read at the last refresh.
void onSettings(wxCommandEvent &aEvent)
The gear's menu: the advanced window and the author.
bool transferCanStart()
False, with a message, while a transfer is running or a merge waits to be finished.
void updateMessageVisibility(bool aHasChanges)
Show the message field whenever a commit is possible, including a message-only amend.
bool deferForSecret(const std::shared_ptr< KIGIT_COMMON > &aCommon, const wxString &aStatus, std::function< void()> aStart)
Read the keyring before a transfer, holding the pane busy as aStatus, then call aStart unless cancell...
void RefreshFileList()
Read the project's git status and repopulate the list.
bool m_editorsDirty
True when an open editor held unsaved changes at the last refresh.
void finishPullConflictPreparation(std::shared_ptr< KIGIT_COMMON > aCommon, bool aThenPush, std::shared_ptr< MERGE_PREPARATION > aPreparation)
void setBusy(bool aBusy, const wxString &aStatus)
Enable or disable the controls while a network operation runs, showing a status.
wxString othersStatus() const
void ReloadAdvancedWindow()
Reload the advanced window when it is open, for a preferences change it also shows.
bool m_canAmend
Whether the current branch allows an amend. A refresh must not change an active amend into a commit.
wxString operationNoun() const
The noun for the operation in progress, for messages.
void onChecklistChanged(wxDataViewEvent &aEvent)
void populateBranches(const STATUS &aStatus)
Fill the branch dropdown from the completed snapshot.
size_t m_unpushedCount
Commits waiting to be pushed, or 0 when the branch has no upstream to count them against.
void onFileActivated(wxDataViewEvent &aEvent)
bool Layout() override
Lay out the pane, then re-wrap the status line when the width its column got has changed.
bool m_commitButtonPushes
True while the main button reads Push, with nothing left to commit.
void ShowHistory()
Open the advanced window on its History page.
wxStaticText * m_summaryRemoved
void updateSummary()
Refresh the staged count in the changes heading, and the summary box where the wide layout has one.
void saveForCommit(std::shared_ptr< KIGIT_COMMON > aCommon, std::shared_ptr< COMMIT_REQUEST > aRequest)
void onCommit(wxCommandEvent &aEvent)
The split button's main half. It commits, or pushes when that is all there is to do.
GIT_TRANSFER_BUSY::HOLD m_ownHold
m_transfer's hold on the repository, so every other pane on it follows and can cancel it
GIT_TRANSFER_BUSY & transfers() const
The transfers on the repository this pane shows.
void showDisabledState()
Clear the list and disable every control while version control is off.
void updateDescriptionHint()
Where the platform has no hint for a multi line box, a label lies over the description box while it i...
std::function< void(bool)> m_busyChangedHandler
Told when a transfer starts and ends. Empty unless an owning window asked.
void layoutWide()
Put the file list beside the commit controls instead of above them, for a wide host,...
KIGIT_TRANSFER m_transfer
The push or pull this panel submitted last.
void OnGitTransfersChanged() override
Follow a transfer on this pane's repository beginning or ending in any window.
void onPushDone(std::shared_ptr< KIGIT_COMMON > aCommon, int aResult, const wxString &aError, const wxString &aDetails, bool aAuthFailure, const std::optional< KIGIT::HOST_KEY_FAILURE > &aHostKey, bool aRetriedAfterTrust, bool aCancelled)
std::pair< wxString, wxString > m_amendHead
The branch and commit chosen when amend started. Keep them fixed while editing.
void onChecklistContextMenu(wxDataViewEvent &aEvent)
void startPush(std::shared_ptr< KIGIT_COMMON > aCommon, const wxString &aBranch, const wxString &aHead, bool aRetriedAfterTrust)
void setStatusText(const wxString &aText)
Set the status line text and wrap it to the width of the label's column.
std::function< void()> m_messageChangedHandler
Told when the message is edited. Empty unless an owning window asked.
bool m_headDetached
True when HEAD is a commit rather than a branch, so nothing can be committed or pushed.
wxString m_statusText
Unwrapped status text, kept so it can be re-wrapped on resize.
std::vector< wxString > m_recentMessageTexts
The full messages behind the Recent messages dropdown, in its order after the caption.
wxString m_currentBranch
The branch a commit will land on, empty when detached or before the first commit.
void populateRecentMessages(const std::vector< wxString > &aMessages)
Fill the Recent messages dropdown from the completed snapshot.
void Push()
Push the local commits, as the Push button does.
int m_statusWrapWidth
The width the status text was last wrapped to, so a layout re-wraps it only when that changes.
bool layoutAndWrapStatus()
Lay out the controls, then rewrap the status line to its column's new width.
void onShowDiff(wxCommandEvent &aEvent)
bool m_operationInProgress
True while a merge or rebase is in progress. The network button then reads Abandon.
void SetCommitMessage(const wxString &aMessage)
wxStaticText * m_summaryFiles
void onThemeChanged(wxSysColourChangedEvent &aEvent)
wxMenuItem * m_commitAndPushItem
The arrow menu's entry, relabelled with the main button.
bool m_hasRepo
Whether the last completed status snapshot had a repository.
void SetFileSelectedHandler(std::function< void(const wxString &)> aHandler)
Called with the path of the file the user selects in the list, or empty when none is.
void onCommitAndPush(wxCommandEvent &aEvent)
GIT_COMMIT_PANE(EDA_BASE_FRAME *aParent)
int m_minDockWidth
The widest row's minimum width, measured before anything is hidden.
GitOperation m_operation
Which operation, so the button and the explanation can name it.
~GIT_COMMIT_PANE() override
std::set< wxString > m_shownPaths
Paths shown in the list at the last refresh, so a refresh can tell which files the user deliberately ...
void onPullDone(std::shared_ptr< KIGIT_COMMON > aCommon, int aResult, const wxString &aError, const wxString &aDetails, bool aAuthFailure, const std::optional< KIGIT::HOST_KEY_FAILURE > &aHostKey, bool aRetriedAfterTrust, bool aThenPush, bool aCancelled)
void onRecentMessage(wxCommandEvent &aEvent)
void runActionQuery(std::shared_ptr< KIGIT_COMMON > aCommon, std::function< void(KIGIT_COMMON &)> aWork, std::function< void()> aDone, const wxString &aStatus)
Read an action's prerequisites off the UI thread, then resume only in the same project.
void startPull(std::shared_ptr< KIGIT_COMMON > aCommon, bool aThenPush, bool aRetriedAfterTrust)
bool dropKeyringWait()
Forget a keyring wait without touching the busy state. True when one was pending.
void onAmendToggled(wxCommandEvent &aEvent)
void onIdle(wxIdleEvent &aEvent)
int m_dockMinHeight
The controls' minimum height from the last layout, applied to the AUI pane at idle time.
bool m_listenerAttached
True once this panel has attached its refresh listener to a session at least once.
void syncListener()
Register a refresh listener with the project's current git session, re-registering if the session cha...
bool m_keyringWait
A push or pull waits on the keyring. The count fences off an answer from a cancelled wait.
size_t m_upstreamAhead
Commits the upstream has that this project does not, which Get Changes brings in.
void applyTheme()
Set the icons and colours that follow the light or dark theme.
void confirmDiscardFile(std::shared_ptr< KIGIT_COMMON > aCommon, const wxString &aPath, bool aTracked, bool aConflicted, wxString aRoot)
KIGIT_QUERY m_actionQuery
EDITOR_SNAPSHOT m_docsBeforePull
On-disk identity of the open documents, taken before a pull so only the ones the merge rewrote are re...
wxStaticText * m_descriptionHint
The description box's hint, a label laid over it while it is empty.
void updateSummaryCount()
Show how many of the summary's 72 columns are left, once that is 10 or fewer.
void applyStatus(const STATUS &aStatus)
Apply a completed repository snapshot on the UI thread.
void submitPush(std::shared_ptr< KIGIT_COMMON > aCommon, bool aRetriedAfterTrust=false)
void finishAbandonOperation(std::shared_ptr< KIGIT_COMMON > aCommon, const std::vector< wxString > &aOutside)
std::weak_ptr< KIGIT_COMMON > m_listenerSession
The git session this panel registered a refresh listener with, weak so it does not keep the session a...
wxHyperlinkCtrl * m_historyLink
Opens the History page from the docked panel. Never shown inside the advanced window.
void updateDockMinHeight()
Give the AUI pane the controls' minimum height, so a dock never squeezes them.
void doCommit(bool aAndPush)
Commit the checked files (or amend the last commit when the amend box is ticked), then push when aAnd...
wxStaticText * m_summaryAdded
void showTrustCommand(const wxString &aCommand)
Show a command to copy under the status line, or hide the row when aCommand is empty.
GitUserConfig GetUserConfig()
Get user configuration (name and email) from git config Falls back to common settings if not found in...
A private scratch directory for extracting committed file versions to diff, removed when this object ...
const wxString & Root() const
The scratch directory, for callers that lay out their own files (e.g. footprint libraries).
The transfers running on one repository, so every window can show and cancel the others'.
wxString Status(const HOLD &aExcept) const
The status of the latest live transfer other than aExcept's, or empty when none is.
void CancelAll()
Call each live transfer's cancel once. They stay live until their owners end them.
bool CanCancel(const HOLD &aExcept) const
True while a live transfer other than aExcept's has a cancel that has not been called.
bool IsBusy(const HOLD &aExcept) const
True while a transfer other than aExcept's is live.
wxColour ToColour() const
static wxString LfsRefusal(KIGIT_COMMON *aCommon)
Return a refusal message for LFS files or an unknown project folder, otherwise empty.
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::pair< int, int > GetWorkingTreeLineStats(const std::set< wxString > &aPaths) const
std::shared_ptr< std::atomic< bool > > CANCEL_TOKEN
One token per operation.
wxString GetLastCommitMessage() const
wxString GetCurrentBranchName() const
wxString GetGitRootDirectory() const
bool IsOperationInProgress() const
True while a merge, rebase, cherry-pick or revert is in progress, which refuses commits.
bool IsPullRebaseConfigured() const
True when the repository is set to rebase rather than merge when getting changes.
git_repository * GetRepo() const
std::vector< wxString > GetRecentCommitMessages(size_t aMax) const
bool CreateBranch(const wxString &aName, const wxString &aFrom=wxEmptyString)
bool GetMergeConflicts(const wxString &aStageDir, wxString &aHeadOid, wxString &aTheirsOid, std::vector< KIGIT_CONFLICT_SIDES > &aConflicts, wxString &aError)
Recompute the merge in memory and extract each conflicted file's three versions into aStageDir,...
bool StartUnbornBranch(const wxString &aName)
Point HEAD at a branch that does not exist yet, so the first commit creates it.
bool IsHeadUnborn() const
True while the repository has no commits, so HEAD names a branch that does not exist yet.
static constexpr std::chrono::milliseconds ACTION_LOCK_WAIT
Long enough for a status read to finish, short enough that a window does not look hung.
wxString GetHeadCommitId() const
Full commit ID at HEAD, or empty for an unborn or missing HEAD.
bool HasPushAndPullRemote() const
bool IsPathInHead(const wxString &aPath)
True when the working directory relative path exists in the HEAD commit's tree.
std::optional< KIGIT_UPSTREAM_STATUS > UpstreamStatus() const
The current branch against its upstream.
static wxString GetLastGitError()
libgit2's last message, without credentials from any URL it quotes, so it is safe to show or trace.
bool HasLocalCommits() const
True when HEAD has commits its upstream does not, or has no upstream yet.
GitOperation OperationInProgress() const
Which operation that is, so the panel can name it.
std::vector< KIGIT_BRANCH_INFO > GetBranches() const
Local and remote branches with their tip commits.
bool DeleteBranch(const wxString &aName)
bool IsPathConflicted(const wxString &aPath) const
True while aPath is one of the files a merge or rebase stopped on.
bool IsHeadDetached() const
True when HEAD points at a commit rather than a branch, as after checking out a tag.
KIGIT_ERROR_MESSAGE PopError()
Take the newest error with its details. Both are empty when none is queued.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
virtual SETTINGS_MANAGER & GetSettingsManager() const
wxString GetBackupRootForProject(const PROJECT *aProject=nullptr) const
Resolve the backup root directory for a project, honoring the active BACKUP_LOCATION preference.
A wrapper for reporting to a wxString object.
bool SaveClipboard(const std::string &aTextUTF8)
Store information to the system clipboard.
int OKOrCancelDialog(wxWindow *aParent, const wxString &aWarning, const wxString &aMessage, const wxString &aDetailedMessage, const wxString &aOKLabel, const wxString &aCancelLabel, bool *aApplyToAll)
Display a warning dialog with aMessage and returns the user response.
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
Base window classes and related definitions.
@ SuccessIndexStale
Committed, but the staged list was left as another program had it. Never retry on this.
@ TargetChanged
The branch or its last commit is no longer the one the caller saw.
@ Published
A remote-tracking branch already holds the commit, so taking it back would rewrite shared history.
static wxString amendRefusal(KIGIT_COMMON &aCommon, const std::pair< wxString, wxString > &aExpectedHead)
static bool moveToNewBranch(KIGIT_COMMON &aCommon, const wxString &aName, wxString &aError, wxString &aDetail)
static std::pair< wxString, wxString > commitHead(git_repository *aRepo)
static void dropNewBranch(KIGIT_COMMON &aCommon, const wxString &aName, const wxString &aPrevious)
static KIGIT::PROMPT_ANSWER refusal(const wxWeakRef< wxWindow > &aParent, bool aHadParent)
@ Busy
Another git operation held the action lock, so nothing was pushed.
bool PrepareEditorsForGitOperation(EDA_BASE_FRAME *aFrame, GIT_EDITOR_PREP aPurpose, bool *aSavedEditors)
Offer to save unsaved schematic and board edits before a git operation.
std::vector< wxString > ChangedTrackedFilesOutsideProject(KIGIT_COMMON &aCommon, const wxString &aProjectPath)
Repository relative paths of tracked files changed outside the project directory, which the checklist...
EDITOR_SNAPSHOT CaptureOpenEditorDocs(KIWAY &aKiway)
Record the on-disk identity of the open documents, before an operation that may rewrite them.
std::vector< FILE_CHECKLIST_ENTRY > BuildGitChangeEntries(KIGIT_COMMON &aCommon, const wxString &aProjectPath, bool aDarkTheme)
Build the file checklist entries for the project's changed files, transient files filtered out and ea...
void ChangeGitIgnore(EDA_BASE_FRAME *aFrame, wxWindow *aParent, GIT_IGNORE_CHANGE aChange, const std::vector< GIT_IGNORE_TARGET > &aTargets)
Write a change to the project's ignored files and refresh every Git surface.
void ReloadOpenEditors(KIWAY &aKiway, const EDITOR_SNAPSHOT &aBefore)
Tell the open board and schematic editors to reload from disk.
GIT_WORKTREE_STATUS ReadGitWorktreeStatus(KIGIT_COMMON &aCommon, const wxString &aProjectPath)
Read tracked changes and Git LFS using a captured project path.
bool DocumentEditorsDirty(KIWAY &aKiway)
Unsaved schematic or board edits can be saved for a commit, even with no changes on disk.
void ShowGitFileDiff(EDA_BASE_FRAME *aFrame, const wxString &aRelativePath)
Open the diff for a changed file, comparing the committed version at HEAD with the working copy.
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.
bool EditorsDirty(KIWAY &aKiway)
Unsaved document or library edits block operations that rewrite files. Call on the UI thread.
@ IGNORE_PATH
Ignore the paths themselves.
@ IGNORE_EXTENSION
Ignore every file sharing the paths' extension.
@ COMMIT
Saving dirty editors for a commit also saves the project file.
static const int ERR_CANCELLED
The user cancelled the operation.
int DispatchMerge(KIWAY &aKiway, DOC_KIND aKind, const wxString &aAncestor, const wxString &aOurs, const wxString &aTheirs, const wxString &aOutput, bool aInteractive, bool aSingleFile, REPORTER *aReporter)
Run a 3-way document/library merge by calling the owning kiface's KIFACE_MERGE_DOCUMENT function expo...
DOC_KIND DocKindFromExtension(const wxString &aPath)
Map a path's extension to a DOC_KIND (.kicad_pcb -> PCB, .kicad_sch -> SCH, .kicad_sym -> SYM_LIB,...
DOC_KIND
Document type a diff/merge entry point should route to, derived from a file path's extension.
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.
void SplitCommitMessage(const wxString &aMessage, wxString &aSummary, wxString &aDescription)
Split a commit message into its first line and the description after the first blank line.
wxString BranchNameError(const wxString &aName)
Empty when aName is a branch name git would accept, otherwise why it would not, in the words to show ...
GIT_IDENTITY ReadGitIdentity(KIGIT_COMMON &aCommon)
Read on a worker while holding the session's action lock.
bool EnsureGitIdentity(wxWindow *aParent, EDA_BASE_FRAME *aFrame, const std::shared_ptr< KIGIT_COMMON > &aCommon, const GIT_IDENTITY &aIdentity)
Open the same editor when the worker snapshot has no usable Git identity.
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.
APIEXPORT wxString ExtensionIgnoreRule(const wxString &aProjectRelPath)
The rule that ignores every file sharing a path's extension, or nothing when it has none.
wxString ComposeCommitMessage(const wxString &aSummary, const wxString &aDescription, const wxString &aSignOff)
Join a summary line, an optional description and an optional sign-off into one commit message.
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.
std::unique_lock< std::mutex > TryLockAction(KIGIT_COMMON &aCommon, wxWindow *aParent)
Try the action lock and show a busy message if it is unavailable.
APIEXPORT IGNORE_STATE IgnoreState(KIGIT_COMMON &aCommon, const wxString &aProjectRelPath, bool aIsDirectory)
What git's rules and its index say about a project path, so the user is offered only what would take ...
@ 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.
@ REPORT
Show the failure.
@ HOST_DECLINED
Stop without a message, the user chose not to trust the server.
bool EditGitIdentity(wxWindow *aParent, EDA_BASE_FRAME *aFrame, const std::shared_ptr< KIGIT_COMMON > &aCommon, const GIT_IDENTITY &aIdentity)
Edit the repository's author and refresh Git views after saving.
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.
KICOMMON_API wxString WrapText(wxWindow *aWindow, const wxString &aText, int aWidth)
Break text into lines no wider than aWidth pixels in aWindow's font.
KICOMMON_API void FollowSystemLinkColour(wxHyperlinkCtrl *aLink)
Keep a hyperlink in the system link colour across a light or dark switch.
PGM_BASE & Pgm()
The global program "get" accessor.
What the open editors and the project settings looked like on disk before an operation that may rewri...
One file row in a FILE_CHECKLIST_CTRL.
wxString path
Row identity, and what the row shows.
std::pair< wxString, wxString > head
std::vector< wxString > files
KIGIT::GIT_IDENTITY identity
std::vector< KIGIT_CONFLICT_SIDES > conflicts
KIGIT::GIT_IDENTITY identity
std::unique_ptr< GIT_DIFF_WORKSPACE > workspace
std::pair< int, int > lineStats
std::vector< KIGIT_BRANCH_INFO > branches
std::vector< FILE_CHECKLIST_ENTRY > entries
wxString attachTrustCommand
std::pair< wxString, wxString > head
std::vector< wxString > recentMessages
One path an ignore change applies to, relative to the project folder with forward slashes.
Repository state used before an operation that requires a clean working tree.
Diff colors with defaults for light backgrounds.
static DIFF_COLOR_THEME ForText(bool aDarkTheme)
Resolve change colors for UI text. Pass the desktop theme captured on the UI thread.
Repository values and whether Git can use them to record a commit.
bool tracked
The path, or a file inside it, is in the index, so a new rule would do nothing.
Why a transfer to a remote failed.
bool cancelled
The user cancelled the transfer.
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.
wxString theirsFile
Extracted remote version, an empty file when absent.
wxString ancestorFile
Extracted common-ancestor version, an empty file when absent.
wxString oursFile
Extracted local version, an empty file when absent.
bool hasOurs
False when the local side deleted the file.
wxString path
Repository-relative path of the conflicted file.
bool hasTheirs
False when the remote side deleted the file.
bool hasAncestor
False when the file did not exist in the common ancestor.
A summary the user can act on, with the raw text that explains it kept apart for the details.
IbisParser parser & reporter
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.
Definition of file extensions used in Kicad.