Example #1
0
        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;
        }
Example #2
0
 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();
     }
 }
Example #3
0
 /// <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);
 }
Example #4
0
 public static Repository Clone(CloneCommand command)
 {
     command.Execute();
     return command.Repository;
 }
Example #5
0
 public static void Clone(CloneCommand command)
 {
     command.Execute();
 }