/// <summary> /// /// </summary> /// <param name="component"></param> /// <returns></returns> public static string CloneOrCheckOutRepo(AsposeComponent component) { if (Directory.Exists(getLocalRepositoryPath(component))) { if (Directory.Exists(getLocalRepositoryPath(component) + "\\.git\\refs\\heads")) { if (Directory.GetFiles(getLocalRepositoryPath(component) + "\\.git\\refs\\heads").Length <= 0) { System.IO.DirectoryInfo directory = new System.IO.DirectoryInfo(getLocalRepositoryPath(component)); Empty(directory); } } } string repUrl = component.get_remoteExamplesRepository(); string localFolder = getLocalRepositoryPath(component); string error = string.Empty; checkAndCreateFolder(getLocalRepositoryPath(component)); try { CloneCommand clone = Git.CloneRepository(); clone.SetURI(repUrl); clone.SetDirectory(localFolder); Git repo = clone.Call(); //writer.Close(); repo.GetRepository().Close(); } catch (Exception ex) { try { var git = Git.Open(localFolder); //var repository = git.GetRepository(); //PullCommand pullCommand = git.Pull(); //pullCommand.Call(); //repository.Close(); var reset = git.Reset().SetMode(ResetCommand.ResetType.HARD).SetRef("origin/master").Call(); } catch (Exception ex2) { error = ex2.Message; } error = ex.Message; } return(error); }
/// <summary> /// /// </summary> /// <param name="component"></param> /// <returns></returns> public static string CloneOrCheckOutRepo(GroupDocsComponent component) { string repUrl = component.get_remoteExamplesRepository(); string localFolder = getLocalRepositoryPath(component); string error = string.Empty; checkAndCreateFolder(getLocalRepositoryPath(component)); try { CloneCommand clone = Git.CloneRepository(); clone.SetURI(repUrl); clone.SetDirectory(localFolder); Git repo = clone.Call(); //writer.Close(); repo.GetRepository().Close(); } catch (Exception ex) { try { var git = Git.Open(localFolder); //var repository = git.GetRepository(); //PullCommand pullCommand = git.Pull(); //pullCommand.Call(); //repository.Close(); var reset = git.Reset().SetMode(ResetCommand.ResetType.HARD).SetRef("origin/master").Call(); } catch (Exception ex2) { error = ex2.Message; } error = ex.Message; } return(error); }
/// <summary> /// リモートリポジトリをローカルへ複製する /// </summary> /// <param name="entity">エンティティ</param> /// <param name="monitor">モニター</param> public void CloneRepository(CloneEntity entity, BusyIndicatorProgressMonitor monitor) { FilePath directory = entity.Path; CloneCommand clone = new CloneCommand(); //clone.SetCloneAllBranches(true); clone.SetDirectory(directory); clone.SetURI(entity.Url); clone.SetProgressMonitor(monitor); if (entity.IsCredential) { UsernamePasswordCredentialsProvider user = new UsernamePasswordCredentialsProvider(entity.UserName, entity.PassWord); clone.SetCredentialsProvider(user); } BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += (s, evt) => { monitor.StartAction(); try { clone.Call(); } catch (JGitInternalException) { // TODO: } }; bw.RunWorkerCompleted += (s, evt) => { monitor.CompleteAction(); }; bw.RunWorkerAsync(); }
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); }