| 161 | } |
| 162 | |
| 163 | Result Context::fetchModule(const fs::path& name, bool recursive) { |
| 164 | Result res; |
| 165 | |
| 166 | auto modCtx = res.addScopedContext({{"Module Name", name.string()}}); |
| 167 | |
| 168 | if (name == "lang") { return res; } |
| 169 | |
| 170 | // get the url |
| 171 | std::string url; |
| 172 | std::string cloneInto; |
| 173 | VCSType type; |
| 174 | std::tie(type, url, cloneInto) = resolveUrlFromModuleName(name); |
| 175 | |
| 176 | // see if it exists |
| 177 | auto fileName = workspacePath() / "src" / fs::path(name).replace_extension(".chimod"); |
| 178 | bool exists = fs::is_regular_file(fileName); |
| 179 | |
| 180 | if (exists) { |
| 181 | // try to pull it |
| 182 | |
| 183 | // see if it's actually a git repository |
| 184 | auto repoPath = workspacePath() / "src" / cloneInto; |
| 185 | if (cloneInto == "" || !fs::is_directory(repoPath / ".git")) { |
| 186 | // it's not a git repo, just exit |
| 187 | |
| 188 | return res; |
| 189 | } |
| 190 | |
| 191 | auto repoPathCtx = res.addScopedContext({{"Repo Path", repoPath}}); |
| 192 | |
| 193 | if (type == VCSType::Unknown) { |
| 194 | res.addEntry("EUKN", "Could not resolve URL for module", {}); |
| 195 | return res; |
| 196 | } |
| 197 | assert(type == VCSType::Git); |
| 198 | |
| 199 | // open the repository |
| 200 | git_repository* repo; |
| 201 | int err = git_repository_open(&repo, repoPath.string().c_str()); |
| 202 | if (err != 0) { |
| 203 | res.addEntry("EUKN", "Failed to open git repository", |
| 204 | {{"Error Message", giterr_last()->message}}); |
| 205 | return res; |
| 206 | } |
| 207 | |
| 208 | // get the remote |
| 209 | git_remote* origin; |
| 210 | err = git_remote_lookup(&origin, repo, "origin"); |
| 211 | if (err != 0) { |
| 212 | res.addEntry("EUKN", "Failed to get remote origin", |
| 213 | {{"Error Message", giterr_last()->message}}); |
| 214 | return res; |
| 215 | } |
| 216 | |
| 217 | // fetch |
| 218 | git_fetch_options opts = GIT_FETCH_OPTIONS_INIT; |
| 219 | err = git_remote_fetch(origin, nullptr, &opts, nullptr); |
| 220 | if (err != 0) { |
no test coverage detected