Run() public method

public Run ( ) : int
return int
Ejemplo n.º 1
0
        public int Run(string tfsUrl, string tfsRepositoryPath, string gitRepositoryPath)
        {
            var currentDir           = Environment.CurrentDirectory;
            var repositoryDirCreated = InitGitDir(gitRepositoryPath);

            // TFS string representations of repository paths do not end in trailing slashes
            tfsRepositoryPath = (tfsRepositoryPath ?? string.Empty).TrimEnd('/');

            try
            {
                var retVal = init.Run(tfsUrl, tfsRepositoryPath, gitRepositoryPath);

                VerifyTfsPathToClone(tfsRepositoryPath);

                if (retVal == 0)
                {
                    retVal = fetch.Run();
                }
                if (retVal == 0)
                {
                    globals.Repository.CommandNoisy("merge", globals.Repository.ReadTfsRemote(globals.RemoteId).RemoteRef);
                }
                if (retVal == 0 && withBranches && initBranch != null)
                {
                    initBranch.CloneAllBranches = true;
                    retVal = initBranch.Run();
                }
                return(retVal);
            }
            catch
            {
                try
                {
                    // if we appeared to be inside repository dir when exception was thrown - we won't be able to delete it
                    Environment.CurrentDirectory = currentDir;
                    if (repositoryDirCreated)
                    {
                        Directory.Delete(gitRepositoryPath, recursive: true);
                    }
                    else
                    {
                        CleanDirectory(gitRepositoryPath);
                    }
                }
                catch (IOException e)
                {
                    // swallow IOException. Smth went wrong before this and we're much more interested in that error
                    string msg = String.Format("Something went wrong, can't cleanup files because of IOException:\n{0}\n", e.IndentExceptionMessage());
                    Trace.WriteLine(msg);
                }
                catch (UnauthorizedAccessException e)
                {
                    // swallow it also
                    string msg = String.Format("Something went wrong, can't cleanup files because of UnauthorizedAccessException:\n{0}\n", e.IndentExceptionMessage());
                    Trace.WriteLine(msg);
                }

                throw;
            }
        }
Ejemplo n.º 2
0
        public int Run(string tfsUrl, string tfsRepositoryPath, string gitRepositoryPath)
        {
            var currentDir           = Environment.CurrentDirectory;
            var repositoryDirCreated = InitGitDir(gitRepositoryPath);

            // TFS string representations of repository paths do not end in trailing slashes
            if (tfsRepositoryPath != GitTfsConstants.TfsRoot)
            {
                tfsRepositoryPath = (tfsRepositoryPath ?? string.Empty).TrimEnd('/');
            }

            int retVal = 0;

            try
            {
                if (repositoryDirCreated)
                {
                    retVal = init.Run(tfsUrl, tfsRepositoryPath, gitRepositoryPath);
                }
                else
                {
                    try
                    {
                        Environment.CurrentDirectory = gitRepositoryPath;
                        globals.Repository           = init.GitHelper.MakeRepository(globals.GitDir);
                    }
                    catch (Exception)
                    {
                        retVal = init.Run(tfsUrl, tfsRepositoryPath, gitRepositoryPath);
                    }
                }

                VerifyTfsPathToClone(tfsRepositoryPath);
            }
            catch
            {
                if (!resumable)
                {
                    try
                    {
                        // if we appeared to be inside repository dir when exception was thrown - we won't be able to delete it
                        Environment.CurrentDirectory = currentDir;
                        if (repositoryDirCreated)
                        {
                            Directory.Delete(gitRepositoryPath, recursive: true);
                        }
                        else
                        {
                            CleanDirectory(gitRepositoryPath);
                        }
                    }
                    catch (IOException e)
                    {
                        // swallow IOException. Smth went wrong before this and we're much more interested in that error
                        string msg = String.Format("warning: Something went wrong while cleaning file after internal error (See below).\n    Can't cleanup files because of IOException:\n{0}\n", e.IndentExceptionMessage());
                        Trace.WriteLine(msg);
                    }
                    catch (UnauthorizedAccessException e)
                    {
                        // swallow it also
                        string msg = String.Format("warning: Something went wrong while cleaning file after internal error (See below).\n    Can't cleanup files because of UnauthorizedAccessException:\n{0}\n", e.IndentExceptionMessage());
                        Trace.WriteLine(msg);
                    }
                }

                throw;
            }
            bool errorOccurs = false;

            try
            {
                if (withBranches && initBranch != null)
                {
                    fetch.IgnoreBranches = false;
                }

                if (tfsRepositoryPath == GitTfsConstants.TfsRoot)
                {
                    fetch.IgnoreBranches = true;
                }

                if (retVal == 0)
                {
                    fetch.Run(withBranches);
                    globals.Repository.GarbageCollect();
                }

                if (withBranches && initBranch != null)
                {
                    initBranch.CloneAllBranches = true;

                    retVal = initBranch.Run();
                }
            }
            catch (GitTfsException)
            {
                errorOccurs = true;
                throw;
            }
            catch (Exception ex)
            {
                errorOccurs = true;
                throw new GitTfsException("error: a problem occured when trying to clone the repository. Try to solve the problem described below.\nIn any case, after, try to continue using command `git tfs "
                                          + (withBranches ? "branch init --all" : "fetch") + "`\n", ex);
            }
            finally
            {
                try
                {
                    if (!init.IsBare)
                    {
                        globals.Repository.Merge(globals.Repository.ReadTfsRemote(globals.RemoteId).RemoteRef);
                    }
                }
                catch (Exception)
                {
                    //Swallow exception because the previously thrown exception is more important...
                    if (!errorOccurs)
                    {
                        throw;
                    }
                }
            }
            return(retVal);
        }