public InstallerMessage SetRepository(string uri, string user, string password, bool replaceExisting = false) { LastException = null; try { if (RepoIsClonned()) { if (replaceExisting) { try { Directory.Delete(_repoPath, true); } catch (Exception e) { throw new Exception("Could not delete current repository. " + e.Message); } } else { if (!GitHelper.isValidLocalRepository(Path.Combine(_repoPath, @".git"))) throw new Exception("There are files stored where the repository would be cloned. Clone canceled"); var repo = new FileRepository(Path.Combine(_repoPath, @".git")); var c = repo.GetConfig(); var remoteUrl = c.GetString("remote", "origin", "url"); var isSameRepo = remoteUrl != uri; if (!isSameRepo) { var remotes = c.GetSubsections("remote"); foreach (var remote in remotes) { var rUrl = c.GetString("remote", remote, "url"); if (String.IsNullOrEmpty(remoteUrl)) // let's keep the first we find remoteUrl = rUrl; if (rUrl == uri) { isSameRepo = true; break; } } if (!isSameRepo) { if (!String.IsNullOrEmpty(remoteUrl)) throw new Exception("There is already a repository pointing to " + remoteUrl + " where the wiki should be cloned."); throw new Exception("There is already a repository where the wiki should be cloned."); } } return InstallerMessage.Success; } } if (!Directory.Exists(_repoPath)) { if (!Directory.Exists(Path.Combine(_appRoot, "App_Data"))) Directory.CreateDirectory(Path.Combine(_appRoot, "App_Data")); Directory.CreateDirectory(_repoPath); } var cmd = new CloneCommand(); if(!String.IsNullOrEmpty(user)) cmd.SetCredentialsProvider(new UsernamePasswordCredentialsProvider(user, password)); cmd.SetURI(uri); cmd.SetCloneSubmodules(true); cmd.SetDirectory(_repoPath); cmd.Call(); } catch (Exception e) { LastException = e; return InstallerMessage.ExceptionThrown; } if (RepoIsClonned()) { WG.Settings.Repository = uri; return InstallerMessage.Success; } return InstallerMessage.UnkownFailure; }
public static void Clone(string fromUrl, DirectoryInfo toPath, bool isQuiet) { CloneCommand cmd = new CloneCommand(); if (cmd != null) { cmd.Path = fromUrl; cmd.Directory = toPath.FullName; cmd.Quiet = isQuiet; cmd.Execute(); } }
/// <summary> /// Clone a repository and checkout the working directory only if bare == false /// </summary> /// <param name="fromUrl"></param> /// <param name="toPath"></param> /// <param name="bare"></param> /// <returns></returns> public static Repository Clone(string fromUrl, string toPath, bool bare) { CloneCommand cmd = new CloneCommand() { Source = fromUrl, GitDirectory = toPath, Bare=bare, }; return Clone(cmd); }
public static Repository Clone(CloneCommand command) { command.Execute(); return command.Repository; }
public static void Clone(CloneCommand command) { command.Execute(); }