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; }
int CGit::Revert(CString commit, CTGitPath &path) { CString cmd, out; if(path.m_Action & CTGitPath::LOGACTIONS_REPLACED && !path.GetGitOldPathString().IsEmpty()) { if (CTGitPath(path.GetGitOldPathString()).IsDirectory()) { CString err; err.Format(_T("Cannot revert renaming of \"%s\". A directory with the old name \"%s\" exists."), path.GetGitPathString(), path.GetGitOldPathString()); ::MessageBox(NULL, err, _T("TortoiseGit"), MB_OK|MB_ICONERROR); return -1; } CString force; // if the filenames only differ in case, we have to pass "-f" if (path.GetGitPathString().CompareNoCase(path.GetGitOldPathString()) == 0) force = _T("-f "); cmd.Format(_T("git.exe mv %s-- \"%s\" \"%s\""), force, path.GetGitPathString(), path.GetGitOldPathString()); if (Run(cmd, &out, CP_UTF8)) { ::MessageBox(NULL, out, _T("TortoiseGit"), MB_OK|MB_ICONERROR); return -1; } cmd.Format(_T("git.exe checkout %s -f -- \"%s\""), commit, path.GetGitOldPathString()); if (Run(cmd, &out, CP_UTF8)) { ::MessageBox(NULL, out, _T("TortoiseGit"), MB_OK|MB_ICONERROR); return -1; } } else 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 -f --cached -- \"%s\""),path.GetGitPathString()); if (Run(cmd, &out, CP_UTF8)) { ::MessageBox(NULL, out, _T("TortoiseGit"), MB_OK|MB_ICONERROR); return -1; } } else { cmd.Format(_T("git.exe checkout %s -f -- \"%s\""), commit, path.GetGitPathString()); if (Run(cmd, &out, CP_UTF8)) { ::MessageBox(NULL, out, _T("TortoiseGit"), MB_OK|MB_ICONERROR); return -1; } } if (path.m_Action & CTGitPath::LOGACTIONS_DELETED) { cmd.Format(_T("git.exe add -f -- \"%s\""), path.GetGitPathString()); if (Run(cmd, &out, CP_UTF8)) { ::MessageBox(NULL, out, _T("TortoiseGit"), MB_OK|MB_ICONERROR); return -1; } } return 0; }