Beispiel #1
0
        public override void Execute()
        {
            int exitCode = 0;

            this.CheckGVFltRunning();
            this.CheckNotInsideExistingRepo();

            string fullPath = GVFSEnlistment.ToFullPath(this.EnlistmentRootPath, this.GetDefaultEnlistmentRoot());

            if (fullPath == null)
            {
                this.ReportErrorAndExit("Unable to write to directory " + this.EnlistmentRootPath);
            }

            this.EnlistmentRootPath = fullPath;
            this.CacheServerUrl     = Enlistment.StripObjectsEndpointSuffix(this.CacheServerUrl);

            try
            {
                GVFSEnlistment enlistment;
                Result         cloneResult = new Result(false);

                using (JsonEtwTracer tracer = new JsonEtwTracer(GVFSConstants.GVFSEtwProviderName, "GVFSClone"))
                {
                    cloneResult = this.TryCreateEnlistment(out enlistment);
                    if (cloneResult.Success)
                    {
                        tracer.AddLogFileEventListener(
                            GVFSEnlistment.GetNewGVFSLogFileName(enlistment.GVFSLogsRoot, GVFSConstants.LogFileTypes.Clone),
                            EventLevel.Informational,
                            Keywords.Any);

                        tracer.WriteStartEvent(
                            enlistment.EnlistmentRoot,
                            enlistment.RepoUrl,
                            enlistment.CacheServerUrl,
                            new EventMetadata
                        {
                            { "Branch", this.Branch },
                            { "SingleBranch", this.SingleBranch },
                            { "NoMount", this.NoMount },
                            { "NoPrefetch", this.NoPrefetch }
                        });

                        this.Output.WriteLine("Clone parameters:");
                        this.Output.WriteLine("  Repo URL:     " + enlistment.RepoUrl);
                        this.Output.WriteLine("  Cache Server: " + (enlistment.CacheServerUrl == enlistment.RepoUrl ? "None" : enlistment.CacheServerUrl));
                        this.Output.WriteLine("  Destination:  " + enlistment.EnlistmentRoot);

                        this.ShowStatusWhileRunning(
                            () =>
                        {
                            cloneResult = this.TryClone(tracer, enlistment);
                            return(cloneResult.Success);
                        },
                            "Cloning");
                    }

                    if (!cloneResult.Success)
                    {
                        tracer.RelatedError(cloneResult.ErrorMessage);
                    }
                }

                if (cloneResult.Success)
                {
                    if (!this.NoPrefetch)
                    {
                        PrefetchVerb prefetch = new PrefetchVerb();
                        prefetch.EnlistmentRootPath = this.EnlistmentRootPath;
                        prefetch.Commits            = true;
                        prefetch.Execute();
                    }

                    if (this.NoMount)
                    {
                        this.Output.WriteLine("\r\nIn order to mount, first cd to within your enlistment, then call: ");
                        this.Output.WriteLine("gvfs mount");
                    }
                    else
                    {
                        MountVerb mount = new MountVerb();
                        mount.EnlistmentRootPath = this.EnlistmentRootPath;
                        mount.SkipMountedCheck   = true;
                        mount.SkipVersionCheck   = true;
                        mount.ServiceName        = this.ServiceName;

                        mount.Execute();
                    }
                }
                else
                {
                    this.Output.WriteLine("\r\nCannot clone @ {0}", this.EnlistmentRootPath);
                    this.Output.WriteLine("Error: {0}", cloneResult.ErrorMessage);
                    exitCode = (int)ReturnCode.GenericError;
                }
            }
            catch (AggregateException e)
            {
                this.Output.WriteLine("Cannot clone @ {0}:", this.EnlistmentRootPath);
                foreach (Exception ex in e.Flatten().InnerExceptions)
                {
                    this.Output.WriteLine("Exception: {0}", ex.ToString());
                }

                exitCode = (int)ReturnCode.GenericError;
            }
            catch (VerbAbortedException)
            {
                throw;
            }
            catch (Exception e)
            {
                this.ReportErrorAndExit("Cannot clone @ {0}: {1}", this.EnlistmentRootPath, e.ToString());
            }

            Environment.Exit(exitCode);
        }
