OSDN Git Service

restored the accidently removed quotes on igit command line
[tortoisegit/TortoiseGitJp.git] / src / Git / Git.cpp
index 3000113..4e5e951 100644 (file)
@@ -304,19 +304,24 @@ int CGit::Run(CString cmd, CString* output,int code)
 \r
 CString CGit::GetUserName(void)\r
 {\r
-       CString UserName;\r
-       Run(_T("git.exe config user.name"),&UserName,CP_UTF8);\r
-       int start = 0;\r
-       return UserName.Tokenize(_T("\n"),start);\r
+       return GetConfigValue(L"user.name");\r
 }\r
 CString CGit::GetUserEmail(void)\r
 {\r
-       CString UserName;\r
-       Run(_T("git.exe config user.email"),&UserName,CP_UTF8);\r
+       return GetConfigValue(L"user.email");\r
+}\r
+\r
+CString CGit::GetConfigValue(CString name)\r
+{\r
+       CString configValue;\r
+       CString cmd;\r
+       cmd.Format(L"git.exe config %s", name);\r
+       Run(cmd,&configValue,CP_UTF8);\r
        int start = 0;\r
-       return UserName.Tokenize(_T("\n"),start);\r
+       return configValue.Tokenize(_T("\n"),start);\r
 }\r
 \r
+\r
 CString CGit::GetCurrentBranch(void)\r
 {\r
        CString output;\r
@@ -339,6 +344,40 @@ CString CGit::GetCurrentBranch(void)
        return CString("");\r
 }\r
 \r
+CString CGit::GetSymbolicRef(const wchar_t* symbolicRefName, bool bStripRefsHeads)\r
+{\r
+       CString refName;\r
+       CString cmd;\r
+       cmd.Format(L"git symbolic-ref %s", symbolicRefName);\r
+       if(Run(cmd, &refName, CP_UTF8) != 0)\r
+               return CString();//Error\r
+       int iStart = 0;\r
+       refName = refName.Tokenize(L"\n", iStart);\r
+       if(bStripRefsHeads)\r
+               refName = StripRefName(refName);\r
+       return refName;\r
+}\r
+\r
+CString CGit::GetFullRefName(CString shortRefName)\r
+{\r
+       CString refName;\r
+       CString cmd;\r
+       cmd.Format(L"git rev-parse --symbolic-full-name %s", shortRefName);\r
+       if(Run(cmd, &refName, CP_UTF8) != 0)\r
+               return CString();//Error\r
+       int iStart = 0;\r
+       return refName.Tokenize(L"\n", iStart);\r
+}\r
+\r
+CString CGit::StripRefName(CString refName)\r
+{\r
+       if(wcsncmp(refName, L"refs/heads/", 11) == 0)\r
+               refName = refName.Mid(11);\r
+       else if(wcsncmp(refName, L"refs/", 5) == 0)\r
+               refName = refName.Mid(5);\r
+       return refName;\r
+}\r
+\r
 int CGit::GetCurrentBranchFromFile(const CString &sProjectRoot, CString &sBranchOut)\r
 {\r
        // read current branch name like git-gui does, by parsing the .git/HEAD file directly\r
@@ -1024,10 +1063,27 @@ BOOL CGit::EnumFiles(const TCHAR *pszProjectPath, const TCHAR *pszSubPath, unsig
                sMode = _T("-");\r
        }\r
 \r
+       // NOTE: there seems to be some issue with msys based app receiving backslash on commandline, at least\r
+       // if followed by " like for example 'igit "C:\"', the commandline igit receives is 'igit.exe C:" status' with\r
+       // the 'C:" status' part as a single arg, Maybe it uses unix style processing. In order to avoid this just\r
+       // use forward slashes for supplied project and sub paths\r
+\r
+       CString sProjectPath = pszProjectPath;\r
+       sProjectPath.Replace(_T('\\'), _T('/'));\r
+\r
        if (pszSubPath)\r
-               cmd.Format(_T("igit.exe \"%s\" status %s \"%s\""), pszProjectPath, sMode, pszSubPath);\r
+       {\r
+               CString sSubPath = pszSubPath;\r
+               sSubPath.Replace(_T('\\'), _T('/'));\r
+\r
+               cmd.Format(_T("igit.exe \"%s\" status %s \"%s\""), sProjectPath, sMode, sSubPath);\r
+       }\r
        else\r
-               cmd.Format(_T("igit.exe \"%s\" status %s"), pszProjectPath, sMode);\r
+       {\r
+               cmd.Format(_T("igit.exe \"%s\" status %s"), sProjectPath, sMode);\r
+       }\r
+\r
+       //OutputDebugStringA("---");OutputDebugStringW(cmd);OutputDebugStringA("\r\n");\r
 \r
        W_GitCall.SetCmd(cmd);\r
        // NOTE: should igit get added as a part of msysgit then use below line instead of the above one\r
@@ -1078,7 +1134,8 @@ int CGit::Revert(CTGitPath &path,bool keep)
        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
+               cmd.Format(_T("git.exe rm --cached \"%s\""),path.GetGitPathString());\r
+\r
                if(g_Git.Run(cmd,&out,CP_ACP))\r
                        return -1;\r
        }\r