32#include <wx/filename.h>
33#include <wx/stdpaths.h>
36#define ARG_KIND "--kind"
37#define ARG_ANCESTOR "ancestor"
38#define ARG_OURS "ours"
39#define ARG_THEIRS "theirs"
40#define ARG_OUTPUT_F "--output"
52 UTF8STDSTR(
_(
"Internal git merge-driver hook (configured automatically by KiCad's "
53 "git integration; not intended for direct use)." ) ) );
77 bool singleFile =
false;
80 if( kindStr ==
"pcb" )
85 else if( kindStr ==
"sch" )
90 else if( kindStr ==
"sym" )
95 else if( kindStr ==
"fp" )
105 wxFprintf( stderr,
_(
"Unknown --kind '%s' (expected pcb, sch, sym, or fp)\n" ),
106 wxString::FromUTF8( kindStr ) );
114 const wxString tmpDir = wxFileName::CreateTempFileName( wxStandardPaths::Get().GetTempDir()
115 + wxFileName::GetPathSeparator()
116 + wxS(
"kicad_mergedriver_" ) );
117 wxRemoveFile( tmpDir );
119 if( !wxFileName::Mkdir( tmpDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
121 wxFprintf( stderr,
_(
"Could not create a temporary directory for the merge.\n" ) );
125 auto staged = [&](
const wxString& aName )
127 return tmpDir + wxFileName::GetPathSeparator() + aName + wxS(
"." ) + ext;
130 const wxString stagedAncestor = staged( wxS(
"ancestor" ) );
131 const wxString stagedOurs = staged( wxS(
"ours" ) );
132 const wxString stagedTheirs = staged( wxS(
"theirs" ) );
133 const wxString stagedOut = staged( wxS(
"merged" ) );
135 bool copied = wxCopyFile( ancestor, stagedAncestor ) && wxCopyFile( ours, stagedOurs )
136 && wxCopyFile( theirs, stagedTheirs );
140 wxFileName::Rmdir( tmpDir, wxPATH_RMDIR_RECURSIVE );
141 wxFprintf( stderr,
_(
"Could not stage merge inputs.\n" ) );
149 stagedOut,
false, singleFile,
nullptr );
155 && wxFileExists( stagedOut ) )
157 if( !wxCopyFile( stagedOut, output ) )
159 wxFileName::Rmdir( tmpDir, wxPATH_RMDIR_RECURSIVE );
160 wxFprintf( stderr,
_(
"Could not write merged output.\n" ) );
165 wxFileName::Rmdir( tmpDir, wxPATH_RMDIR_RECURSIVE );
argparse::ArgumentParser m_argParser
COMMAND(const std::string &aName)
Define a new COMMAND instance.
int doPerform(KIWAY &aKiway) override
The internal handler that should be overloaded to implement command specific processing and work.
GIT_MERGEDRIVER_COMMAND()
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
static const std::string KiCadSchematicFileExtension
static const std::string KiCadSymbolLibFileExtension
static const std::string KiCadFootprintFileExtension
static const std::string KiCadPcbFileExtension
static wxString From_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
static const int ERR_ARGS
static const int ERR_RC_VIOLATIONS
Rules check violation count was greater than 0.
static const int ERR_INVALID_INPUT_FILE
static const int ERR_INVALID_OUTPUT_CONFLICT
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
Document type a diff/merge entry point should route to, derived from a file path's extension.
Definition of file extensions used in Kicad.