38 git_repository* repo =
nullptr;
39 int error = git_repository_open( &repo, aPath.mb_str() );
43 git_repository_free( repo );
55 return InitResult::AlreadyExists;
58 git_repository* repo =
nullptr;
60 if( git_repository_init( &repo, aPath.mb_str(), 0 ) != GIT_OK )
63 git_repository_free( repo );
65 AddErrorString( wxString::Format(
_(
"Failed to initialize Git repository: %s" ),
67 return InitResult::Error;
73 wxLogTrace(
traceGit,
"Successfully initialized Git repository at %s", aPath );
74 return InitResult::Success;
80 if( aConfig.
url.IsEmpty() )
83 git_repository* repo =
GetRepo();
96 git_remote* remote =
nullptr;
106 fullURL = aConfig.
url.StartsWith(
"https" ) ?
"https://" :
"http://";
114 fullURL.append( wxS(
":" ) );
118 fullURL.append( wxS(
"@" ) );
122 wxString bareURL = aConfig.
url;
123 if( bareURL.StartsWith(
"https://" ) )
124 bareURL = bareURL.Mid( 8 );
125 else if( bareURL.StartsWith(
"http://" ) )
126 bareURL = bareURL.Mid( 7 );
128 fullURL.append( bareURL );
132 fullURL = aConfig.
url;
135 int error = git_remote_create_with_fetchspec( &remote, repo,
"origin",
136 fullURL.ToStdString().c_str(),
137 "+refs/heads/*:refs/remotes/origin/*" );
141 if( error != GIT_OK )
148 wxLogTrace(
traceGit,
"Successfully set up remote origin" );
bool IsRepository(const wxString &aPath)
Check if a directory is already a git repository.
virtual ~GIT_INIT_HANDLER()
void UpdateProgress(int aCurrent, int aTotal, const wxString &aMessage) override
GIT_INIT_HANDLER(KIGIT_COMMON *aCommon)
InitResult InitializeRepository(const wxString &aPath)
Initialize a new git repository in the specified directory.
bool SetupRemote(const RemoteConfig &aConfig)
Set up a remote for the repository.
void ReportProgress(int aCurrent, int aTotal, const wxString &aMessage)
static wxString GetLastGitError()
void SetSSHKey(const wxString &aSSHKey)
void SetUsername(const wxString &aUsername)
void SetPassword(const wxString &aPassword)
void SetRepo(git_repository *aRepo)
void AddErrorString(const wxString aErrorString)
git_repository * GetRepo() const
Get a pointer to the git repository.
KIGIT_COMMON * GetCommon() const
Get the common object.
const wxChar *const traceGit
Flag to enable Git debugging output.
std::unique_ptr< git_remote, decltype([](git_remote *aRemote) { git_remote_free(aRemote) GitRemotePtr
A unique pointer for git_remote objects with automatic cleanup.
KIGIT_COMMON::GIT_CONN_TYPE connType
wxLogTrace helper definitions.