Beispiel #2
0
        public override void Execute(ITracer tracer = null)
        {
            if (tracer != null)
            {
                throw new InvalidOperationException("Clone does not support being called with an existing tracer");
            }

            this.CheckElevated();
            this.CheckGVFltRunning();

            string fullPath = GVFSEnlistment.ToFullPath(this.EnlistmentRootPath, this.GetDefaultEnlistmentRoot());

            if (fullPath == null)
            {
                this.ReportErrorAndExit("Unable to write to directory " + this.EnlistmentRootPath);
            }

            this.EnlistmentRootPath = fullPath;

            this.Output.WriteLine();
            this.Output.WriteLine("Starting clone of {0} into {1}...", this.RepositoryURL, this.EnlistmentRootPath);
            this.Output.WriteLine();

            this.CacheServerUrl = Enlistment.StripObjectsEndpointSuffix(this.CacheServerUrl);

            try
            {
                GVFSEnlistment enlistment;

                Result cloneResult = this.TryCreateEnlistment(out enlistment);
                if (cloneResult.Success)
                {
                    using (JsonEtwTracer cloneTracer = new JsonEtwTracer(GVFSConstants.GVFSEtwProviderName, "GVFSClone"))
                    {
                        cloneTracer.AddLogFileEventListener(
                            GVFSEnlistment.GetNewGVFSLogFileName(
                                Path.Combine(this.EnlistmentRootPath, GVFSConstants.DotGVFSPath, GVFSConstants.GVFSLogFolderName),
                                this.VerbName),
                            EventLevel.Informational,
                            Keywords.Any);
                        cloneTracer.AddConsoleEventListener(EventLevel.Informational, Keywords.Any);
                        cloneTracer.WriteStartEvent(
                            enlistment.EnlistmentRoot,
                            enlistment.RepoUrl,
                            enlistment.CacheServerUrl,
                            new EventMetadata
                        {
                            { "Branch", this.Branch },
                            { "SingleBranch", this.SingleBranch },
                            { "NoMount", this.NoMount },
                            { "NoPrefetch", this.NoPrefetch }
                        });

                        cloneResult = this.TryClone(cloneTracer, enlistment);

                        if (cloneResult.Success)
                        {
                            this.Output.WriteLine("GVFS Enlistment created @ {0}", this.EnlistmentRootPath);

                            if (!this.NoPrefetch)
                            {
                                PrefetchVerb prefetch = new PrefetchVerb();
                                prefetch.EnlistmentRootPath = this.EnlistmentRootPath;
                                prefetch.Commits            = true;
                                prefetch.Execute(cloneTracer);
                            }

                            if (this.NoMount)
                            {
                                this.Output.WriteLine("\r\nIn order to mount, first cd to within your enlistment, then call: ");
                                this.Output.WriteLine(CloneVerb.MountVerb);
                            }
                            else
                            {
                                MountVerb mount = new MountVerb();
                                mount.EnlistmentRootPath = this.EnlistmentRootPath;

                                // Tracer will be disposed in mount.Execute to avoid conflicts with the background process.
                                mount.Execute(cloneTracer);
                            }
                        }
                    }
                }

                // Write to the output after the tracer is disposed so that the error is the last message
                // displayed to the user
                if (!cloneResult.Success)
                {
                    this.Output.WriteLine("\r\nCannot clone @ {0}", this.EnlistmentRootPath);
                    this.Output.WriteLine("Error: {0}", cloneResult.ErrorMessage);
                    Environment.ExitCode = (int)ReturnCode.GenericError;
                }
            }
            catch (AggregateException e)
            {
                this.Output.WriteLine("Cannot clone @ {0}:", this.EnlistmentRootPath);
                foreach (Exception ex in e.Flatten().InnerExceptions)
                {
                    this.Output.WriteLine("Exception: {0}", ex.ToString());
                }

                Environment.ExitCode = (int)ReturnCode.GenericError;
            }
            catch (VerbAbortedException)
            {
                throw;
            }
            catch (Exception e)
            {
                this.ReportErrorAndExit("Cannot clone @ {0}: {1}", this.EnlistmentRootPath, e.ToString());
            }
        }