#include "GitConfig.h"\r
\r
#define MAX_DIRBUFFER 1000\r
+CString CGit::ms_LastMsysGitDir;\r
CGit g_Git;\r
CGit::CGit(void)\r
{\r
{\r
SECURITY_ATTRIBUTES sa;\r
HANDLE hRead, hWrite;\r
- HANDLE hStdioFile;\r
+ HANDLE hStdioFile = NULL;\r
\r
sa.nLength = sizeof(SECURITY_ATTRIBUTES);\r
sa.lpSecurityDescriptor=NULL;\r
_tdupenv_s(&oldpath,&size,_T("PATH")); \r
\r
CString path;\r
+ CString unterminated_path = str; // path to msysgit without semicolon\r
+ CString oldpath_s = oldpath;\r
path.Format(_T("%s;"),str);\r
- path+=oldpath;\r
-\r
- _tputenv_s(_T("PATH"),path);\r
-\r
+ // check msysgit not already in path\r
+ if ( oldpath_s.Find( path ) < 0 && oldpath_s.Right( unterminated_path.GetLength() ) != unterminated_path )\r
+ {\r
+ // not already there, see if we have to take out one we added last time\r
+ if ( ms_LastMsysGitDir != "" )\r
+ {\r
+ // we have added one so take it out\r
+ int index = oldpath_s.Find( ms_LastMsysGitDir );\r
+ if ( index >= 0 )\r
+ {\r
+ oldpath_s = oldpath_s.Left( index ) + \r
+ oldpath_s.Right( oldpath_s.GetLength() - (index+ms_LastMsysGitDir.GetLength()) );\r
+ }\r
+ }\r
+ // save the new msysdir path that we are about to add\r
+ ms_LastMsysGitDir = path;\r
+ // add the new one on the front of the existing path\r
+ path+=oldpath_s;\r
+ _tputenv_s(_T("PATH"),path);\r
+ }\r
free(oldpath);\r
\r
CString cmd,out;\r