KiCad PCB EDA Suite
Loading...
Searching...
No Matches
git_status_entries.h
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
20#ifndef GIT_STATUS_ENTRIES_H
21#define GIT_STATUS_ENTRIES_H
22
23#include <functional>
24#include <vector>
25
26#include <gestfich.h>
30
31class EDA_BASE_FRAME;
32class KIWAY;
33class KIGIT_COMMON;
34class KIGIT_QUERY;
35class wxWindow;
36struct git_repository;
37
38
45{
46public:
48
51
53 bool IsOk() const { return !m_root.Path().IsEmpty(); }
54
56 const wxString& Root() const { return m_root.Path(); }
57
60 wxString Materialize( git_repository* aRepo, const wxString& aRef, const wxString& aRelPath,
62
63private:
65 int m_slot = 0;
66};
67
76std::vector<FILE_CHECKLIST_ENTRY> BuildGitChangeEntries( KIGIT_COMMON& aCommon, const wxString& aProjectPath,
77 bool aDarkTheme );
78
88
103bool PrepareEditorsForGitOperation( EDA_BASE_FRAME* aFrame, GIT_EDITOR_PREP aPurpose, bool* aSavedEditors = nullptr );
104
107bool DocumentEditorsDirty( KIWAY& aKiway );
108
110bool EditorsDirty( KIWAY& aKiway );
111
114std::vector<wxString> LibraryEditorsWithUnsavedChanges( KIWAY& aKiway );
115
118std::vector<wxString> ChangedTrackedFilesOutsideProject( KIGIT_COMMON& aCommon, const wxString& aProjectPath );
119
126{
127 bool checked = false;
128 bool hasTrackedChanges = false;
129 wxString lfsMessage;
130 std::vector<wxString> outsideProject;
131
134 wxString RefusalMessage( const std::vector<wxString>& aUnsavedEditors, bool aAllowTrackedChanges = false ) const;
135};
136
139GIT_WORKTREE_STATUS ReadGitWorktreeStatus( KIGIT_COMMON& aCommon, const wxString& aProjectPath );
140
143bool ProjectSafeToRewrite( EDA_BASE_FRAME* aFrame, wxWindow* aParent, const GIT_WORKTREE_STATUS& aStatus,
144 bool aAllowTrackedChanges = false );
145
152
161void ReloadOpenEditors( KIWAY& aKiway, const EDITOR_SNAPSHOT& aBefore );
162
169void ProjectClearOfUncommittedWork( EDA_BASE_FRAME* aFrame, wxWindow* aParent, KIGIT_QUERY& aQuery,
170 std::function<void( const GIT_WORKTREE_STATUS& )> aReady );
171
178void SwitchProjectToBranch( EDA_BASE_FRAME* aFrame, wxWindow* aParent, const wxString& aBranch, KIGIT_QUERY& aQuery,
179 std::function<void()> aFinished = {} );
180
189void ShowGitFileDiff( EDA_BASE_FRAME* aFrame, const wxString& aRelativePath );
190
201void ShowGitCommitDiff( EDA_BASE_FRAME* aFrame, const wxString& aCommitHash, wxWindow* aParentWindow = nullptr,
202 const wxString& aRelativePath = wxEmptyString );
203
212
219bool MaterializeCommitFile( KIGIT_COMMON& aCommon, GIT_DIFF_WORKSPACE& aWorkspace, const wxString& aCommitHash,
220 const wxString& aRelativePath, GIT_FILE_SIDES& aSides );
221
227bool MaterializeWorkingFile( KIGIT_COMMON& aCommon, GIT_DIFF_WORKSPACE& aWorkspace, const wxString& aRelativePath,
228 GIT_FILE_SIDES& aSides );
229
230#endif // GIT_STATUS_ENTRIES_H
Represent a set of changes (additions, deletions or modifications) of a data model (e....
Definition commit.h:68
The base frame for deriving all KiCad main window classes.
A private scratch directory for extracting committed file versions to diff, removed when this object ...
bool IsOk() const
True when the scratch directory was created.
const wxString & Root() const
The scratch directory, for callers that lay out their own files (e.g. footprint libraries).
wxString Materialize(git_repository *aRepo, const wxString &aRef, const wxString &aRelPath, KICAD_DIFF::DOC_KIND aKind)
Extract aRelPath at aRef into a uniquely named slot and return the path to load, or an empty string w...
GIT_DIFF_WORKSPACE & operator=(const GIT_DIFF_WORKSPACE &)=delete
GIT_DIFF_WORKSPACE(const GIT_DIFF_WORKSPACE &)=delete
SCOPED_TEMP_PATH m_root
The project's git session.
Read repository state without blocking the UI.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition kiway.h:348
A temporary file or directory that is removed when the object goes out of scope.
Definition gestfich.h:62
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.
bool MaterializeWorkingFile(KIGIT_COMMON &aCommon, GIT_DIFF_WORKSPACE &aWorkspace, const wxString &aRelativePath, GIT_FILE_SIDES &aSides)
Write the committed version of a file into aWorkspace and name its working copy beside it.
bool MaterializeCommitFile(KIGIT_COMMON &aCommon, GIT_DIFF_WORKSPACE &aWorkspace, const wxString &aCommitHash, const wxString &aRelativePath, GIT_FILE_SIDES &aSides)
Write both sides of one file a commit changed into aWorkspace, the parent's version and the commit's.
bool ProjectSafeToRewrite(EDA_BASE_FRAME *aFrame, wxWindow *aParent, const GIT_WORKTREE_STATUS &aStatus, bool aAllowTrackedChanges=false)
Combine the repository snapshot with live editor state and explain any refusal.
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...
GIT_EDITOR_PREP
What the caller is about to do, which decides the wording and whether the project file is written.
@ WORKING_TREE
The working files are about to be rewritten, by a pull, branch switch or stash.
void ReloadOpenEditors(KIWAY &aKiway, const EDITOR_SNAPSHOT &aBefore)
Tell the open board and schematic editors to reload from disk.
std::vector< wxString > LibraryEditorsWithUnsavedChanges(KIWAY &aKiway)
Names of the library editors holding unsaved changes.
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...
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.
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.
bool PrepareEditorsForGitOperation(EDA_BASE_FRAME *aFrame, GIT_EDITOR_PREP aPurpose, bool *aSavedEditors=nullptr)
Offer to save unsaved schematic and board edits before a git operation.
void ShowGitCommitDiff(EDA_BASE_FRAME *aFrame, const wxString &aCommitHash, wxWindow *aParentWindow=nullptr, const wxString &aRelativePath=wxEmptyString)
Open the diff for what a commit changed, comparing it against its parent.
bool EditorsDirty(KIWAY &aKiway)
Unsaved document or library edits block operations that rewrite files. Call on the UI thread.
DOC_KIND
Document type a diff/merge entry point should route to, derived from a file path's extension.
What the open editors and the project settings looked like on disk before an operation that may rewri...
The two sides of one file, written out for a comparison.
KICAD_DIFF::DOC_KIND kind
wxString before
Empty when the file did not exist on that side.
wxString error
Why the sides could not be written, when they could not.
Repository state used before an operation that requires a clean working tree.
std::vector< wxString > outsideProject
wxString RefusalMessage(const std::vector< wxString > &aUnsavedEditors, bool aAllowTrackedChanges=false) const
Empty when rewriting is allowed.