private void MountAndStartWorkingDirectoryCallbacks(GVFSContext context) { HttpGitObjects httpGitObjects = new HttpGitObjects(context.Tracer, context.Enlistment, Environment.ProcessorCount); if (!httpGitObjects.TryRefreshCredentials()) { this.FailMountAndExit("Failed to obtain git credentials"); } // Checking the disk layout version is done before this point in GVFS.CommandLine.MountVerb.PreExecute RepoMetadata repoMetadata = new RepoMetadata(this.enlistment.DotGVFSRoot); this.gitObjects = new GVFSGitObjects(context, httpGitObjects); this.gvfltCallbacks = this.CreateOrReportAndExit(() => new GVFltCallbacks(context, this.gitObjects, repoMetadata), "Failed to create src folder callbacks"); int persistedVersion; string error; if (!repoMetadata.TryGetOnDiskLayoutVersion(out persistedVersion, out error)) { this.FailMountAndExit("Error: {0}", error); } if (!repoMetadata.OnDiskVersionUsesAlwaysExclude()) { // Want this as close to repoMetadata.SaveCurrentDiskLayoutVersion() as possible to avoid possible corrupt states. this.UpdateToAlwaysExcludeFile(repoMetadata); } try { if (!this.gvfltCallbacks.TryStart(out error)) { this.FailMountAndExit("Error: {0}. \r\nPlease confirm that gvfs clone completed without error.", error); } } catch (Exception e) { this.FailMountAndExit("Failed to initialize src folder callbacks. {0}", e.ToString()); } repoMetadata.SaveCurrentDiskLayoutVersion(); repoMetadata.SetAlwaysExcludeInvalid(false); this.AcquireFolderLocks(context); this.heartbeat = new HeartbeatThread(this.tracer, this.gvfltCallbacks); this.heartbeat.Start(); }
private void MountAndStartWorkingDirectoryCallbacks(GVFSContext context, CacheServerInfo cache) { string error; if (!context.Enlistment.Authentication.TryRefreshCredentials(context.Tracer, out error)) { this.FailMountAndExit("Failed to obtain git credentials: " + error); } // Checking the disk layout version is done before this point in GVFS.CommandLine.MountVerb RepoMetadata repoMetadata = new RepoMetadata(this.enlistment.DotGVFSRoot); GitObjectsHttpRequestor objectRequestor = new GitObjectsHttpRequestor(context.Tracer, context.Enlistment, cache, this.retryConfig); this.gitObjects = new GVFSGitObjects(context, objectRequestor); this.gvfltCallbacks = this.CreateOrReportAndExit(() => new GVFltCallbacks(context, this.gitObjects, repoMetadata), "Failed to create src folder callbacks"); int persistedVersion; if (!repoMetadata.TryGetOnDiskLayoutVersion(out persistedVersion, out error)) { this.FailMountAndExit("Error: {0}", error); } try { if (!this.gvfltCallbacks.TryStart(out error)) { this.FailMountAndExit("Error: {0}. \r\nPlease confirm that gvfs clone completed without error.", error); } } catch (Exception e) { this.FailMountAndExit("Failed to initialize src folder callbacks. {0}", e.ToString()); } try { repoMetadata.SaveCurrentDiskLayoutVersion(); } catch (Exception ex) { this.FailMountAndExit("Failed to update repo disk layout version: {0}", ex.ToString()); } this.AcquireFolderLocks(context); this.heartbeat = new HeartbeatThread(this.tracer, this.gvfltCallbacks); this.heartbeat.Start(); }
public void Mount(EventLevel verbosity, Keywords keywords) { this.currentState = MountState.Mounting; if (Environment.CurrentDirectory != this.enlistment.EnlistmentRoot) { Environment.CurrentDirectory = this.enlistment.EnlistmentRoot; } this.StartNamedPipe(); this.AcquireRepoMutex(); // Checking the disk layout version is done before this point in GVFS.CommandLine.MountVerb.PreExecute using (RepoMetadata repoMetadata = new RepoMetadata(this.enlistment.DotGVFSRoot)) { repoMetadata.SaveCurrentDiskLayoutVersion(); } GVFSContext context = this.CreateContext(); this.ValidateMountPoints(); this.UpdateHooks(); this.gvfsLock = context.Repository.GVFSLock; this.MountAndStartWorkingDirectoryCallbacks(context); Console.Title = "GVFS " + ProcessHelper.GetCurrentProcessVersion() + " - " + this.enlistment.EnlistmentRoot; this.tracer.RelatedEvent( EventLevel.Critical, "Mount", new EventMetadata { { "Message", "Virtual repo is ready" }, }); this.currentState = MountState.Ready; }
public CloneVerb.Result CreateClone(GitRefs refs, string branch) { GitObjects gitObjects = new GitObjects(this.tracer, this.enlistment, this.objectRequestor); CloneVerb.Result initRepoResult = this.TryInitRepo(refs, this.enlistment); if (!initRepoResult.Success) { return(initRepoResult); } string errorMessage; if (!this.enlistment.TryConfigureAlternate(out errorMessage)) { return(new CloneVerb.Result("Error configuring alternate: " + errorMessage)); } if (!gitObjects.TryDownloadAndSaveCommit(refs.GetTipCommitId(branch), commitDepth: 2)) { return(new CloneVerb.Result("Could not download tip commits from: " + Uri.EscapeUriString(this.objectRequestor.CacheServer.ObjectsEndpointUrl))); } GitProcess git = new GitProcess(this.enlistment); if (!this.SetConfigSettings(git, this.objectRequestor.CacheServer)) { return(new CloneVerb.Result("Unable to configure git repo")); } string originBranchName = "origin/" + branch; GitProcess.Result createBranchResult = git.CreateBranchWithUpstream(branch, originBranchName); if (createBranchResult.HasErrors) { return(new CloneVerb.Result("Unable to create branch '" + originBranchName + "': " + createBranchResult.Errors + "\r\n" + createBranchResult.Output)); } File.WriteAllText( Path.Combine(this.enlistment.WorkingDirectoryRoot, GVFSConstants.DotGit.Head), "ref: refs/heads/" + branch); File.AppendAllText( Path.Combine(this.enlistment.WorkingDirectoryRoot, GVFSConstants.DotGit.Info.SparseCheckoutPath), GVFSConstants.GitPathSeparatorString + GVFSConstants.SpecialGitFiles.GitAttributes + "\n"); CloneVerb.Result hydrateResult = this.HydrateRootGitAttributes(gitObjects, branch); if (!hydrateResult.Success) { return(hydrateResult); } this.CreateGitScript(); GitProcess.Result forceCheckoutResult = git.ForceCheckout(branch); if (forceCheckoutResult.HasErrors) { string[] errorLines = forceCheckoutResult.Errors.Split('\n'); StringBuilder checkoutErrors = new StringBuilder(); foreach (string gitError in errorLines) { if (IsForceCheckoutErrorCloneFailure(gitError)) { checkoutErrors.AppendLine(gitError); } } if (checkoutErrors.Length > 0) { string error = "Could not complete checkout of branch: " + branch + ", " + checkoutErrors.ToString(); this.tracer.RelatedError(error); return(new CloneVerb.Result(error)); } } GitProcess.Result updateIndexresult = git.UpdateIndexVersion4(); if (updateIndexresult.HasErrors) { string error = "Could not update index, error: " + updateIndexresult.Errors; this.tracer.RelatedError(error); return(new CloneVerb.Result(error)); } string installHooksError; if (!HooksInstaller.InstallHooks(this.enlistment, out installHooksError)) { this.tracer.RelatedError(installHooksError); return(new CloneVerb.Result(installHooksError)); } using (RepoMetadata repoMetadata = new RepoMetadata(this.enlistment.DotGVFSRoot)) { repoMetadata.SaveCurrentDiskLayoutVersion(); } // Prepare the working directory folder for GVFS last to ensure that gvfs mount will fail if gvfs clone has failed string prepGVFltError; if (!GVFltCallbacks.TryPrepareFolderForGVFltCallbacks(this.enlistment.WorkingDirectoryRoot, out prepGVFltError)) { this.tracer.RelatedError(prepGVFltError); return(new CloneVerb.Result(prepGVFltError)); } return(new CloneVerb.Result(true)); }