37#include <wx/filename.h>
38#include <wx/stdpaths.h>
47 LIBGIT2_SCOPE() { git_libgit2_init(); }
48 ~LIBGIT2_SCOPE() { git_libgit2_shutdown(); }
52struct SCOPED_BOOL_OVERRIDE
54 explicit SCOPED_BOOL_OVERRIDE(
bool& aFlag ) : m_flag( aFlag ), m_original( aFlag ) {}
55 ~SCOPED_BOOL_OVERRIDE() { m_flag = m_original; }
66 explicit SCOPED_TEMP_DIR(
const wxString& aPrefix )
68 wxString base = wxStandardPaths::Get().GetTempDir();
69 m_path = base + wxFileName::GetPathSeparator() + aPrefix
70 + wxString::Format( wxS(
"_%lu_%ld" ),
71 static_cast<unsigned long>( ::wxGetProcessId() ),
72 static_cast<long>( wxDateTime::UNow().GetTicks() ) );
73 wxFileName::Mkdir( m_path, 0777, wxPATH_MKDIR_FULL );
78 if( !m_path.IsEmpty() && wxDirExists( m_path ) )
79 wxFileName::Rmdir( m_path, wxPATH_RMDIR_RECURSIVE );
82 const wxString& Path()
const {
return m_path; }
104 std::vector<HISTORY_FILE_DATA> fileData;
108 BOOST_CHECK_NO_THROW( board.
SaveToHistory( wxS(
"/tmp/anywhere" ), fileData ) );
109 BOOST_CHECK( fileData.empty() );
121 wxString tempDir = wxStandardPaths::Get().GetTempDir();
122 wxString projectPath = tempDir + wxFileName::GetPathSeparator() + wxS(
"pcb_autosave.kicad_pro" );
129 std::vector<HISTORY_FILE_DATA> fileData;
133 BOOST_CHECK( fileData.empty() );
144 LIBGIT2_SCOPE libgit;
148 SCOPED_BOOL_OVERRIDE restoreBackupFlag( backupEnabled );
149 backupEnabled =
true;
151 SCOPED_TEMP_DIR tempProject( wxS(
"kicad_qa_issue24016" ) );
152 const wxString& projectPath = tempProject.Path();
154 auto writeFile = [](
const wxString& aPath,
const wxString& aContents )
156 wxFFile f( aPath, wxT(
"w" ) );
158 f.Write( aContents );
163 projectPath + wxFileName::GetPathSeparator() + wxS(
"issue24016.kicad_pcb" );
164 writeFile( boardPath, wxS(
"(kicad_pcb (version 20240108))\n" ) );
169 wxString headHash = history.
GetHeadHash( projectPath );
174 wxString backupsDir =
175 projectPath + wxFileName::GetPathSeparator() + wxS(
"issue24016-backups" );
176 BOOST_REQUIRE( wxFileName::Mkdir( backupsDir, 0777, wxPATH_MKDIR_FULL ) );
178 wxString zipPath = backupsDir + wxFileName::GetPathSeparator()
179 + wxS(
"issue24016-2026-04-22_120000.zip" );
180 writeFile( zipPath, wxS(
"pretend-zip-contents" ) );
182 writeFile( boardPath, wxS(
"(kicad_pcb (version 20240108) (dirty yes))\n" ) );
187 "zip backups directory must survive RestoreCommit" );
189 ".zip archive inside the backups directory must survive RestoreCommit" );
Information pertinent to a Pcbnew printed circuit board.
void SaveToHistory(const wxString &aProjectPath, std::vector< HISTORY_FILE_DATA > &aFileData)
Serialize board into HISTORY_FILE_DATA for non-blocking history commit.
void SetProject(PROJECT *aProject, bool aReferenceOnly=false)
Link a board to a given project.
const wxString & GetFileName() const
PROJECT * GetProject() const
Simple local history manager built on libgit2.
wxString GetHeadHash(const wxString &aProjectPath)
Return the current head commit hash.
bool RestoreCommit(const wxString &aProjectPath, const wxString &aHash, wxWindow *aParent=nullptr)
Restore the project files to the state recorded by the given commit hash.
bool Init(const wxString &aProjectPath)
Initialize the local history repository for the given project path.
virtual COMMON_SETTINGS * GetCommonSettings() const
virtual const wxString GetProjectPath() const
Return the full path of the project.
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Load a project or sets up a new project with a specified path.
bool UnloadProject(PROJECT *aProject, bool aSave=true)
Save, unload and unregister the given PROJECT.
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
PGM_BASE & Pgm()
The global program "get" accessor.
bool enabled
Automatically back up the project when files are saved.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(SaveToHistoryWithNullProjectDoesNotCrash)
Regression test for https://gitlab.com/kicad/code/kicad/-/issues/23737.
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")