OSDN Git Service

Add context menu item "Revert" at Commit File List
[tortoisegit/TortoiseGitJp.git] / src / Git / Git.cpp
index 6208576..024d6bd 100644 (file)
@@ -120,27 +120,6 @@ CGit g_Git;
 static LPTSTR l_processEnv = NULL;\r
 \r
 \r
-BOOL CGit::IsVista()\r
-{\r
-\r
-       if( CRegStdWORD(_T("Software\\TortoiseGit\\CacheType") ) == 0)\r
-       {\r
-               return TRUE;\r
-       }\r
-\r
-       OSVERSIONINFO osvi;\r
-    BOOL bIsWindowsXPorLater;\r
-\r
-    ZeroMemory(&osvi, sizeof(OSVERSIONINFO));\r
-    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);\r
-\r
-    GetVersionEx(&osvi);\r
-       \r
-       if(osvi.dwMajorVersion >= 6)\r
-               return TRUE;\r
-       else\r
-               return FALSE;\r
-}\r
 \r
 CGit::CGit(void)\r
 {\r
@@ -957,6 +936,44 @@ BOOL CGit::CheckCleanWorkTree()
 \r
        return TRUE;\r
 }\r
+int CGit::Revert(CTGitPathList &list,bool keep)\r
+{\r
+       int ret;\r
+       for(int i=0;i<list.GetCount();i++)\r
+       {       \r
+               ret = Revert((CTGitPath&)list[i],keep);\r
+               if(ret)\r
+                       return ret;\r
+       }\r
+       return 0;\r
+}\r
+int CGit::Revert(CTGitPath &path,bool keep)\r
+{\r
+       CString cmd, out;\r
+       if(path.m_Action & CTGitPath::LOGACTIONS_ADDED)\r
+       {       //To init git repository, there are not HEAD, so we can use git reset command\r
+               cmd.Format(_T("git.exe rm --cache -- \"%s\""),path.GetGitPathString());\r
+               if(g_Git.Run(cmd,&out,CP_OEMCP))\r
+                       return -1;\r
+       }\r
+       else if(path.m_Action & CTGitPath::LOGACTIONS_REPLACED )\r
+       {\r
+               cmd.Format(_T("git.exe mv \"%s\" \"%s\""),path.GetGitPathString(),path.GetGitOldPathString());\r
+               if(g_Git.Run(cmd,&out,CP_OEMCP))\r
+                       return -1;\r
+               \r
+               cmd.Format(_T("git.exe checkout -f -- \"%s\""),path.GetGitOldPathString());\r
+               if(g_Git.Run(cmd,&out,CP_OEMCP))\r
+                       return -1;\r
+       }\r
+       else\r
+       {\r
+               cmd.Format(_T("git.exe checkout -f -- \"%s\""),path.GetGitPathString());\r
+               if(g_Git.Run(cmd,&out,CP_OEMCP))\r
+                       return -1;\r
+       }\r
+       return 0;\r
+}\r
 \r
 int CGit::ListConflictFile(CTGitPathList &list,CTGitPath *path)\r
 {\r