3333#include < mach/mach.h>
3434#endif
3535
36+ #include " web_client.hpp"
37+
3638void replaceAll (std::string &str, const std::string &from,
3739 const std::string &to) {
3840 if (from.empty ()) {
@@ -87,12 +89,12 @@ std::string getPath() {
8789 return " " ;
8890}
8991
90- void execCmd (const std::string &cmd) {
92+ void execCmd (const std::string &cmd, bool fail_on_error = true ) {
9193 auto exit_code = system (cmd.c_str ());
9294 if (exit_code != 0 ) {
9395 Log::get ().error (" Error executing command (exit code " +
9496 std::to_string (exit_code) + " ): " + cmd,
95- true );
97+ fail_on_error );
9698 }
9799}
98100
@@ -117,7 +119,7 @@ void ensureEnv(const std::string &key, const std::string &value) {
117119 }
118120}
119121
120- void fixWindowsEnv () {
122+ void fixWindowsEnv (std::string project_dir ) {
121123 const std::string sys32 = " C:\\ WINDOWS\\ system32" ;
122124 ensureEnv (" COMSPEC" , sys32 + FILE_SEP + " cmd.exe" );
123125 ensureEnv (" SYSTEMROOT" , " C:\\ WINDOWS" );
@@ -131,22 +133,44 @@ void fixWindowsEnv() {
131133 program_files = std::string (p);
132134 }
133135 ensureTrailingFileSep (program_files);
136+ if (!project_dir.empty ()) {
137+ ensureTrailingFileSep (project_dir);
138+ }
134139 bool update = false ;
135140 if (path.find (" Git\\ cmd" ) == std::string::npos) {
136141 if (!path.empty ()) {
137142 path += " ;" ;
138143 }
139144 path += program_files + " Git\\ cmd" ;
145+ if (!project_dir.empty ()) {
146+ path += " ;" + project_dir + " git\\ cmd" ;
147+ }
140148 update = true ;
141149 }
142150 if (path.find (" Git\\ usr\\ bin" ) == std::string::npos) {
143151 if (!path.empty ()) {
144152 path += " ;" ;
145153 }
146154 path += program_files + " Git\\ usr\\ bin" ;
155+ if (!project_dir.empty ()) {
156+ path += " ;" + project_dir + " git\\ usr\\ bin" ;
157+ }
147158 update = true ;
148159 }
149160 if (update) {
161+ const std::string mingit_dir = project_dir + " git" ;
162+ if (!project_dir.empty () && !isDir (mingit_dir)) {
163+ ensureDir (mingit_dir);
164+ const std::string mingit_url =
165+ " https://github.com/git-for-windows/git/releases/download/"
166+ " v2.37.1.windows.1/MinGit-2.37.1-64-bit.zip" ;
167+ const std::string mingit_zip = project_dir + " mingit.zip" ;
168+ if (WebClient::get (mingit_url, mingit_zip, false , false )) {
169+ execCmd (" powershell -command \" Expand-Archive -Force '" + mingit_zip +
170+ " ' '" + mingit_dir + " '\" " );
171+ }
172+ std::remove (mingit_zip.c_str ());
173+ }
150174 putEnv (" PATH" , path);
151175 }
152176}
0 commit comments