bool PullCommand::Execute() { CPullFetchDlg dlg; dlg.m_IsPull=TRUE; if(dlg.DoModal()==IDOK) { CString url; url=dlg.m_RemoteURL; CString cmd; cmd.Format(_T("git.exe pull \"%s\" %s"),url,dlg.m_RemoteBranchName); CProgressDlg progress; progress.m_GitCmd=cmd; if(progress.DoModal()==IDOK) return TRUE; } #if 0 CCloneDlg dlg; dlg.m_Directory=this->orgCmdLinePath.GetWinPathString(); if(dlg.DoModal()==IDOK) { CString dir=dlg.m_Directory; CString url=dlg.m_URL; CString cmd; cmd.Format(_T("git.exe clone %s %s"), url, dir); CProgressDlg progress; progress.m_GitCmd=cmd; if(progress.DoModal()==IDOK) return TRUE; } #endif return FALSE; }
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 ) { 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 "), dlg.m_strBranch); dlg.m_strPath.Replace(_T('\\'),_T('/')); dlg.m_strRepos.Replace(_T('\\'),_T('/')); cmd.Format(_T("git.exe submodule add %s -- \"%s\" \"%s\""), branch, dlg.m_strRepos, dlg.m_strPath); CProgressDlg progress; progress.m_GitCmd=cmd; progress.DoModal(); bRet = TRUE; } return bRet; }
bool SVNIgnoreCommand::Execute() { CSVNIgnoreTypeDlg dlg; CProgressDlg progress; if( dlg.DoModal() == IDOK) { switch (dlg.m_SVNIgnoreType) { case 0: { progress.m_GitCmd = _T("git.exe svn show-ignore"); CString dotGitPath; GitAdminDir::GetAdminDirPath(g_Git.m_CurrentDir, dotGitPath); progress.m_LogFile = dotGitPath + _T("info\\exclude"); progress.m_bShowCommand = false; progress.m_PreText = _T("git.exe svn show-ignore > ") + progress.m_LogFile; } break; case 1: progress.m_GitCmd=_T("git.exe svn create-ignore"); break; default: CMessageBox::Show(NULL,_T("Unkown SVN Ignore Type"),_T("TortoiseGit"),MB_OK|MB_ICONERROR); return FALSE; } if (progress.DoModal() == IDOK) return progress.m_GitStatus == 0; } return false; }
bool FormatPatchCommand::Execute() { CFormatPatchDlg dlg; // dlg.m_bIsTag=TRUE; CString startval = parser.GetVal(L"startrev"); CString endval = parser.GetVal(L"endrev"); if( endval.IsEmpty() && (!startval.IsEmpty())) { dlg.m_Since=startval; dlg.m_Radio = IDC_RADIO_SINCE; } else if( (!endval.IsEmpty()) && (!startval.IsEmpty())) { dlg.m_From=startval; dlg.m_To=endval; dlg.m_Radio = IDC_RADIO_RANGE; } if(dlg.DoModal()==IDOK) { CString cmd; CString range; switch(dlg.m_Radio) { case IDC_RADIO_SINCE: range=g_Git.FixBranchName(dlg.m_Since); break; case IDC_RADIO_NUM: range.Format(L"-%d", dlg.m_Num); break; case IDC_RADIO_RANGE: range.Format(L"%s..%s", (LPCTSTR)dlg.m_From, (LPCTSTR)dlg.m_To); break; } dlg.m_Dir.Replace(L'\\', L'/'); cmd.Format(L"git.exe format-patch%s -o \"%s\" %s", dlg.m_bNoPrefix ? L" --no-prefix" : L"", (LPCTSTR)dlg.m_Dir, (LPCTSTR)range ); CProgressDlg progress; progress.m_GitCmd=cmd; progress.DoModal(); CShellUpdater::Instance().AddPathForUpdate(CTGitPath(dlg.m_Dir)); CShellUpdater::Instance().Flush(); if(!progress.m_GitStatus) { if(dlg.m_bSendMail) CAppUtils::SendPatchMail(cmd, progress.m_LogText, true); } return !progress.m_GitStatus; } return FALSE; }
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; }
bool SubmoduleUpdateCommand::Execute() { CString bkpath; if (parser.HasKey(_T("bkpath"))) bkpath = parser.GetVal(_T("bkpath")); else { bkpath = this->orgPathList[0].GetWinPathString(); int start = bkpath.ReverseFind(_T('\\')); if (start >= 0) bkpath = bkpath.Left(start); } CString super = g_GitAdminDir.GetSuperProjectRoot(bkpath); if (super.IsEmpty()) { CMessageBox::Show(NULL,IDS_ERR_NOTFOUND_SUPER_PRJECT,IDS_APPNAME,MB_OK|MB_ICONERROR); //change current project root to super project return false; } CSubmoduleUpdateDlg submoduleUpdateDlg; if (submoduleUpdateDlg.DoModal() != IDOK) return false; CProgressDlg progress; g_Git.m_CurrentDir = super; CString params; if (submoduleUpdateDlg.m_bInit) params = _T(" --init"); if (submoduleUpdateDlg.m_bRecursive) params += _T(" --recursive"); for (int i = 0; i < this->orgPathList.GetCount(); i++) { if (orgPathList[i].IsDirectory()) { CString str; str.Format(_T("git.exe submodule update%s \"%s\""), params, ((CTGitPath &)orgPathList[i]).GetSubPath(CTGitPath(super)).GetGitPathString()); progress.m_GitCmdList.push_back(str); } } progress.DoModal(); return !progress.m_GitStatus; }
bool SubmoduleCommand::Execute(CString cmd, CString arg) { CProgressDlg progress; CString bkpath; if(parser.HasKey(_T("bkpath"))) { bkpath=parser.GetVal(_T("bkpath")); } else { bkpath=this->orgPathList[0].GetWinPathString(); int start = bkpath.ReverseFind(_T('\\')); if( start >= 0 ) bkpath=bkpath.Left(start); } CString super=g_GitAdminDir.GetSuperProjectRoot( bkpath ); if(super.IsEmpty()) { CMessageBox::Show(NULL,IDS_ERR_NOTFOUND_SUPER_PRJECT,IDS_APPNAME,MB_OK|MB_ICONERROR); //change current project root to super project return false; } g_Git.m_CurrentDir=super; progress.m_Title.Format(_T("Submodule %s"),cmd); //progress.m_GitCmd.Format(_T("git.exe submodule update --init ")); CString str; for(int i=0;i<this->orgPathList.GetCount();i++) { if(orgPathList[i].IsDirectory()) { str.Format(_T("git.exe submodule %s %s \"%s\""),cmd,arg, ((CTGitPath &)orgPathList[i]).GetSubPath(CTGitPath(super)).GetGitPathString()); progress.m_GitCmdList.push_back(str); } } progress.DoModal(); return !progress.m_GitStatus; }
bool CloneCommand::Execute() { CTGitPath cloneDirectory; if (!parser.HasKey(_T("hasurlhandler"))) { if (orgCmdLinePath.IsEmpty()) { cloneDirectory.SetFromWin(sOrigCWD, true); DWORD len = ::GetTempPath(0, nullptr); auto tszPath = std::make_unique<TCHAR[]>(len); ::GetTempPath(len, tszPath.get()); if (_tcsncicmp(cloneDirectory.GetWinPath(), tszPath.get(), len-2 /* \\ and \0 */) == 0) { // if the current directory is set to a temp directory, // we don't use that but leave it empty instead. cloneDirectory.Reset(); } } else cloneDirectory = orgCmdLinePath; } CCloneDlg dlg; dlg.m_Directory = cloneDirectory.GetWinPathString(); if (parser.HasKey(_T("url"))) dlg.m_URL = parser.GetVal(_T("url")); if (parser.HasKey(_T("exactpath"))) dlg.m_bExactPath = TRUE; if(dlg.DoModal()==IDOK) { CString recursiveStr; if(dlg.m_bRecursive) recursiveStr = _T(" --recursive"); CString bareStr; if(dlg.m_bBare) bareStr = _T(" --bare"); CString nocheckoutStr; if (dlg.m_bNoCheckout) nocheckoutStr = _T(" --no-checkout"); CString branchStr; if (dlg.m_bBranch) branchStr = _T(" --branch ") + dlg.m_strBranch; CString originStr; if (dlg.m_bOrigin && !dlg.m_bSVN) originStr = _T(" --origin ") + dlg.m_strOrigin; if(dlg.m_bAutoloadPuttyKeyFile) { CAppUtils::LaunchPAgent(&dlg.m_strPuttyKeyFile); } CAppUtils::RemoveTrailSlash(dlg.m_Directory); if (!dlg.m_bSVN) CAppUtils::RemoveTrailSlash(dlg.m_URL); CString dir=dlg.m_Directory; CString url=dlg.m_URL; // is this a windows format UNC path, ie starts with \\? if (url.Find(_T("\\\\")) == 0) { // yes, change all \ to / // this should not be necessary but msysgit does not support the use \ here yet int atSign = url.Find(_T('@')); if (atSign > 0) { CString path = url.Mid(atSign); path.Replace(_T('\\'), _T('/')); url = url.Mid(0, atSign) + path; } else url.Replace( _T('\\'), _T('/')); } CString depth; if (dlg.m_bDepth) { depth.Format(_T(" --depth %d"),dlg.m_nDepth); } CString cmd; cmd.Format(_T("git.exe clone --progress%s%s%s%s%s -v%s \"%s\" \"%s\""), (LPCTSTR)nocheckoutStr, (LPCTSTR)recursiveStr, (LPCTSTR)bareStr, (LPCTSTR)branchStr, (LPCTSTR)originStr, (LPCTSTR)depth, (LPCTSTR)url, (LPCTSTR)dir); bool retry = false; auto postCmdCallback = [&](DWORD status, PostCmdList& postCmdList) { if (status) { postCmdList.emplace_back(IDI_REFRESH, IDS_MSGBOX_RETRY, [&]{ retry = true; }); return; } // After cloning, change current directory to the cloned directory g_Git.m_CurrentDir = dlg.m_Directory; if (dlg.m_bAutoloadPuttyKeyFile) // do this here, since it might be needed for actions performed in Log StorePuttyKey(dlg.m_Directory, dlg.m_bOrigin && !dlg.m_strOrigin.IsEmpty() ? dlg.m_strOrigin : _T("origin"), dlg.m_strPuttyKeyFile); postCmdList.emplace_back(IDI_LOG, IDS_MENULOG, [&] { CString cmd = _T("/command:log"); cmd += _T(" /path:\"") + dlg.m_Directory + _T("\""); CAppUtils::RunTortoiseGitProc(cmd); }); postCmdList.emplace_back(IDI_EXPLORER, IDS_STATUSLIST_CONTEXT_EXPLORE, [&]{ CAppUtils::ExploreTo(hWndExplorer, dlg.m_Directory); }); }; // Handle Git SVN-clone if(dlg.m_bSVN) { //g_Git.m_CurrentDir=dlg.m_Directory; cmd.Format(_T("git.exe svn clone \"%s\" \"%s\""), (LPCTSTR)url, (LPCTSTR)dlg.m_Directory); if (dlg.m_bOrigin) { CString str; if (dlg.m_strOrigin.IsEmpty()) str = _T(" --prefix \"\""); else str.Format(_T(" --prefix \"%s/\""), (LPCTSTR)dlg.m_strOrigin); cmd += str; } if(dlg.m_bSVNTrunk) cmd+=_T(" -T ")+dlg.m_strSVNTrunk; if(dlg.m_bSVNBranch) cmd+=_T(" -b ")+dlg.m_strSVNBranchs; if(dlg.m_bSVNTags) cmd+=_T(" -t ")+dlg.m_strSVNTags; if(dlg.m_bSVNFrom) { CString str; str.Format(_T("%d:HEAD"),dlg.m_nSVNFrom); cmd+=_T(" -r ")+str; } if(dlg.m_bSVNUserName) { cmd+= _T(" --username "); cmd+=dlg.m_strUserName; } } else { if (g_Git.UsingLibGit2(CGit::GIT_CMD_CLONE)) { while (true) { retry = false; CGitProgressDlg GitDlg; CTGitPathList list; g_Git.m_CurrentDir = GetExistingDirectoryForClone(dlg.m_Directory); list.AddPath(CTGitPath(dir)); CloneProgressCommand cloneProgressCommand; GitDlg.SetCommand(&cloneProgressCommand); cloneProgressCommand.m_PostCmdCallback = postCmdCallback; cloneProgressCommand.SetUrl(url); cloneProgressCommand.SetPathList(list); cloneProgressCommand.SetIsBare(dlg.m_bBare == TRUE); if (dlg.m_bBranch) cloneProgressCommand.SetRefSpec(dlg.m_strBranch); if (dlg.m_bOrigin) cloneProgressCommand.SetRemote(dlg.m_strOrigin); cloneProgressCommand.SetNoCheckout(dlg.m_bNoCheckout == TRUE); GitDlg.DoModal(); if (!retry) return !GitDlg.DidErrorsOccur(); } } } while (true) { retry = false; g_Git.m_CurrentDir = GetExistingDirectoryForClone(dlg.m_Directory); CProgressDlg progress; progress.m_GitCmd=cmd; progress.m_PostCmdCallback = postCmdCallback; INT_PTR ret = progress.DoModal(); if (!retry) return ret == IDOK; } } return FALSE; }
static bool DoCleanUp(const CTGitPathList& pathList, int cleanType, bool bDir, bool bSubmodules, bool bDryRun, bool bNoRecycleBin) { CString cmd; cmd.Format(_T("git.exe clean")); if (bDryRun || !bNoRecycleBin) cmd += _T(" -n "); if (bDir) cmd += _T(" -d "); switch (cleanType) { case 0: cmd += _T(" -fx"); break; case 1: cmd += _T(" -f"); break; case 2: cmd += _T(" -fX"); break; } STRING_VECTOR submoduleList; if (bSubmodules) { SubmodulePayload payload(submoduleList); payload.basePath = CTGitPath(g_Git.m_CurrentDir).GetGitPathString(); if (pathList.GetCount() != 1 || pathList.GetCount() == 1 && !pathList[0].IsEmpty()) { for (int i = 0; i < pathList.GetCount(); ++i) { CString path; if (pathList[i].IsDirectory()) payload.prefixList.push_back(pathList[i].GetGitPathString()); else payload.prefixList.push_back(pathList[i].GetContainingDirectory().GetGitPathString()); } } if (!GetSubmodulePathList(payload)) return false; std::sort(submoduleList.begin(), submoduleList.end()); } if (bDryRun || bNoRecycleBin) { CProgressDlg progress; for (int i = 0; i < pathList.GetCount(); ++i) { CString path; if (pathList[i].IsDirectory()) path = pathList[i].GetGitPathString(); else path = pathList[i].GetContainingDirectory().GetGitPathString(); progress.m_GitDirList.push_back(g_Git.m_CurrentDir); progress.m_GitCmdList.push_back(cmd + _T(" -- \"") + path + _T("\"")); } for (CString dir : submoduleList) { progress.m_GitDirList.push_back(CTGitPath(dir).GetWinPathString()); progress.m_GitCmdList.push_back(cmd); } progress.m_PostCmdCallback = [&](DWORD status, PostCmdList& postCmdList) { if (status) postCmdList.push_back(PostCmd(IDS_MSGBOX_RETRY, [&] { DoCleanUp(pathList, cleanType, bDir, bSubmodules, bDryRun, bNoRecycleBin); })); if (status || !bDryRun) return; if (bNoRecycleBin) { postCmdList.push_back(PostCmd(IDS_CLEAN_NO_RECYCLEBIN, [&] { DoCleanUp(pathList, cleanType, bDir, bSubmodules, FALSE, TRUE); })); postCmdList.push_back(PostCmd(IDS_CLEAN_TO_RECYCLEBIN, [&] { DoCleanUp(pathList, cleanType, bDir, bSubmodules, FALSE, FALSE); })); } else { postCmdList.push_back(PostCmd(IDS_CLEAN_TO_RECYCLEBIN, [&] { DoCleanUp(pathList, cleanType, bDir, bSubmodules, FALSE, FALSE); })); postCmdList.push_back(PostCmd(IDS_CLEAN_NO_RECYCLEBIN, [&] { DoCleanUp(pathList, cleanType, bDir, bSubmodules, FALSE, TRUE); })); } }; INT_PTR result = progress.DoModal(); return result == IDOK; } else { CSysProgressDlg sysProgressDlg; sysProgressDlg.SetAnimation(IDR_CLEANUPANI); sysProgressDlg.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME))); sysProgressDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_CLEANUP_INFO1))); sysProgressDlg.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT))); sysProgressDlg.SetShowProgressBar(false); sysProgressDlg.ShowModeless((HWND)NULL, true); bool quotepath = g_Git.GetConfigValueBool(_T("core.quotepath")); CTGitPathList delList; for (int i = 0; i < pathList.GetCount(); ++i) { CString path; if (pathList[i].IsDirectory()) path = pathList[i].GetGitPathString(); else path = pathList[i].GetContainingDirectory().GetGitPathString(); if (!GetFilesToCleanUp(delList, cmd, &g_Git, path, quotepath, sysProgressDlg)) return false; } for (CString dir : submoduleList) { CGit git; git.m_CurrentDir = dir; if (!GetFilesToCleanUp(delList, cmd, &git, _T(""), quotepath, sysProgressDlg)) return false; } delList.DeleteAllFiles(true, false, true); sysProgressDlg.Stop(); } return true; }
bool SVNFetchCommand::Execute() { CString cmd, out, err; cmd = _T("git.exe config svn-remote.svn.fetch"); if (!g_Git.Run(cmd, &out, &err, CP_UTF8)) { int start = out.Find(_T(':')); if( start >=0 ) out=out.Mid(start); if(out.Left(5) == _T(":refs")) out=out.Mid(6); start = 0; out=out.Tokenize(_T("\n"),start); } else { MessageBox(hwndExplorer, L"Found no SVN remote.", L"TortoiseGit", MB_OK | MB_ICONERROR); return false; } CGitHash upstreamOldHash; if (g_Git.GetHash(upstreamOldHash, out)) { MessageBox(hwndExplorer, g_Git.GetGitLastErr(_T("Could not get upstream hash.")), _T("TortoiseGit"), MB_ICONERROR); return false; } CProgressDlg progress; progress.m_GitCmd=_T("git.exe svn fetch"); CGitHash upstreamNewHash; // declare outside lambda, because it is captured by reference progress.m_PostCmdCallback = [&](DWORD status, PostCmdList& postCmdList) { if (status) return; if (g_Git.GetHash(upstreamNewHash, out)) { MessageBox(hwndExplorer, g_Git.GetGitLastErr(_T("Could not get upstream hash after fetching.")), _T("TortoiseGit"), MB_ICONERROR); return; } if (upstreamOldHash == upstreamNewHash) return; postCmdList.emplace_back(IDI_DIFF, _T("Fetched Diff"), [&] { CLogDlg dlg; dlg.SetParams(CTGitPath(_T("")), CTGitPath(_T("")), _T(""), upstreamOldHash.ToString() + _T("..") + upstreamNewHash.ToString(), 0); dlg.DoModal(); }); postCmdList.emplace_back(IDI_LOG, _T("Fetched Log"), [&] { CFileDiffDlg dlg; dlg.SetDiff(nullptr, upstreamNewHash.ToString(), upstreamOldHash.ToString()); dlg.DoModal(); }); }; return progress.DoModal() == IDOK; }
void CPhotoPubDoc::OnMultithumb() { char szDir[MAX_PATH]; BROWSEINFO bi; ITEMIDLIST *pidl; bi.hwndOwner = NULL; bi.pidlRoot = NULL; bi.pszDisplayName = szDir; bi.lpszTitle = "请选择多个照片文件夹的上层文件夹:"; bi.ulFlags = BIF_RETURNONLYFSDIRS; bi.lpfn = NULL; bi.lParam = 0; bi.iImage = 0; pidl = SHBrowseForFolder(&bi); if(pidl == NULL) return ; if(!SHGetPathFromIDList(pidl, szDir)) return ; CString SrcPath(szDir); int n=CountAllFolderFile(SrcPath,"*.jpg"); if (n) { AfxMessageBox("主文件夹包含了图片,请重新组织,编入子文件夹。"); return; } CStringArray sizelist; sizelist.Add("1寸"); sizelist.Add("2寸"); CSizeDlg sizeDlg(NULL,"预览照片",sizelist); if (IDCANCEL==sizeDlg.DoModal()) return; CString size=sizeDlg.m_Size.Left(1); // CString TarPath(SrcPath+"\\A4缩略图"); CString TarPath; CInputStrDlg DirDlg(NULL,"目标文件夹名称", size+"寸照片A4缩略图"); do { if (IDCANCEL==DirDlg.DoModal()) return; else { TarPath=SrcPath+"\\"+DirDlg.m_input; } } while(CreateDirectory(TarPath, NULL)?false:(true,AfxMessageBox("该文件夹已经存在,请另外指定文件夹名称!"))); //CPage::A4PreView(SrcPath,TarPath); CProgressDlg ProgDlg; ProgDlg.page=m_pPageSetting; ProgDlg.srcPath=SrcPath; ProgDlg.tarPath=TarPath; ProgDlg.title="生成缩略图"; ProgDlg.photosize=size; ProgDlg.pThread = AfxBeginThread(MultiA4PreviewThreadProc, &ProgDlg, THREAD_PRIORITY_NORMAL); ProgDlg.DoModal(); }
void CPhotoPubDoc::OnBnClickedBatchPub() { char szDir[MAX_PATH]; BROWSEINFO bi; ITEMIDLIST *pidl; bi.hwndOwner = NULL; bi.pidlRoot = NULL; bi.pszDisplayName = szDir; bi.lpszTitle = "请选择照片所在的文件夹:"; bi.ulFlags = BIF_RETURNONLYFSDIRS; bi.lpfn = NULL; bi.lParam = 0; bi.iImage = 0; pidl = SHBrowseForFolder(&bi); if(pidl == NULL) return ; if(!SHGetPathFromIDList(pidl, szDir)) return ; CString SrcPath(szDir); int n=CountAllFolderFile(SrcPath,"*.jpg"); if (!n) { AfxMessageBox("该文件夹中没有JPG文件!"); return; } CPgSelectDlg dlg(AfxGetApp()->GetMainWnd(),m_PreDefinedPages,m_pOpenedImage!=NULL); if (IDCANCEL==dlg.DoModal()) { return; }else{ m_pPageSetting=dlg.m_pCurrentPageSetting; }; //CString TarPath(SrcPath+"\\排版"); CString TarPath; CInputStrDlg DirDlg(NULL,"目标文件夹名称", m_pPageSetting->m_SizeDiscription+"底板"+m_pPageSetting->m_PageDiscription); do { if (IDCANCEL==DirDlg.DoModal()) return; else { TarPath=SrcPath+"\\"+DirDlg.m_input; } } while(CreateDirectory(TarPath, NULL)?false:(true,AfxMessageBox("该文件夹已经存在,请另外指定文件夹名称!"))); CProgressDlg ProgDlg; ProgDlg.page=m_pPageSetting; ProgDlg.srcPath=SrcPath; ProgDlg.tarPath=TarPath; ProgDlg.title="排版"; ProgDlg.pThread = AfxBeginThread(PublishDirThreadProc, &ProgDlg, THREAD_PRIORITY_NORMAL); ProgDlg.DoModal(); }
bool PullCommand::Execute() { if (!GitAdminDir().HasAdminDir(g_Git.m_CurrentDir)) { CMessageBox::Show(hwndExplorer, IDS_NOWORKINGCOPY, IDS_APPNAME, MB_ICONERROR); return false; } CPullFetchDlg dlg; dlg.m_IsPull=TRUE; if(dlg.DoModal()==IDOK) { CString url; url=dlg.m_RemoteURL; if(dlg.m_bAutoLoad) { CAppUtils::LaunchPAgent(NULL,&dlg.m_RemoteURL); } CString cmd; CGitHash hashOld; if (g_Git.GetHash(hashOld, _T("HEAD"))) { MessageBox(hwndExplorer, g_Git.GetGitLastErr(_T("Could not get HEAD hash.")), _T("TortoiseGit"), MB_ICONERROR); return false; } CString cmdRebase; if(dlg.m_bRebase) cmdRebase = "--rebase "; CString noff; CString ffonly; CString squash; CString nocommit; CString notags; if (!dlg.m_bFetchTags) notags = _T("--no-tags"); if(dlg.m_bNoFF) noff=_T("--no-ff"); if (dlg.m_bFFonly) ffonly = _T("--ff-only"); if(dlg.m_bSquash) squash=_T("--squash"); if(dlg.m_bNoCommit) nocommit=_T("--no-commit"); int ver = CAppUtils::GetMsysgitVersion(); if(ver >= 0x01070203) //above 1.7.0.2 cmdRebase += _T("--progress "); cmd.Format(_T("git.exe pull -v %s %s %s %s %s %s \"%s\" %s"), cmdRebase, noff, ffonly, squash, nocommit, notags, url, dlg.m_RemoteBranchName); CProgressDlg progress; progress.m_GitCmd = cmd; progress.m_PostCmdList.Add(CString(MAKEINTRESOURCE(IDS_PROC_PULL_DIFFS))); progress.m_PostCmdList.Add(CString(MAKEINTRESOURCE(IDS_PROC_PULL_LOG))); CTGitPath gitPath = g_Git.m_CurrentDir; if (gitPath.HasSubmodules()) progress.m_PostCmdList.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE))); //progress.m_PostCmdList.Add(_T("Show Conflict")); if (parser.HasVal(_T("closeonend"))) progress.m_bAutoCloseOnSuccess = !!parser.GetLongVal(_T("closeonend")); INT_PTR ret = progress.DoModal(); if (ret == IDOK && progress.m_GitStatus == 1 && progress.m_LogText.Find(_T("CONFLICT")) >= 0 && CMessageBox::Show(NULL, IDS_SEECHANGES, IDS_APPNAME, MB_YESNO | MB_ICONINFORMATION) == IDYES) { CChangedDlg dlg; dlg.m_pathList.AddPath(CTGitPath()); dlg.DoModal(); return FALSE; } CGitHash hashNew; if (g_Git.GetHash(hashNew, L"HEAD")) { MessageBox(hwndExplorer, g_Git.GetGitLastErr(_T("Could not get HEAD hash after pulling.")), _T("TortoiseGit"), MB_ICONERROR); return FALSE; } if( ret == IDC_PROGRESS_BUTTON1) { if(hashOld == hashNew) { if(progress.m_GitStatus == 0) CMessageBox::Show(NULL, IDS_UPTODATE, IDS_APPNAME, MB_OK | MB_ICONINFORMATION); return TRUE; } CFileDiffDlg dlg; dlg.SetDiff(NULL, hashNew.ToString(), hashOld.ToString()); dlg.DoModal(); return TRUE; } else if ( ret == IDC_PROGRESS_BUTTON1 +1 ) { if(hashOld == hashNew) { if(progress.m_GitStatus == 0) CMessageBox::Show(NULL, IDS_UPTODATE, IDS_APPNAME, MB_OK | MB_ICONINFORMATION); return TRUE; } CLogDlg dlg; //dlg.SetParams(cmdLinePath); dlg.SetParams(CTGitPath(_T("")), CTGitPath(_T("")), _T(""), hashOld.ToString() + _T("..") + hashNew.ToString(), 0); // dlg.SetIncludeMerge(!!parser.HasKey(_T("merge"))); // val = parser.GetVal(_T("propspath")); // if (!val.IsEmpty()) // dlg.SetProjectPropertiesPath(CTSVNPath(val)); dlg.DoModal(); } else if (ret == IDC_PROGRESS_BUTTON1 + 2 && gitPath.HasSubmodules()) { CString sCmd; sCmd.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git.m_CurrentDir); CAppUtils::RunTortoiseGitProc(sCmd); } } return FALSE; }
bool CleanupCommand::Execute() { bool bRet = false; CCleanTypeDlg dlg; if( dlg.DoModal() == IDOK) { bool quotepath = g_Git.GetConfigValueBool(_T("core.quotepath")); CString cmd; cmd.Format(_T("git clean")); if (dlg.m_bDryRun || !dlg.m_bNoRecycleBin) cmd += _T(" -n "); if(dlg.m_bDir) cmd += _T(" -d "); switch(dlg.m_CleanType) { case 0: cmd += _T(" -fx"); break; case 1: cmd += _T(" -f"); break; case 2: cmd += _T(" -fX"); break; } if (dlg.m_bDryRun || dlg.m_bNoRecycleBin) { CProgressDlg progress; for (int i = 0; i < this->pathList.GetCount(); ++i) { CString path; if (this->pathList[i].IsDirectory()) path = pathList[i].GetGitPathString(); else path = pathList[i].GetContainingDirectory().GetGitPathString(); progress.m_GitCmdList.push_back(cmd + _T(" \"") + path + _T("\"")); } if (progress.DoModal()==IDOK) return TRUE; } else { CSysProgressDlg sysProgressDlg; sysProgressDlg.SetAnimation(IDR_CLEANUPANI); sysProgressDlg.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME))); sysProgressDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_CLEANUP_INFO1))); sysProgressDlg.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT))); sysProgressDlg.SetShowProgressBar(false); sysProgressDlg.ShowModeless((HWND)NULL, true); CString cmdout, cmdouterr; if (g_Git.Run(cmd, &cmdout, &cmdouterr, CP_UTF8)) { MessageBox(NULL, cmdouterr, _T("TortoiseGit"), MB_ICONERROR); return FALSE; } if (sysProgressDlg.HasUserCancelled()) { CMessageBox::Show(NULL, IDS_SVN_USERCANCELLED, IDS_APPNAME, MB_OK); return FALSE; } int pos = 0; CString token = cmdout.Tokenize(_T("\n"), pos); CTGitPathList delList; while (!token.IsEmpty()) { if (token.Mid(0, 13) == _T("Would remove ")) { CString tempPath = token.Mid(13).TrimRight(); if (quotepath) { tempPath = UnescapeQuotePath(tempPath.Trim(_T('"'))); } delList.AddPath(CTGitPath(tempPath)); } token = cmdout.Tokenize(_T("\n"), pos); } if (sysProgressDlg.HasUserCancelled()) { CMessageBox::Show(NULL, IDS_SVN_USERCANCELLED, IDS_APPNAME, MB_OK); return FALSE; } delList.DeleteAllFiles(true, false); sysProgressDlg.Stop(); } } #if 0 CProgressDlg progress; progress.SetTitle(IDS_PROC_CLEANUP); progress.SetAnimation(IDR_CLEANUPANI); progress.SetShowProgressBar(false); progress.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_CLEANUP_INFO1))); progress.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROC_CLEANUP_INFO2))); progress.ShowModeless(hwndExplorer); CString strSuccessfullPaths, strFailedPaths; for (int i=0; i<pathList.GetCount(); ++i) { SVN svn; if (!svn.CleanUp(pathList[i])) { strFailedPaths += _T("- ") + pathList[i].GetWinPathString() + _T("\n"); strFailedPaths += svn.GetLastErrorMessage() + _T("\n\n"); } else { strSuccessfullPaths += _T("- ") + pathList[i].GetWinPathString() + _T("\n"); // after the cleanup has finished, crawl the path downwards and send a change // notification for every directory to the shell. This will update the // overlays in the left tree view of the explorer. CDirFileEnum crawler(pathList[i].GetWinPathString()); CString sPath; bool bDir = false; CTSVNPathList updateList; while (crawler.NextFile(sPath, &bDir)) { if ((bDir) && (!g_SVNAdminDir.IsAdminDirPath(sPath))) { updateList.AddPath(CTSVNPath(sPath)); } } updateList.AddPath(pathList[i]); CShellUpdater::Instance().AddPathsForUpdate(updateList); CShellUpdater::Instance().Flush(); updateList.SortByPathname(true); for (INT_PTR i=0; i<updateList.GetCount(); ++i) { SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH, updateList[i].GetWinPath(), NULL); ATLTRACE(_T("notify change for path %s\n"), updateList[i].GetWinPath()); } } } progress.Stop(); CString strMessage; if ( !strSuccessfullPaths.IsEmpty() ) { CString tmp; tmp.Format(IDS_PROC_CLEANUPFINISHED, (LPCTSTR)strSuccessfullPaths); strMessage += tmp; bRet = true; } if ( !strFailedPaths.IsEmpty() ) { if (!strMessage.IsEmpty()) strMessage += _T("\n"); CString tmp; tmp.Format(IDS_PROC_CLEANUPFINISHED_FAILED, (LPCTSTR)strFailedPaths); strMessage += tmp; bRet = false; } CMessageBox::Show(hwndExplorer, strMessage, _T("TortoiseGit"), MB_OK | (strFailedPaths.IsEmpty()?MB_ICONINFORMATION:MB_ICONERROR)); #endif CShellUpdater::Instance().Flush(); return bRet; }
bool CloneCommand::Execute() { CCloneDlg dlg; dlg.m_Directory=this->orgCmdLinePath.GetWinPathString(); if (parser.HasKey(_T("url"))) dlg.m_URL = parser.GetVal(_T("url")); if(dlg.DoModal()==IDOK) { CString recursiveStr; if(dlg.m_bRecursive) recursiveStr = _T("--recursive"); else recursiveStr = _T(""); CString bareStr; if(dlg.m_bBare) bareStr = _T("--bare"); else bareStr = _T(""); if(dlg.m_bAutoloadPuttyKeyFile) { CAppUtils::LaunchPAgent(&dlg.m_strPuttyKeyFile); } CAppUtils::RemoveTrailSlash(dlg.m_Directory); CAppUtils::RemoveTrailSlash(dlg.m_URL); CString dir=dlg.m_Directory; CString url=dlg.m_URL; // is this a windows format UNC path, ie starts with \\? if (url.Find(_T("\\\\")) == 0) { // yes, change all \ to / // this should not be necessary but msysgit does not support the use \ here yet int atSign = url.Find(_T('@')); if (atSign > 0) { CString path = url.Mid(atSign); path.Replace(_T('\\'), _T('/')); url = url.Mid(0, atSign) + path; } else url.Replace( _T('\\'), _T('/')); } CString depth; if (dlg.m_bDepth) { depth.Format(_T(" --depth %d"),dlg.m_nDepth); } g_Git.m_CurrentDir = this->orgCmdLinePath.GetWinPathString(); CString cmd; CString progressarg; int ver = CAppUtils::GetMsysgitVersion(); if(ver >= 0x01070002) //above 1.7.0.2 progressarg = _T("--progress"); cmd.Format(_T("git.exe clone %s %s %s -v %s \"%s\" \"%s\""), recursiveStr, bareStr, progressarg, depth, url, dir); // Handle Git SVN-clone if(dlg.m_bSVN) { //g_Git.m_CurrentDir=dlg.m_Directory; cmd.Format(_T("git.exe svn clone \"%s\" \"%s\""), url,dlg.m_Directory); if(dlg.m_bSVNTrunk) cmd+=_T(" -T ")+dlg.m_strSVNTrunk; if(dlg.m_bSVNBranch) cmd+=_T(" -b ")+dlg.m_strSVNBranchs; if(dlg.m_bSVNTags) cmd+=_T(" -t ")+dlg.m_strSVNTags; if(dlg.m_bSVNFrom) { CString str; str.Format(_T("%d:HEAD"),dlg.m_nSVNFrom); cmd+=_T(" -r ")+str; } if(dlg.m_bSVNUserName) { cmd+= _T(" --username "); cmd+=dlg.m_strUserName; } } CProgressDlg progress; progress.m_GitCmd=cmd; int ret = progress.DoModal(); if( progress.m_GitStatus == 0) { if(dlg.m_bAutoloadPuttyKeyFile) { g_Git.m_CurrentDir = dlg.m_Directory; SetCurrentDirectory(g_Git.m_CurrentDir); if(g_Git.SetConfigValue(_T("remote.origin.puttykeyfile"), dlg.m_strPuttyKeyFile, CONFIG_LOCAL, CP_UTF8, &dlg.m_Directory)) { CMessageBox::Show(NULL,_T("Fail set config remote.origin.puttykeyfile"),_T("TortoiseGit"),MB_OK|MB_ICONERROR); return FALSE; } } } if(ret == IDOK) return TRUE; } return FALSE; }
BOOL CRebaseDlg::OnInitDialog() { CResizableStandAloneDialog::OnInitDialog(); CAppUtils::MarkWindowAsUnpinnable(m_hWnd); // Let the TaskbarButtonCreated message through the UIPI filter. If we don't // do this, Explorer would be unable to send that message to our window if we // were running elevated. It's OK to make the call all the time, since if we're // not elevated, this is a no-op. CHANGEFILTERSTRUCT cfs = { sizeof(CHANGEFILTERSTRUCT) }; typedef BOOL STDAPICALLTYPE ChangeWindowMessageFilterExDFN(HWND hWnd, UINT message, DWORD action, PCHANGEFILTERSTRUCT pChangeFilterStruct); CAutoLibrary hUser = ::LoadLibrary(_T("user32.dll")); if (hUser) { ChangeWindowMessageFilterExDFN *pfnChangeWindowMessageFilterEx = (ChangeWindowMessageFilterExDFN*)GetProcAddress(hUser, "ChangeWindowMessageFilterEx"); if (pfnChangeWindowMessageFilterEx) { pfnChangeWindowMessageFilterEx(m_hWnd, WM_TASKBARBTNCREATED, MSGFLT_ALLOW, &cfs); } } m_pTaskbarList.Release(); m_pTaskbarList.CoCreateInstance(CLSID_TaskbarList); CRect rectDummy; //IDC_REBASE_DUMY_TAB GetClientRect(m_DlgOrigRect); m_CommitList.GetClientRect(m_CommitListOrigRect); CWnd *pwnd=this->GetDlgItem(IDC_REBASE_DUMY_TAB); pwnd->GetWindowRect(&rectDummy); this->ScreenToClient(rectDummy); if (!m_ctrlTabCtrl.Create(CMFCTabCtrl::STYLE_FLAT, rectDummy, this, IDC_REBASE_TAB)) { TRACE0("Failed to create output tab window\n"); return FALSE; // fail to create } m_ctrlTabCtrl.SetResizeMode(CMFCTabCtrl::RESIZE_NO); // Create output panes: //const DWORD dwStyle = LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL; DWORD dwStyle =LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP | WS_CHILD | WS_VISIBLE; if (! this->m_FileListCtrl.Create(dwStyle,rectDummy,&this->m_ctrlTabCtrl,0) ) { TRACE0("Failed to create output windows\n"); return FALSE; // fail to create } if( ! this->m_LogMessageCtrl.Create(_T("Scintilla"),_T("source"),0,rectDummy,&m_ctrlTabCtrl,0,0) ) { TRACE0("Failed to create log message control"); return FALSE; } m_LogMessageCtrl.Init(0); m_LogMessageCtrl.Call(SCI_SETREADONLY, TRUE); dwStyle = LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL; if (!m_wndOutputRebase.Create(_T("Scintilla"),_T("source"),0,rectDummy, &m_ctrlTabCtrl, 0,0) ) { TRACE0("Failed to create output windows\n"); return -1; // fail to create } m_wndOutputRebase.Init(0); m_wndOutputRebase.Call(SCI_SETREADONLY, TRUE); m_tooltips.Create(this); m_tooltips.AddTool(IDC_REBASE_CHECK_FORCE,IDS_REBASE_FORCE_TT); m_tooltips.AddTool(IDC_REBASE_ABORT,IDS_REBASE_ABORT_TT); m_FileListCtrl.Init(GITSLC_COLEXT | GITSLC_COLSTATUS |GITSLC_COLADD|GITSLC_COLDEL , _T("RebaseDlg"),(GITSLC_POPALL ^ (GITSLC_POPCOMMIT|GITSLC_POPRESTORE)),false); m_ctrlTabCtrl.AddTab(&m_FileListCtrl,_T("Revision Files")); m_ctrlTabCtrl.AddTab(&m_LogMessageCtrl,_T("Commit Message"),1); AddRebaseAnchor(); CString sWindowTitle; GetWindowText(sWindowTitle); CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle); EnableSaveRestore(_T("RebaseDlg")); DWORD yPos = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\RebaseDlgSizer")); RECT rcDlg, rcLogMsg, rcFileList; GetClientRect(&rcDlg); m_CommitList.GetWindowRect(&rcLogMsg); ScreenToClient(&rcLogMsg); this->m_ctrlTabCtrl.GetWindowRect(&rcFileList); ScreenToClient(&rcFileList); if (yPos) { RECT rectSplitter; m_wndSplitter.GetWindowRect(&rectSplitter); ScreenToClient(&rectSplitter); int delta = yPos - rectSplitter.top; if ((rcLogMsg.bottom + delta > rcLogMsg.top)&&(rcLogMsg.bottom + delta < rcFileList.bottom - 30)) { m_wndSplitter.SetWindowPos(NULL, 0, yPos, 0, 0, SWP_NOSIZE); DoSize(delta); } } if( this->m_RebaseStage == CHOOSE_BRANCH) { this->LoadBranchInfo(); } else { this->m_BranchCtrl.EnableWindow(FALSE); this->m_UpstreamCtrl.EnableWindow(FALSE); } m_CommitList.m_ColumnRegKey = _T("Rebase"); m_CommitList.m_IsIDReplaceAction = TRUE; // m_CommitList.m_IsOldFirst = TRUE; m_CommitList.m_IsRebaseReplaceGraph = TRUE; m_CommitList.InsertGitColumn(); this->SetControlEnable(); if(!this->m_PreCmd.IsEmpty()) { CProgressDlg progress; progress.m_GitCmd=m_PreCmd; progress.m_bAutoCloseOnSuccess=true; progress.DoModal(); } if(m_IsCherryPick) { this->m_BranchCtrl.SetCurSel(-1); this->m_BranchCtrl.EnableWindow(FALSE); this->m_UpstreamCtrl.AddString(_T("HEAD")); this->m_UpstreamCtrl.EnableWindow(FALSE); this->SetWindowText(_T("Cherry Pick")); this->m_CommitList.StartFilter(); } else { SetContinueButtonText(); m_CommitList.DeleteAllItems(); FetchLogList(); } m_CommitList.m_ContextMenuMask &= ~(m_CommitList.GetContextMenuBit(CGitLogListBase::ID_CHERRY_PICK)| m_CommitList.GetContextMenuBit(CGitLogListBase::ID_SWITCHTOREV)| m_CommitList.GetContextMenuBit(CGitLogListBase::ID_RESET)| m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REVERTREV)| m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REBASE_TO_VERSION)| m_CommitList.GetContextMenuBit(CGitLogListBase::ID_REVERTTOREV)| m_CommitList.GetContextMenuBit(CGitLogListBase::ID_COMBINE_COMMIT)); if(m_CommitList.m_IsOldFirst) this->m_CurrentRebaseIndex = -1; else this->m_CurrentRebaseIndex = m_CommitList.m_logEntries.size(); if(this->CheckRebaseCondition()) { /* Disable Start Rebase */ this->GetDlgItem(IDC_REBASE_CONTINUE)->EnableWindow(FALSE); } return TRUE; }
bool BisectCommand::Execute() { CTGitPath path = g_Git.m_CurrentDir; if (this->parser.HasKey(_T("start")) && !path.IsBisectActive()) { bool autoClose = false; if (parser.HasVal(_T("closeonend"))) autoClose = !!parser.GetLongVal(_T("closeonend")); CString lastGood, firstBad; if (parser.HasKey(_T("good"))) lastGood = parser.GetVal(_T("good")); if (parser.HasKey(_T("bad"))) firstBad = parser.GetVal(_T("bad")); return CAppUtils::BisectStart(lastGood, firstBad, autoClose); } else if ((this->parser.HasKey(_T("good")) || this->parser.HasKey(_T("bad")) || this->parser.HasKey(_T("reset"))) && path.IsBisectActive()) { CString cmd = _T("git.exe bisect "); if (this->parser.HasKey(_T("good"))) cmd += _T("good"); else if (this->parser.HasKey(_T("bad"))) cmd += _T("bad"); else if (this->parser.HasKey(_T("reset"))) cmd += _T("reset"); if (this->parser.HasKey(_T("ref")) &&! this->parser.HasKey(_T("reset"))) { cmd += _T(" "); cmd += this->parser.GetVal(_T("ref")); } CProgressDlg progress; theApp.m_pMainWnd = &progress; if (parser.HasVal(_T("closeonend"))) progress.m_bAutoCloseOnSuccess = !!parser.GetLongVal(_T("closeonend")); progress.m_GitCmd = cmd; if (path.HasSubmodules()) progress.m_PostCmdList.Add(CString(MAKEINTRESOURCE(IDS_PROC_SUBMODULESUPDATE))); int reset = -1; if (!this->parser.HasKey(_T("reset"))) reset = (int)progress.m_PostCmdList.Add(_T("Bisect reset")); INT_PTR ret = progress.DoModal(); if (path.HasSubmodules() && ret == IDC_PROGRESS_BUTTON1) { CString sCmd; sCmd.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git.m_CurrentDir); CAppUtils::RunTortoiseGitProc(sCmd); return true; } else if (reset >= 0 && ret == IDC_PROGRESS_BUTTON1 + reset) { CAppUtils::RunTortoiseGitProc(_T("/command:bisect /reset")); return true; } else if (ret == IDOK) return true; } else { CMessageBox::Show(NULL,_T("Operation unknown or not allowed."), _T("TortoiseGit"), MB_OK|MB_ICONINFORMATION); } return false; }
bool SVNRebaseCommand::Execute() { bool isStash = false; if(!g_Git.CheckCleanWorkTree()) { if (CMessageBox::Show(hwndExplorer, g_Git.m_CurrentDir + L"\r\n" + CString(MAKEINTRESOURCE(IDS_ERROR_NOCLEAN_STASH)), L"TortoiseGit", 1, IDI_QUESTION, CString(MAKEINTRESOURCE(IDS_STASHBUTTON)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON))) == 1) { CSysProgressDlg sysProgressDlg; sysProgressDlg.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME))); sysProgressDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING))); sysProgressDlg.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT))); sysProgressDlg.SetShowProgressBar(false); sysProgressDlg.SetCancelMsg(IDS_PROGRS_INFOFAILED); sysProgressDlg.ShowModeless((HWND)NULL, true); CString cmd,out; cmd=_T("git.exe stash"); if (g_Git.Run(cmd, &out, CP_UTF8)) { sysProgressDlg.Stop(); MessageBox(hwndExplorer, out, _T("TortoiseGit"), MB_OK | MB_ICONERROR); return false; } sysProgressDlg.Stop(); isStash = true; } else { return false; } } CRebaseDlg dlg; // dlg.m_PreCmd=_T("git.exe svn fetch"); CString cmd, out, err; cmd = _T("git.exe config svn-remote.svn.fetch"); if (!g_Git.Run(cmd, &out, &err, CP_UTF8)) { int start = out.Find(_T(':')); if( start >=0 ) out=out.Mid(start); if(out.Left(5) == _T(":refs")) out=out.Mid(6); start = 0; out=out.Tokenize(_T("\n"),start); } else { MessageBox(hwndExplorer, out + L"\n" + err, L"TortoiseGit", MB_OK | MB_ICONERROR); return false; } dlg.m_Upstream=out; CGitHash UpStreamOldHash,HeadHash,UpStreamNewHash; if (g_Git.GetHash(UpStreamOldHash, out)) { MessageBox(hwndExplorer, g_Git.GetGitLastErr(_T("Could not get hash of SVN branch.")), _T("TortoiseGit"), MB_ICONERROR); return false; } if (g_Git.GetHash(HeadHash, _T("HEAD"))) { MessageBox(hwndExplorer, g_Git.GetGitLastErr(_T("Could not get HEAD hash.")), _T("TortoiseGit"), MB_ICONERROR); return false; } CProgressDlg progress; progress.m_GitCmd=_T("git.exe svn fetch"); progress.m_AutoClose = AUTOCLOSE_IF_NO_ERRORS; if(progress.DoModal()!=IDOK) return false; if(progress.m_GitStatus) return false; if (g_Git.GetHash(UpStreamNewHash, out)) { MessageBox(hwndExplorer, g_Git.GetGitLastErr(_T("Could not get upstream hash after fetching.")), _T("TortoiseGit"), MB_ICONERROR); return false; } //everything updated if(UpStreamNewHash==HeadHash) { MessageBox(hwndExplorer, g_Git.m_CurrentDir + _T("\r\n") + CString(MAKEINTRESOURCE(IDS_PROC_EVERYTHINGUPDATED)), _T("TortoiseGit"), MB_OK | MB_ICONQUESTION); if(isStash) askIfUserWantsToStashPop(); return true; } //fast forward; if(g_Git.IsFastForward(CString(_T("HEAD")),out)) { CProgressDlg progressReset; cmd.Format(_T("git.exe reset --hard %s --"), (LPCTSTR)out); progressReset.m_GitCmd = cmd; progressReset.m_AutoClose = AUTOCLOSE_IF_NO_ERRORS; if (progressReset.DoModal() != IDOK) return false; else { MessageBox(hwndExplorer, g_Git.m_CurrentDir + _T("\r\n") + CString(MAKEINTRESOURCE(IDS_PROC_FASTFORWARD)) + _T(":\n") + progressReset.m_LogText, _T("TortoiseGit"), MB_OK | MB_ICONQUESTION); if(isStash) askIfUserWantsToStashPop(); return true; } } dlg.m_PostButtonTexts.Add(CString(MAKEINTRESOURCE(IDS_MENULOG))); //need rebase INT_PTR response = dlg.DoModal(); if (response == IDOK || response == IDC_REBASE_POST_BUTTON) { if(isStash) askIfUserWantsToStashPop(); if (response == IDC_REBASE_POST_BUTTON) { cmd = _T("/command:log"); cmd += _T(" /path:\"") + g_Git.m_CurrentDir + _T("\""); CAppUtils::RunTortoiseGitProc(cmd); } return true; } return false; }
bool PullCommand::Execute() { CPullFetchDlg dlg; dlg.m_IsPull=TRUE; if(dlg.DoModal()==IDOK) { CString url; url=dlg.m_RemoteURL; if(dlg.m_bAutoLoad) { CAppUtils::LaunchPAgent(NULL,&dlg.m_RemoteURL); } CString cmd; CString hashOld = g_Git.GetHash(L"HEAD"); CString cmdRebase; if(dlg.m_bRebase) cmdRebase = "--rebase "; CString noff; CString ffonly; CString squash; CString nocommit; if(dlg.m_bNoFF) noff=_T("--no-ff"); if (dlg.m_bFFonly) ffonly = _T("--ff-only"); if(dlg.m_bSquash) squash=_T("--squash"); if(dlg.m_bNoCommit) nocommit=_T("--no-commit"); int ver = CAppUtils::GetMsysgitVersion(); if(ver >= 0x01070203) //above 1.7.0.2 cmdRebase += _T("--progress "); cmd.Format(_T("git.exe pull -v %s %s %s %s %s \"%s\" %s"), cmdRebase, noff, ffonly, squash, nocommit, url, dlg.m_RemoteBranchName); CProgressDlg progress; progress.m_GitCmd = cmd; progress.m_PostCmdList.Add(_T("Pulled Diff")); progress.m_PostCmdList.Add(_T("Pulled Log")); CTGitPath gitPath = g_Git.m_CurrentDir; if (gitPath.HasSubmodules()) progress.m_PostCmdList.Add(_T("Update submodules")); //progress.m_PostCmdList.Add(_T("Show Conflict")); if (parser.HasVal(_T("closeonend"))) progress.m_bAutoCloseOnSuccess = !!parser.GetLongVal(_T("closeonend")); int ret = progress.DoModal(); CString hashNew = g_Git.GetHash(L"HEAD"); if( ret == IDC_PROGRESS_BUTTON1) { if(hashOld == hashNew) { if(progress.m_GitStatus == 0) CMessageBox::Show(NULL, L"Already up to date.", L"Pull", MB_OK | MB_ICONINFORMATION); return TRUE; } CFileDiffDlg dlg; dlg.SetDiff(NULL, hashNew, hashOld); dlg.DoModal(); return TRUE; } else if ( ret == IDC_PROGRESS_BUTTON1 +1 ) { if(hashOld == hashNew) { if(progress.m_GitStatus == 0) CMessageBox::Show(NULL, L"Already up to date.", L"Pull", MB_OK | MB_ICONINFORMATION); return TRUE; } CLogDlg dlg; //dlg.SetParams(cmdLinePath); dlg.SetParams(CTGitPath(_T("")),CTGitPath(_T("")),_T(""), hashOld, hashNew, 0); // dlg.SetIncludeMerge(!!parser.HasKey(_T("merge"))); // val = parser.GetVal(_T("propspath")); // if (!val.IsEmpty()) // dlg.SetProjectPropertiesPath(CTSVNPath(val)); dlg.DoModal(); } else if (ret == IDC_PROGRESS_BUTTON1 + 2 && gitPath.HasSubmodules()) { CString sCmd; sCmd.Format(_T("/command:subupdate /bkpath:\"%s\""), g_Git.m_CurrentDir); CAppUtils::RunTortoiseProc(sCmd); } } #if 0 CCloneDlg dlg; dlg.m_Directory=this->orgCmdLinePath.GetWinPathString(); if(dlg.DoModal()==IDOK) { CString dir=dlg.m_Directory; CString url=dlg.m_URL; CString cmd; cmd.Format(_T("git.exe clone %s %s"), url, dir); CProgressDlg progress; progress.m_GitCmd=cmd; if(progress.DoModal()==IDOK) return TRUE; } #endif return FALSE; }
bool CloneCommand::Execute() { CTGitPath cloneDirectory; if (!parser.HasKey(_T("hasurlhandler"))) { if (orgCmdLinePath.IsEmpty()) { cloneDirectory.SetFromWin(sOrigCWD, true); DWORD len = ::GetTempPath(0, NULL); std::unique_ptr<TCHAR[]> tszPath(new TCHAR[len]); ::GetTempPath(len, tszPath.get()); if (_tcsncicmp(cloneDirectory.GetWinPath(), tszPath.get(), len-2 /* \\ and \0 */) == 0) { // if the current directory is set to a temp directory, // we don't use that but leave it empty instead. cloneDirectory.Reset(); } } else cloneDirectory = orgCmdLinePath; } CCloneDlg dlg; dlg.m_Directory = cloneDirectory.GetWinPathString(); if (parser.HasKey(_T("url"))) dlg.m_URL = parser.GetVal(_T("url")); if (parser.HasKey(_T("exactpath"))) dlg.m_bExactPath = TRUE; if(dlg.DoModal()==IDOK) { CString recursiveStr; if(dlg.m_bRecursive) recursiveStr = _T("--recursive"); else recursiveStr = _T(""); CString bareStr; if(dlg.m_bBare) bareStr = _T("--bare"); else bareStr = _T(""); CString nocheckoutStr; if (dlg.m_bNoCheckout) nocheckoutStr = _T("--no-checkout"); CString branchStr; if (dlg.m_bBranch) branchStr = _T("--branch ") + dlg.m_strBranch; CString originStr; if (dlg.m_bOrigin) originStr = _T("--origin ") + dlg.m_strOrigin; if(dlg.m_bAutoloadPuttyKeyFile) { CAppUtils::LaunchPAgent(&dlg.m_strPuttyKeyFile); } CAppUtils::RemoveTrailSlash(dlg.m_Directory); if (!dlg.m_bSVN) CAppUtils::RemoveTrailSlash(dlg.m_URL); CString dir=dlg.m_Directory; CString url=dlg.m_URL; // is this a windows format UNC path, ie starts with \\? if (url.Find(_T("\\\\")) == 0) { // yes, change all \ to / // this should not be necessary but msysgit does not support the use \ here yet int atSign = url.Find(_T('@')); if (atSign > 0) { CString path = url.Mid(atSign); path.Replace(_T('\\'), _T('/')); url = url.Mid(0, atSign) + path; } else url.Replace( _T('\\'), _T('/')); } CString depth; if (dlg.m_bDepth) { depth.Format(_T(" --depth %d"),dlg.m_nDepth); } g_Git.m_CurrentDir = GetExistingDirectoryForClone(dlg.m_Directory); CString cmd; CString progressarg; int ver = CAppUtils::GetMsysgitVersion(); if(ver >= 0x01070002) //above 1.7.0.2 progressarg = _T("--progress"); cmd.Format(_T("git.exe clone %s %s %s %s %s %s -v %s \"%s\" \"%s\""), nocheckoutStr, recursiveStr, bareStr, branchStr, originStr, progressarg, depth, url, dir); // Handle Git SVN-clone if(dlg.m_bSVN) { //g_Git.m_CurrentDir=dlg.m_Directory; cmd.Format(_T("git.exe svn clone \"%s\" \"%s\""), url,dlg.m_Directory); if(dlg.m_bSVNTrunk) cmd+=_T(" -T ")+dlg.m_strSVNTrunk; if(dlg.m_bSVNBranch) cmd+=_T(" -b ")+dlg.m_strSVNBranchs; if(dlg.m_bSVNTags) cmd+=_T(" -t ")+dlg.m_strSVNTags; if(dlg.m_bSVNFrom) { CString str; str.Format(_T("%d:HEAD"),dlg.m_nSVNFrom); cmd+=_T(" -r ")+str; } if(dlg.m_bSVNUserName) { cmd+= _T(" --username "); cmd+=dlg.m_strUserName; } } else { if (g_Git.UsingLibGit2(CGit::GIT_CMD_CLONE)) { CGitProgressDlg GitDlg; CTGitPathList list; g_Git.m_CurrentDir = dir; list.AddPath(CTGitPath(dir)); GitDlg.SetCommand(CGitProgressList::GitProgress_Clone); GitDlg.SetUrl(url); GitDlg.SetPathList(list); GitDlg.SetIsBare(!!dlg.m_bBare); GitDlg.SetRefSpec(dlg.m_bBranch ? dlg.m_strBranch : CString()); GitDlg.SetRemote(dlg.m_bOrigin ? dlg.m_strOrigin : CString()); GitDlg.SetNoCheckout(!!dlg.m_bNoCheckout); GitDlg.DoModal(); return !GitDlg.DidErrorsOccur(); } } CProgressDlg progress; progress.m_GitCmd=cmd; progress.m_PostCmdList.Add(CString(MAKEINTRESOURCE(IDS_MENULOG))); progress.m_PostCmdList.Add(CString(MAKEINTRESOURCE(IDS_STATUSLIST_CONTEXT_EXPLORE))); INT_PTR ret = progress.DoModal(); if (dlg.m_bSVN) ::DeleteFile(g_Git.m_CurrentDir + _T("\\sys$command")); if( progress.m_GitStatus == 0) { if(dlg.m_bAutoloadPuttyKeyFile) { g_Git.m_CurrentDir = dlg.m_Directory; SetCurrentDirectory(g_Git.m_CurrentDir); if(g_Git.SetConfigValue(_T("remote.origin.puttykeyfile"), dlg.m_strPuttyKeyFile, CONFIG_LOCAL, CP_UTF8)) { CMessageBox::Show(NULL,_T("Fail set config remote.origin.puttykeyfile"),_T("TortoiseGit"),MB_OK|MB_ICONERROR); return FALSE; } } if (ret == IDC_PROGRESS_BUTTON1) { CString cmd = _T("/command:log"); cmd += _T(" /path:\"") + dlg.m_Directory + _T("\""); CAppUtils::RunTortoiseGitProc(cmd); return TRUE; } if (ret == IDC_PROGRESS_BUTTON1 + 1) { ShellExecute(nullptr, _T("explore"), dlg.m_Directory, nullptr, nullptr, SW_SHOW); return TRUE; } } if(ret == IDOK) return TRUE; } return FALSE; }
bool SubmoduleUpdateCommand::Execute() { CString bkpath; if (parser.HasKey(_T("bkpath"))) bkpath = parser.GetVal(_T("bkpath")); else { bkpath = this->orgPathList[0].GetWinPathString(); int start = bkpath.ReverseFind(_T('\\')); if (start >= 0) bkpath = bkpath.Left(start); } CString super = GitAdminDir::GetSuperProjectRoot(bkpath); if (super.IsEmpty()) { CMessageBox::Show(NULL,IDS_ERR_NOTFOUND_SUPER_PRJECT,IDS_APPNAME,MB_OK|MB_ICONERROR); //change current project root to super project return false; } STRING_VECTOR pathFilterList; for (int i = 0; i < orgPathList.GetCount(); i++) { if (orgPathList[i].IsDirectory()) { CString path = ((CTGitPath &)orgPathList[i]).GetSubPath(CTGitPath(super)).GetGitPathString(); if (!path.IsEmpty()) pathFilterList.push_back(path); } } CSubmoduleUpdateDlg submoduleUpdateDlg; submoduleUpdateDlg.m_PathFilterList = pathFilterList; if (parser.HasKey(_T("selectedpath"))) { CString selectedPath = parser.GetVal(_T("selectedpath")); selectedPath.Replace(_T('\\'), _T('/')); submoduleUpdateDlg.m_PathList.push_back(selectedPath); } if (submoduleUpdateDlg.DoModal() != IDOK) return false; CProgressDlg progress; g_Git.m_CurrentDir = super; CString params; if (submoduleUpdateDlg.m_bInit) params = _T(" --init"); if (submoduleUpdateDlg.m_bRecursive) params += _T(" --recursive"); if (submoduleUpdateDlg.m_bForce) params += _T(" --force"); if (submoduleUpdateDlg.m_bNoFetch) params += _T(" --no-fetch"); if (submoduleUpdateDlg.m_bMerge) params += _T(" --merge"); if (submoduleUpdateDlg.m_bRebase) params += _T(" --rebase"); if (submoduleUpdateDlg.m_bRemote) params += _T(" --remote"); for (size_t i = 0; i < submoduleUpdateDlg.m_PathList.size(); ++i) { CString str; str.Format(_T("git.exe submodule update%s -- \"%s\""), (LPCTSTR)params, (LPCTSTR)submoduleUpdateDlg.m_PathList[i]); progress.m_GitCmdList.push_back(str); } progress.DoModal(); return !progress.m_GitStatus; }
bool CleanupCommand::Execute() { bool bRet = false; CCleanTypeDlg dlg; if( dlg.DoModal() == IDOK) { bool quotepath = g_Git.GetConfigValueBool(_T("core.quotepath")); CString cmd; cmd.Format(_T("git.exe clean")); if (dlg.m_bDryRun || !dlg.m_bNoRecycleBin) cmd += _T(" -n "); if(dlg.m_bDir) cmd += _T(" -d "); switch(dlg.m_CleanType) { case 0: cmd += _T(" -fx"); break; case 1: cmd += _T(" -f"); break; case 2: cmd += _T(" -fX"); break; } STRING_VECTOR submoduleList; SubmodulePayload payload(submoduleList); if (dlg.m_bSubmodules) { payload.basePath = CTGitPath(g_Git.m_CurrentDir).GetGitPathString(); if (pathList.GetCount() != 1 || pathList.GetCount() == 1 && !pathList[0].IsEmpty()) { for (int i = 0; i < pathList.GetCount(); ++i) { CString path; if (pathList[i].IsDirectory()) payload.prefixList.push_back(pathList[i].GetGitPathString()); else payload.prefixList.push_back(pathList[i].GetContainingDirectory().GetGitPathString()); } } if (!GetSubmodulePathList(payload)) return FALSE; std::sort(submoduleList.begin(), submoduleList.end()); } if (dlg.m_bDryRun || dlg.m_bNoRecycleBin) { while (true) { CProgressDlg progress; for (int i = 0; i < this->pathList.GetCount(); ++i) { CString path; if (this->pathList[i].IsDirectory()) path = pathList[i].GetGitPathString(); else path = pathList[i].GetContainingDirectory().GetGitPathString(); progress.m_GitDirList.push_back(g_Git.m_CurrentDir); progress.m_GitCmdList.push_back(cmd + _T(" \"") + path + _T("\"")); } if (dlg.m_bSubmodules) { for (CString dir : submoduleList) { progress.m_GitDirList.push_back(CTGitPath(dir).GetWinPathString()); progress.m_GitCmdList.push_back(cmd); } } INT_PTR idRetry = -1; if (!dlg.m_bDryRun) idRetry = progress.m_PostFailCmdList.Add(CString(MAKEINTRESOURCE(IDS_MSGBOX_RETRY))); INT_PTR result = progress.DoModal(); if (result == IDOK) return TRUE; if (progress.m_GitStatus && result == IDC_PROGRESS_BUTTON1 + idRetry) continue; break; } } else { CSysProgressDlg sysProgressDlg; sysProgressDlg.SetAnimation(IDR_CLEANUPANI); sysProgressDlg.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME))); sysProgressDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_CLEANUP_INFO1))); sysProgressDlg.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT))); sysProgressDlg.SetShowProgressBar(false); sysProgressDlg.ShowModeless((HWND)NULL, true); CTGitPathList delList; for (size_t i = 0; i <= submoduleList.size(); ++i) { CGit git; CGit *pGit; if (i == 0) pGit = &g_Git; else { git.m_CurrentDir = submoduleList[i - 1]; pGit = &git; } CString cmdout, cmdouterr; if (pGit->Run(cmd, &cmdout, &cmdouterr, CP_UTF8)) { MessageBox(nullptr, cmdouterr, _T("TortoiseGit"), MB_ICONERROR); return FALSE; } if (sysProgressDlg.HasUserCancelled()) { CMessageBox::Show(nullptr, IDS_SVN_USERCANCELLED, IDS_APPNAME, MB_OK); return FALSE; } int pos = 0; CString token = cmdout.Tokenize(_T("\n"), pos); while (!token.IsEmpty()) { if (token.Mid(0, 13) == _T("Would remove ")) { CString tempPath = token.Mid(13).TrimRight(); if (quotepath) { tempPath = UnescapeQuotePath(tempPath.Trim(_T('"'))); } if (i == 0) delList.AddPath(CTGitPath(tempPath)); else delList.AddPath(CTGitPath(submoduleList[i - 1] + "/" + tempPath)); } token = cmdout.Tokenize(_T("\n"), pos); } if (sysProgressDlg.HasUserCancelled()) { CMessageBox::Show(nullptr, IDS_SVN_USERCANCELLED, IDS_APPNAME, MB_OK); return FALSE; } } delList.DeleteAllFiles(true, false); sysProgressDlg.Stop(); } } #if 0 CProgressDlg progress; progress.SetTitle(IDS_PROC_CLEANUP); progress.SetAnimation(IDR_CLEANUPANI); progress.SetShowProgressBar(false); progress.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_CLEANUP_INFO1))); progress.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROC_CLEANUP_INFO2))); progress.ShowModeless(hwndExplorer); CString strSuccessfullPaths, strFailedPaths; for (int i=0; i<pathList.GetCount(); ++i) { SVN svn; if (!svn.CleanUp(pathList[i])) { strFailedPaths += _T("- ") + pathList[i].GetWinPathString() + _T("\n"); strFailedPaths += svn.GetLastErrorMessage() + _T("\n\n"); } else { strSuccessfullPaths += _T("- ") + pathList[i].GetWinPathString() + _T("\n"); // after the cleanup has finished, crawl the path downwards and send a change // notification for every directory to the shell. This will update the // overlays in the left tree view of the explorer. CDirFileEnum crawler(pathList[i].GetWinPathString()); CString sPath; bool bDir = false; CTSVNPathList updateList; while (crawler.NextFile(sPath, &bDir)) { if ((bDir) && (!g_SVNAdminDir.IsAdminDirPath(sPath))) { updateList.AddPath(CTSVNPath(sPath)); } } updateList.AddPath(pathList[i]); CShellUpdater::Instance().AddPathsForUpdate(updateList); CShellUpdater::Instance().Flush(); updateList.SortByPathname(true); for (INT_PTR i=0; i<updateList.GetCount(); ++i) { SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH, updateList[i].GetWinPath(), NULL); CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) _T(": notify change for path %s\n"), updateList[i].GetWinPath()); } } } progress.Stop(); CString strMessage; if ( !strSuccessfullPaths.IsEmpty() ) { CString tmp; tmp.Format(IDS_PROC_CLEANUPFINISHED, (LPCTSTR)strSuccessfullPaths); strMessage += tmp; bRet = true; } if ( !strFailedPaths.IsEmpty() ) { if (!strMessage.IsEmpty()) strMessage += _T("\n"); CString tmp; tmp.Format(IDS_PROC_CLEANUPFINISHED_FAILED, (LPCTSTR)strFailedPaths); strMessage += tmp; bRet = false; } CMessageBox::Show(hwndExplorer, strMessage, _T("TortoiseGit"), MB_OK | (strFailedPaths.IsEmpty()?MB_ICONINFORMATION:MB_ICONERROR)); #endif CShellUpdater::Instance().Flush(); return bRet; }
bool SVNFetchCommand::Execute() { bool autoClose = false; if (parser.HasVal(_T("closeonend"))) autoClose = !!parser.GetLongVal(_T("closeonend")); CString cmd, out, err; cmd = _T("git.exe config svn-remote.svn.fetch"); if (!g_Git.Run(cmd, &out, &err, CP_UTF8)) { int start = out.Find(_T(':')); if( start >=0 ) out=out.Mid(start); if(out.Left(5) == _T(":refs")) out=out.Mid(6); start = 0; out=out.Tokenize(_T("\n"),start); } else { CMessageBox::Show(NULL, _T("Found no SVN remote."), _T("TortoiseGit"), MB_OK|MB_ICONERROR); return false; } CString upstreamOldHash, upstreamNewHash; upstreamOldHash = g_Git.GetHash(out); CProgressDlg progress; progress.m_GitCmd=_T("git.exe svn fetch"); progress.m_PostCmdList.Add(_T("Fetched Diff")); progress.m_PostCmdList.Add(_T("Fetched Log")); progress.m_bAutoCloseOnSuccess = autoClose; int userResponse = progress.DoModal(); upstreamNewHash = g_Git.GetHash(out); if (userResponse == IDC_PROGRESS_BUTTON1) { if (upstreamOldHash == upstreamNewHash) { if (progress.m_GitStatus == 0) CMessageBox::Show(NULL, L"No new revisions fetched.", L"TortoiseGit Fetch", MB_OK | MB_ICONINFORMATION); return TRUE; } CLogDlg dlg; dlg.SetParams(CTGitPath(_T("")), CTGitPath(_T("")), _T(""), upstreamOldHash, upstreamNewHash, 0); dlg.DoModal(); return TRUE; } else if (userResponse == IDC_PROGRESS_BUTTON1 + 1) { if (upstreamOldHash == upstreamNewHash) { if (progress.m_GitStatus == 0) CMessageBox::Show(NULL, L"No new revisions fetched.", L"TortoiseGit Fetch", MB_OK | MB_ICONINFORMATION); return TRUE; } CFileDiffDlg dlg; dlg.SetDiff(NULL, upstreamNewHash, upstreamOldHash); dlg.DoModal(); return TRUE; } else return false; return true; }
bool SVNRebaseCommand::Execute() { if (!GitAdminDir::HasAdminDir(g_Git.m_CurrentDir)) { CMessageBox::Show(GetExplorerHWND(), IDS_NOWORKINGCOPY, IDS_APPNAME, MB_ICONERROR); return false; } bool isStash = false; if(!g_Git.CheckCleanWorkTree()) { if (CMessageBox::Show(GetExplorerHWND(), g_Git.m_CurrentDir + L"\r\n" + CString(MAKEINTRESOURCE(IDS_ERROR_NOCLEAN_STASH)), L"TortoiseGit", 1, IDI_QUESTION, CString(MAKEINTRESOURCE(IDS_STASHBUTTON)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON))) == 1) { CSysProgressDlg sysProgressDlg; sysProgressDlg.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME))); sysProgressDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_STASHRUNNING))); sysProgressDlg.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT))); sysProgressDlg.SetShowProgressBar(false); sysProgressDlg.SetCancelMsg(IDS_PROGRS_INFOFAILED); sysProgressDlg.ShowModeless(static_cast<HWND>(nullptr), true); CString out; if (g_Git.Run(L"git.exe stash", &out, CP_UTF8)) { sysProgressDlg.Stop(); MessageBox(GetExplorerHWND(), out, L"TortoiseGit", MB_OK | MB_ICONERROR); return false; } sysProgressDlg.Stop(); isStash = true; } else { return false; } } CRebaseDlg dlg; // dlg.m_PreCmd=L"git.exe svn fetch"; CString out, err; if (!g_Git.Run(L"git.exe config svn-remote.svn.fetch", &out, &err, CP_UTF8)) { int start = out.Find(L':'); if( start >=0 ) out=out.Mid(start); if (CStringUtils::StartsWith(out, L":refs")) out = out.Mid(static_cast<int>(wcslen(L":refs")) + 1); start = 0; out = out.Tokenize(L"\n", start); } else { MessageBox(GetExplorerHWND(), L"Could not get \"svn-remote.svn.fetch\" config value.\n" + out + L'\n' + err, L"TortoiseGit", MB_OK | MB_ICONERROR); return false; } dlg.m_Upstream=out; CGitHash UpStreamOldHash,HeadHash,UpStreamNewHash; if (g_Git.GetHash(UpStreamOldHash, out)) { MessageBox(GetExplorerHWND(), g_Git.GetGitLastErr(L"Could not get hash of SVN branch."), L"TortoiseGit", MB_ICONERROR); return false; } if (g_Git.GetHash(HeadHash, L"HEAD")) { MessageBox(GetExplorerHWND(), g_Git.GetGitLastErr(L"Could not get HEAD hash."), L"TortoiseGit", MB_ICONERROR); return false; } CProgressDlg progress; progress.m_GitCmd = L"git.exe svn fetch"; progress.m_AutoClose = AUTOCLOSE_IF_NO_ERRORS; if(progress.DoModal()!=IDOK) return false; if(progress.m_GitStatus) return false; if (g_Git.GetHash(UpStreamNewHash, out)) { MessageBox(GetExplorerHWND(), g_Git.GetGitLastErr(L"Could not get upstream hash after fetching."), L"TortoiseGit", MB_ICONERROR); return false; } //everything updated if(UpStreamNewHash==HeadHash) { MessageBox(GetExplorerHWND(), g_Git.m_CurrentDir + L"\r\n" + CString(MAKEINTRESOURCE(IDS_PROC_EVERYTHINGUPDATED)), L"TortoiseGit", MB_OK | MB_ICONQUESTION); if(isStash) askIfUserWantsToStashPop(); return true; } //fast forward; if (g_Git.IsFastForward(L"HEAD", out)) { CProgressDlg progressReset; CString cmd; cmd.Format(L"git.exe reset --hard %s --", static_cast<LPCTSTR>(out)); progressReset.m_GitCmd = cmd; progressReset.m_AutoClose = AUTOCLOSE_IF_NO_ERRORS; if (progressReset.DoModal() != IDOK) return false; else { MessageBox(GetExplorerHWND(), g_Git.m_CurrentDir + L"\r\n" + CString(MAKEINTRESOURCE(IDS_PROC_FASTFORWARD)) + L":\n" + progressReset.m_LogText, L"TortoiseGit", MB_OK | MB_ICONQUESTION); if(isStash) askIfUserWantsToStashPop(); return true; } } dlg.m_PostButtonTexts.Add(CString(MAKEINTRESOURCE(IDS_MENULOG))); //need rebase INT_PTR response = dlg.DoModal(); if (response == IDOK || response == IDC_REBASE_POST_BUTTON) { if(isStash) askIfUserWantsToStashPop(); if (response == IDC_REBASE_POST_BUTTON) { CString cmd = L"/command:log"; cmd += L" /path:\"" + g_Git.m_CurrentDir + L'"'; CAppUtils::RunTortoiseGitProc(cmd); } return true; } return false; }
bool SVNFetchCommand::Execute() { CString cmd, out, err; cmd = _T("git.exe config svn-remote.svn.fetch"); if (!g_Git.Run(cmd, &out, &err, CP_UTF8)) { int start = out.Find(_T(':')); if( start >=0 ) out=out.Mid(start); if(out.Left(5) == _T(":refs")) out=out.Mid(6); start = 0; out=out.Tokenize(_T("\n"),start); } else { CMessageBox::Show(NULL, _T("Found no SVN remote."), _T("TortoiseGit"), MB_OK|MB_ICONERROR); return false; } CGitHash upstreamOldHash, upstreamNewHash; if (g_Git.GetHash(upstreamOldHash, out)) { MessageBox(hwndExplorer, g_Git.GetGitLastErr(_T("Could not get upstream hash.")), _T("TortoiseGit"), MB_ICONERROR); return false; } CProgressDlg progress; progress.m_GitCmd=_T("git.exe svn fetch"); progress.m_PostCmdList.Add(_T("Fetched Diff")); progress.m_PostCmdList.Add(_T("Fetched Log")); INT_PTR userResponse = progress.DoModal(); ::DeleteFile(g_Git.m_CurrentDir + _T("\\sys$command")); if (g_Git.GetHash(upstreamNewHash, out)) { MessageBox(hwndExplorer, g_Git.GetGitLastErr(_T("Could not get upstream hash after fetching.")), _T("TortoiseGit"), MB_ICONERROR); return false; } if (userResponse == IDC_PROGRESS_BUTTON1) { if (upstreamOldHash == upstreamNewHash) { if (progress.m_GitStatus == 0) CMessageBox::Show(NULL, L"No new revisions fetched.", L"TortoiseGit Fetch", MB_OK | MB_ICONINFORMATION); return true; } CLogDlg dlg; dlg.SetParams(CTGitPath(_T("")), CTGitPath(_T("")), _T(""), upstreamOldHash.ToString() + _T("..") + upstreamNewHash.ToString(), 0); dlg.DoModal(); return true; } else if (userResponse == IDC_PROGRESS_BUTTON1 + 1) { if (upstreamOldHash == upstreamNewHash) { if (progress.m_GitStatus == 0) CMessageBox::Show(NULL, L"No new revisions fetched.", L"TortoiseGit Fetch", MB_OK | MB_ICONINFORMATION); return true; } CFileDiffDlg dlg; dlg.SetDiff(NULL, upstreamNewHash.ToString(), upstreamOldHash.ToString()); dlg.DoModal(); return true; } else return false; }