From 3e671d7b57fa6f38ae557cbba7efa25372ce97ce Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Tue, 22 Jan 2013 15:38:54 +0100 Subject: [PATCH] Use libgit2 to create repositories Signed-off-by: Sven Strickroth --- src/Resources/TortoiseProcENG.rc | 1 + .../Commands/CreateRepositoryCommand.cpp | 42 +++++++++++----------- src/TortoiseProc/resource.h | 1 + 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/Resources/TortoiseProcENG.rc b/src/Resources/TortoiseProcENG.rc index 19836c63f..9a9eabce4 100644 --- a/src/Resources/TortoiseProcENG.rc +++ b/src/Resources/TortoiseProcENG.rc @@ -3936,6 +3936,7 @@ BEGIN IDS_SETTINGS_SYMBOLIZEREFNAMES_TT "Show symbols on ref labels to substitute part of the ref names" IDS_PROC_SYNC_PUSHNOTES "Push notes" + IDS_PROC_REPOCREATED "Initialized empty Git repository in %s." END #endif // English (U.S.) resources diff --git a/src/TortoiseProc/Commands/CreateRepositoryCommand.cpp b/src/TortoiseProc/Commands/CreateRepositoryCommand.cpp index 065f143b2..160bd6ff0 100644 --- a/src/TortoiseProc/Commands/CreateRepositoryCommand.cpp +++ b/src/TortoiseProc/Commands/CreateRepositoryCommand.cpp @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2008-2012 - TortoiseGit +// Copyright (C) 2008-2013 - TortoiseGit // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -21,7 +21,8 @@ #include "CreateRepositoryCommand.h" #include "ShellUpdater.h" #include "MessageBox.h" -#include "git.h" +#include "git2.h" +#include "UnicodeUtils.h" #include "CreateRepoDlg.h" @@ -39,29 +40,26 @@ bool CreateRepositoryCommand::Execute() return false; } - CGit git; - git.m_CurrentDir = this->orgCmdLinePath.GetWinPath(); - CString output; - int ret; - - if (dlg.m_bBare) - ret = git.Run(_T("git.exe init-db --bare"), &output, CP_UTF8); - else - ret = git.Run(_T("git.exe init-db"), &output, CP_UTF8); - - if (output.IsEmpty()) output = _T("git.Run() had no output"); - - if (ret) + git_repository *repo; + CStringA path(CUnicodeUtils::GetMulti(folder, CP_UTF8)); + if (git_repository_init(&repo, path.GetBuffer(), dlg.m_bBare)) { - CMessageBox::Show(hwndExplorer, output, _T("TortoiseGit"), MB_ICONERROR); + path.ReleaseBuffer(); + const git_error *err = giterr_last(); + if (err == nullptr) + CMessageBox::Show(hwndExplorer, _T("An error occoured in libgit2 without providing a message."), _T("TortoiseGit"), MB_OK | MB_ICONERROR); + else + CMessageBox::Show(hwndExplorer, CUnicodeUtils::GetUnicode(giterr_last()->message), _T("TortoiseGit"), MB_OK | MB_ICONERROR); return false; } - else - { - if (!dlg.m_bBare) - CShellUpdater::Instance().AddPathForUpdate(orgCmdLinePath); - CMessageBox::Show(hwndExplorer, output, _T("TortoiseGit"), MB_OK | MB_ICONINFORMATION); - } + path.ReleaseBuffer(); + git_repository_free(repo); + + if (!dlg.m_bBare) + CShellUpdater::Instance().AddPathForUpdate(orgCmdLinePath); + CString str; + str.Format(IDS_PROC_REPOCREATED, folder); + CMessageBox::Show(hwndExplorer, str, _T("TortoiseGit"), MB_OK | MB_ICONINFORMATION); return true; } return false; diff --git a/src/TortoiseProc/resource.h b/src/TortoiseProc/resource.h index 1648ff909..4a67fe86b 100644 --- a/src/TortoiseProc/resource.h +++ b/src/TortoiseProc/resource.h @@ -858,6 +858,7 @@ #define IDC_CONFIG 1385 #define IDC_BUTTON_UNIFIEDDIFF 1385 #define IDS_PROC_SYNC_PUSHNOTES 1385 +#define IDS_PROC_REPOCREATED 1386 #define IDC_FILTER 1387 #define IDC_REVISIONGROUP 1393 #define IDC_REPOLABEL 1394 -- 2.11.4.GIT