本文整理汇总了C++中CGit类的典型用法代码示例。如果您正苦于以下问题:C++ CGit类的具体用法?C++ CGit怎么用?C++ CGit使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CGit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Revert
int CGit::Revert(CTGitPath &path,bool keep)
{
CString cmd, out;
if(path.m_Action & CTGitPath::LOGACTIONS_ADDED)
{ //To init git repository, there are not HEAD, so we can use git reset command
cmd.Format(_T("git.exe rm --cache -- \"%s\""),path.GetGitPathString());
if(g_Git.Run(cmd,&out,CP_OEMCP))
return -1;
}
else if(path.m_Action & CTGitPath::LOGACTIONS_REPLACED )
{
cmd.Format(_T("git.exe mv \"%s\" \"%s\""),path.GetGitPathString(),path.GetGitOldPathString());
if(g_Git.Run(cmd,&out,CP_OEMCP))
return -1;
cmd.Format(_T("git.exe checkout -f -- \"%s\""),path.GetGitOldPathString());
if(g_Git.Run(cmd,&out,CP_OEMCP))
return -1;
}
else
{
cmd.Format(_T("git.exe checkout -f -- \"%s\""),path.GetGitPathString());
if(g_Git.Run(cmd,&out,CP_OEMCP))
return -1;
}
return 0;
}
示例2: _T
int CGitDiff::SubmoduleDiffNull(const CTGitPath * pPath, const git_revnum_t &rev1)
{
CString oldhash = GIT_REV_ZERO;
CString oldsub ;
CString newsub;
CString newhash;
CString cmd;
if (rev1 != GIT_REV_ZERO)
cmd.Format(_T("git.exe ls-tree \"%s\" -- \"%s\""), rev1, pPath->GetGitPathString());
else
cmd.Format(_T("git.exe ls-files -s -- \"%s\""), pPath->GetGitPathString());
CString output, err;
if (g_Git.Run(cmd, &output, &err, CP_UTF8))
{
CMessageBox::Show(NULL, output + L"\n" + err, _T("TortoiseGit"), MB_OK|MB_ICONERROR);
return -1;
}
int start=0;
start=output.Find(_T(' '),start);
if(start>0)
{
if (rev1 != GIT_REV_ZERO) // in ls-files the hash is in the second column; in ls-tree it's in the third one
start = output.Find(_T(' '), start + 1);
if(start>0)
newhash=output.Mid(start+1, 40);
CGit subgit;
subgit.m_CurrentDir=g_Git.m_CurrentDir+_T("\\")+pPath->GetWinPathString();
int encode=CAppUtils::GetLogOutputEncode(&subgit);
cmd.Format(_T("git.exe log -n1 --pretty=format:\"%%s\" %s --"), newhash);
bool toOK = !subgit.Run(cmd,&newsub,encode);
bool dirty = false;
if (rev1 == GIT_REV_ZERO)
{
CString dirtyList;
subgit.Run(_T("git.exe status --porcelain"), &dirtyList, encode);
dirty = !dirtyList.IsEmpty();
}
CSubmoduleDiffDlg submoduleDiffDlg;
submoduleDiffDlg.SetDiff(pPath->GetWinPath(), false, oldhash, oldsub, true, newhash, newsub, toOK, dirty, CSubmoduleDiffDlg::NewSubmodule);
submoduleDiffDlg.DoModal();
if (submoduleDiffDlg.IsRefresh())
return 1;
return 0;
}
if (rev1 != GIT_REV_ZERO)
CMessageBox::Show(NULL, _T("ls-tree output format error"), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
else
CMessageBox::Show(NULL, _T("ls-files output format error"), _T("TortoiseGit"), MB_OK | MB_ICONERROR);
return -1;
}
示例3: _T
bool SubmoduleAddCommand::Execute()
{
bool bRet = false;
CSubmoduleAddDlg dlg;
dlg.m_strPath = cmdLinePath.GetDirectory().GetWinPathString();
dlg.m_strProject = g_Git.m_CurrentDir;
if( dlg.DoModal() == IDOK )
{
if (dlg.m_bAutoloadPuttyKeyFile)
CAppUtils::LaunchPAgent(&dlg.m_strPuttyKeyFile);
CString cmd;
if(dlg.m_strPath.Left(g_Git.m_CurrentDir.GetLength()) == g_Git.m_CurrentDir)
dlg.m_strPath = dlg.m_strPath.Right(dlg.m_strPath.GetLength()-g_Git.m_CurrentDir.GetLength()-1);
CString branch;
if(dlg.m_bBranch)
branch.Format(_T(" -b %s "), (LPCTSTR)dlg.m_strBranch);
CString force;
if (dlg.m_bForce)
force = _T("--force");
dlg.m_strPath.Replace(_T('\\'),_T('/'));
dlg.m_strRepos.Replace(_T('\\'),_T('/'));
cmd.Format(_T("git.exe submodule add %s %s -- \"%s\" \"%s\""),
(LPCTSTR)branch, (LPCTSTR)force,
(LPCTSTR)dlg.m_strRepos, (LPCTSTR)dlg.m_strPath);
CProgressDlg progress;
progress.m_GitCmd=cmd;
progress.DoModal();
if (progress.m_GitStatus == 0)
{
if (dlg.m_bAutoloadPuttyKeyFile)
{
SetCurrentDirectory(g_Git.m_CurrentDir);
CGit subgit;
dlg.m_strPath.Replace(_T('/'), _T('\\'));
subgit.m_CurrentDir = PathIsRelative(dlg.m_strPath) ? g_Git.CombinePath(dlg.m_strPath) : dlg.m_strPath;
if (subgit.SetConfigValue(_T("remote.origin.puttykeyfile"), dlg.m_strPuttyKeyFile, CONFIG_LOCAL))
{
CMessageBox::Show(NULL, _T("Fail set config remote.origin.puttykeyfile"), _T("TortoiseGit"), MB_OK| MB_ICONERROR);
return FALSE;
}
}
}
bRet = TRUE;
}
return bRet;
}
示例4: GetRemoteList
int CGit::GetRemoteList(STRING_VECTOR &list)
{
int ret;
CString cmd,output;
cmd=_T("git.exe config --get-regexp remote.*.url");
ret=g_Git.Run(cmd,&output,CP_UTF8);
if(!ret)
{
int pos=0;
CString one;
while( pos>=0 )
{
one=output.Tokenize(_T("\n"),pos);
int start=one.Find(_T("."),0);
if(start>0)
{
CString url;
url=one.Right(one.GetLength()-start-1);
one=url;
one=one.Left(one.Find(_T("."),0));
list.push_back(one);
}
}
}
return ret;
}
示例5: GetBranchList
int CGit::GetBranchList(STRING_VECTOR &list,int *current,BRANCH_TYPE type)
{
int ret;
CString cmd,output;
cmd=_T("git.exe branch");
if(type==(BRANCH_LOCAL|BRANCH_REMOTE))
cmd+=_T(" -a");
else if(type==BRANCH_REMOTE)
cmd+=_T(" -r");
int i=0;
ret=g_Git.Run(cmd,&output,CP_UTF8);
if(!ret)
{
int pos=0;
CString one;
while( pos>=0 )
{
one=output.Tokenize(_T("\n"),pos);
list.push_back(one.Right(one.GetLength()-2));
if(one[0] == _T('*'))
if(current)
*current=i;
i++;
}
}
return ret;
}
示例6: addto_map_each_ref_fn
int addto_map_each_ref_fn(const char *refname, const unsigned char *sha1, int /*flags*/, void *cb_data)
{
MAP_HASH_NAME *map = (MAP_HASH_NAME*)cb_data;
CString str;
g_Git.StringAppend(&str, (BYTE*)refname, CP_UTF8);
CGitHash hash((char*)sha1);
(*map)[hash].push_back(str);
if(strncmp(refname, "refs/tags", 9) == 0)
{
try
{
GIT_HASH refhash;
if(!git_deref_tag(sha1, refhash))
{
(*map)[(char*)refhash].push_back(str+_T("^{}"));
}
}
catch (char* msg)
{
CString err(msg);
::MessageBox(NULL, _T("Could not get (readable) reference for hash ") + hash.ToString() + _T(".\nlibgit reports:\n") + err, _T("TortoiseGit"), MB_ICONERROR);
}
}
return 0;
}
示例7: GetOneFile
int CGit::GetOneFile(CString Refname, CTGitPath &path, const CString &outputfile)
{
if(g_Git.m_IsUseGitDLL)
{
CAutoLocker lock(g_Git.m_critGitDllSec);
try
{
g_Git.CheckAndInitDll();
CStringA ref, patha, outa;
ref = CUnicodeUtils::GetMulti(Refname, CP_UTF8);
patha = CUnicodeUtils::GetMulti(path.GetGitPathString(), CP_UTF8);
outa = CUnicodeUtils::GetMulti(outputfile, CP_UTF8);
::DeleteFile(outputfile);
return git_checkout_file((const char*)ref.GetBuffer(),(const char*)patha.GetBuffer(),(const char*)outa.GetBuffer());
}catch(...)
{
return -1;
}
}
else
{
CString cmd;
cmd.Format(_T("git.exe cat-file -p %s:\"%s\""), Refname, path.GetGitPathString());
return RunLogFile(cmd,outputfile);
}
}
示例8: GetMapHashToFriendName
int CGit::GetMapHashToFriendName(MAP_HASH_NAME &map)
{
int ret;
CString cmd,output;
cmd=_T("git show-ref -d");
ret=g_Git.Run(cmd,&output,CP_UTF8);
if(!ret)
{
int pos=0;
CString one;
while( pos>=0 )
{
one=output.Tokenize(_T("\n"),pos);
int start=one.Find(_T(" "),0);
if(start>0)
{
CString name;
name=one.Right(one.GetLength()-start-1);
CString hash;
hash=one.Left(start);
map[hash].push_back(name);
}
}
}
return ret;
}
示例9: _T
int CTGitPathList::FillUnRev(unsigned int action, CTGitPathList *list, CString *err)
{
this->Clear();
CTGitPath path;
int count;
if(list==NULL)
count=1;
else
count=list->GetCount();
for (int i = 0; i < count; ++i)
{
CString cmd;
int pos = 0;
CString ignored;
if(action & CTGitPath::LOGACTIONS_IGNORE)
ignored= _T(" -i");
if(list==NULL)
{
cmd=_T("git.exe ls-files --exclude-standard --full-name --others -z");
cmd+=ignored;
}
else
{ cmd.Format(_T("git.exe ls-files --exclude-standard --full-name --others -z%s -- \"%s\""),
(LPCTSTR)ignored,
(*list)[i].GetWinPath());
}
BYTE_VECTOR out, errb;
out.clear();
if (g_Git.Run(cmd, &out, &errb))
{
if (err != nullptr)
CGit::StringAppend(err, &errb[0], CP_UTF8, (int)errb.size());
return -1;
}
pos=0;
CString one;
while (pos >= 0 && pos < (int)out.size())
{
one.Empty();
CGit::StringAppend(&one, &out[pos], CP_UTF8);
if(!one.IsEmpty())
{
//SetFromGit will clear all status
path.SetFromGit(one);
path.m_Action=action;
AddPath(path);
}
pos=out.findNextString(pos);
}
}
return 0;
}
示例10: _T
int CGitDiff::SubmoduleDiffNull(CTGitPath *pPath, git_revnum_t &/*rev1*/)
{
CString oldhash = GIT_REV_ZERO;
CString oldsub ;
CString newsub;
CString newhash;
CString cmd;
cmd.Format(_T("git.exe ls-tree HEAD -- \"%s\""), pPath->GetGitPathString());
CString output, err;
if(g_Git.Run(cmd, &output, &err, CP_ACP))
{
CMessageBox::Show(NULL, output + L"\n" + err, _T("TortoiseGit"), MB_OK|MB_ICONERROR);
return -1;
}
int start=0;
start=output.Find(_T(' '),start);
if(start>0)
{
start=output.Find(_T(' '),start+1);
if(start>0)
newhash=output.Mid(start+1, 40);
CGit subgit;
subgit.m_CurrentDir=g_Git.m_CurrentDir+_T("\\")+pPath->GetWinPathString();
int encode=CAppUtils::GetLogOutputEncode(&subgit);
cmd.Format(_T("git.exe log -n1 --pretty=format:\"%%s\" %s"),newhash);
subgit.Run(cmd,&newsub,encode);
CSubmoduleDiffDlg submoduleDiffDlg;
submoduleDiffDlg.SetDiff(pPath->GetWinPath(), false, oldhash, oldsub, newhash, newsub);
submoduleDiffDlg.DoModal();
return 0;
}
CMessageBox::Show(NULL,_T("ls-tree output format error"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
return -1;
}
示例11: Execute
bool CreateRepositoryCommand::Execute()
{
CString folder = this->orgCmdLinePath.GetWinPath();
CCreateRepoDlg dlg;
dlg.m_folder = folder;
if(dlg.DoModal() == IDOK)
{
CString message;
message.Format(IDS_WARN_GITINIT_FOLDERNOTEMPTY, folder);
if (!PathIsDirectoryEmpty(folder) && CMessageBox::Show(hwndExplorer, message, _T("TortoiseGit"), 1, IDI_ERROR, CString(MAKEINTRESOURCE(IDS_ABORTBUTTON)), CString(MAKEINTRESOURCE(IDS_PROCEEDBUTTON))) == 1)
{
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)
{
CMessageBox::Show(hwndExplorer, output, _T("TortoiseGit"), MB_ICONERROR);
return false;
}
else
{
if (!dlg.m_bBare)
CShellUpdater::Instance().AddPathForUpdate(orgCmdLinePath);
CMessageBox::Show(hwndExplorer, output, _T("TortoiseGit"), MB_OK | MB_ICONINFORMATION);
}
return true;
}
return false;
}
示例12: CheckCleanWorkTree
BOOL CGit::CheckCleanWorkTree()
{
CString out;
CString cmd;
cmd=_T("git.exe rev-parse --verify HEAD");
if(g_Git.Run(cmd,&out,CP_UTF8))
return FALSE;
cmd=_T("git.exe update-index --ignore-submodules --refresh");
if(g_Git.Run(cmd,&out,CP_UTF8))
return FALSE;
cmd=_T("git.exe diff-files --quiet --ignore-submodules");
if(g_Git.Run(cmd,&out,CP_UTF8))
return FALSE;
cmd=_T("git diff-index --cached --quiet HEAD --ignore-submodules");
if(g_Git.Run(cmd,&out,CP_UTF8))
return FALSE;
return TRUE;
}
示例13: IsInitRepos
BOOL CGit::IsInitRepos()
{
CString cmdout;
cmdout.Empty();
if(g_Git.Run(_T("git.exe rev-parse --revs-only HEAD"),&cmdout,CP_UTF8))
{
// CMessageBox::Show(NULL,cmdout,_T("TortoiseGit"),MB_OK);
return TRUE;
}
if(cmdout.IsEmpty())
return TRUE;
return FALSE;
}
示例14: ListConflictFile
int CGit::ListConflictFile(CTGitPathList &list,CTGitPath *path)
{
BYTE_VECTOR vector;
CString cmd;
if(path)
cmd.Format(_T("git.exe ls-files -u -t -z -- \"%s\""),path->GetGitPathString());
else
cmd=_T("git.exe ls-files -u -t -z");
if(g_Git.Run(cmd,&vector))
{
return -1;
}
list.ParserFromLsFile(vector);
return 0;
}
示例15: GetTagList
int CGit::GetTagList(STRING_VECTOR &list)
{
int ret;
CString cmd,output;
cmd=_T("git.exe tag -l");
int i=0;
ret=g_Git.Run(cmd,&output,CP_UTF8);
if(!ret)
{
int pos=0;
CString one;
while( pos>=0 )
{
i++;
one=output.Tokenize(_T("\n"),pos);
list.push_back(one);
}
}
return ret;
}