public MockFileSystemCallbacks(
     GVFSContext context,
     GVFSGitObjects gitObjects,
     RepoMetadata repoMetadata,
     BlobSizes blobSizes,
     GitIndexProjection gitIndexProjection,
     BackgroundFileSystemTaskRunner backgroundFileSystemTaskRunner,
     FileSystemVirtualizer fileSystemVirtualizer,
     IPlaceholderCollection placeholderDatabase)
     : base(context, gitObjects, repoMetadata, blobSizes, gitIndexProjection, backgroundFileSystemTaskRunner, fileSystemVirtualizer, placeholderDatabase)
 {
 }
 public FileSystemCallbacks(GVFSContext context, GVFSGitObjects gitObjects, RepoMetadata repoMetadata, FileSystemVirtualizer fileSystemVirtualizer, GitStatusCache gitStatusCache)
     : this(
         context,
         gitObjects,
         repoMetadata,
         new BlobSizes(context.Enlistment.BlobSizesRoot, context.FileSystem, context.Tracer),
         gitIndexProjection : null,
         backgroundFileSystemTaskRunner : null,
         fileSystemVirtualizer : fileSystemVirtualizer,
         gitStatusCache : gitStatusCache)
 {
 }
Esempio n. 3
0
        private void PopulateNamedEntrySizes(
            GVFSGitObjects gitObjects,
            PersistentDictionary <string, long> blobSizes,
            string parentVirtualPath,
            GVFSContext context,
            IEnumerable <GitTreeEntry> entries)
        {
            List <GitTreeEntry> blobs = entries.Where(e => e.IsBlob).ToList();

            // Then try to find as many blob sizes locally as possible.
            List <GitTreeEntry> entriesMissingSizes = new List <GitTreeEntry>();

            foreach (GitTreeEntry namedEntry in blobs.Where(b => b.Size == 0))
            {
                long blobLength = 0;
                if (blobSizes.TryGetValue(namedEntry.Sha, out blobLength))
                {
                    namedEntry.Size = blobLength;
                }
                else if (gitObjects.TryGetBlobSizeLocally(namedEntry.Sha, out blobLength))
                {
                    namedEntry.Size           = blobLength;
                    blobSizes[namedEntry.Sha] = blobLength;
                }
                else
                {
                    entriesMissingSizes.Add(namedEntry);
                }
            }

            // Anything remaining should come from the remote.
            if (entriesMissingSizes.Count > 0)
            {
                Dictionary <string, long> objectLengths = gitObjects.GetFileSizes(entriesMissingSizes.Select(e => e.Sha).Distinct()).ToDictionary(s => s.Id, s => s.Size, StringComparer.OrdinalIgnoreCase);
                foreach (GitTreeEntry namedEntry in entriesMissingSizes)
                {
                    long blobLength = 0;
                    if (objectLengths.TryGetValue(namedEntry.Sha, out blobLength))
                    {
                        namedEntry.Size           = blobLength;
                        blobSizes[namedEntry.Sha] = blobLength;
                    }
                    else
                    {
                        EventMetadata metadata = new EventMetadata();
                        metadata.Add("ErrorMessage", "GvFltException: Failed to download size for: " + namedEntry.Name + ", SHA: " + namedEntry.Sha);
                        context.Tracer.RelatedError(metadata, Keywords.Network);
                        throw new GvFltException(StatusCode.StatusFileNotAvailable);
                    }
                }
            }
        }
Esempio n. 4
0
        private void TestSetup()
        {
            this.gitProcess = new MockGitProcess();

            // Create enlistment using git process
            GVFSEnlistment enlistment = new MockGVFSEnlistment(this.gitProcess);

            PhysicalFileSystem fileSystem = new MockFileSystem(new MockDirectory(enlistment.EnlistmentRoot, null, null));

            // Create and return Context
            this.tracer = new MockTracer();
            this.context = new GVFSContext(this.tracer, fileSystem, repository: null, enlistment: enlistment);
        }
Esempio n. 5
0
        public static bool TryUpdateHooks(GVFSContext context, out string errorMessage)
        {
            errorMessage = string.Empty;
            foreach (HookData hook in NativeHooks)
            {
                if (!TryUpdateHook(context, hook, out errorMessage))
                {
                    return(false);
                }
            }

            return(true);
        }
        protected FileSystemVirtualizer(GVFSContext context, GVFSGitObjects gvfsGitObjects, int numWorkerThreads)
        {
            if (numWorkerThreads <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(numWorkerThreads), numWorkerThreads, "Number of threads must be greater than 0");
            }

            this.Context                = context;
            this.GitObjects             = gvfsGitObjects;
            this.fileAndNetworkRequests = new BlockingCollection <FileOrNetworkRequest>();

            this.numWorkerThreads = numWorkerThreads;
        }
Esempio n. 7
0
        public override bool TryInstallGitCommandHooks(GVFSContext context, string executingDirectory, string hookName, string commandHookPath, out string errorMessage)
        {
            errorMessage = null;

            string gvfsHooksPath = Path.Combine(executingDirectory, GVFSPlatform.Instance.Constants.GVFSHooksExecutableName);

            File.WriteAllText(
                commandHookPath,
                $"#!/bin/sh\n{gvfsHooksPath} {hookName} \"$@\"");
            GVFSPlatform.Instance.FileSystem.ChangeMode(commandHookPath, Convert.ToUInt16("755", 8));

            return(true);
        }
        private GVFSGitObjects CreateTestableGVFSGitObjects(MockHttpGitObjects httpObjects, MockFileSystemWithCallbacks fileSystem)
        {
            MockTracer     tracer     = new MockTracer();
            GVFSEnlistment enlistment = new GVFSEnlistment(TestEnlistmentRoot, "https://fakeRepoUrl", "fakeGitBinPath", authentication: null);

            enlistment.InitializeCachePathsFromKey(TestLocalCacheRoot, TestObjectRoot);
            GitRepo repo = new GitRepo(tracer, enlistment, fileSystem, () => new MockLibGit2Repo(tracer));

            GVFSContext    context = new GVFSContext(tracer, fileSystem, repo, enlistment);
            GVFSGitObjects dut     = new GVFSGitObjects(context, httpObjects);

            return(dut);
        }
Esempio n. 9
0
        public override FixResult TryFixIssues(List <string> messages)
        {
            string indexBackupPath = null;

            if (File.Exists(this.indexPath))
            {
                if (!this.TryRenameToBackupFile(this.indexPath, out indexBackupPath, messages))
                {
                    return(FixResult.Failure);
                }
            }

            HashSet <string> sparseCheckoutFiles = null;

            if (File.Exists(this.sparseCheckoutPath))
            {
                GVFSContext context = new GVFSContext(
                    this.Tracer,
                    new PhysicalFileSystem(),
                    repository: null,
                    enlistment: this.Enlistment);

                SparseCheckout sparseCheckout = new SparseCheckout(context, this.sparseCheckoutPath);
                sparseCheckout.LoadOrCreate();
                sparseCheckoutFiles = new HashSet <string>(sparseCheckout.Entries.Select(line => line.TrimStart('/')));
            }

            GitIndexGenerator indexGen = new GitIndexGenerator(this.Tracer, this.Enlistment, shouldHashIndex: false);

            indexGen.CreateFromHeadTree(indexVersion: 4, sparseCheckoutEntries: sparseCheckoutFiles);

            if (indexGen.HasFailures || this.TryParseIndex(this.indexPath, messages) != IssueType.None)
            {
                if (indexBackupPath != null)
                {
                    this.RestoreFromBackupFile(indexBackupPath, this.indexPath, messages);
                }

                return(FixResult.Failure);
            }

            if (indexBackupPath != null)
            {
                if (!this.TryDeleteFile(indexBackupPath))
                {
                    messages.Add("Warning: Could not delete backed up .git\\index at: " + indexBackupPath);
                }
            }

            return(FixResult.Success);
        }
Esempio n. 10
0
        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();
        }
Esempio n. 11
0
        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();
        }
Esempio n. 12
0
 public static bool EnlistmentRootReady(GVFSContext context)
 {
     // If a user locks their drive or disconnects an external drive while the mount process
     // is running, then it will appear as if the directories below do not exist or throw
     // a "Device is not ready" error.
     try
     {
         return(context.FileSystem.DirectoryExists(context.Enlistment.EnlistmentRoot) &&
                context.FileSystem.DirectoryExists(context.Enlistment.GitObjectsRoot));
     }
     catch (IOException)
     {
         return(false);
     }
 }
Esempio n. 13
0
        private void TestSetup()
        {
            ITracer tracer = new MockTracer();
            this.enlistment = new MockGVFSEnlistment();

            // We need to have the EnlistmentRoot and GitObjectsRoot available for jobs to run
            this.fileSystem = new ReadyFileSystem(new string[]
            {
                this.enlistment.EnlistmentRoot,
                this.enlistment.GitObjectsRoot
            });

            this.context = new GVFSContext(tracer, this.fileSystem, null, this.enlistment);
            this.gitObjects = new MockPhysicalGitObjects(tracer, this.fileSystem, this.enlistment, null);
        }
Esempio n. 14
0
        private static List <GitTreeEntry> GetProjectedEntries(GVFSContext context, DotGit.SparseCheckoutAndDoNotProject sparseCheckoutAndDoNotProject, string virtualPath, List <GitTreeEntry> treeEntries)
        {
            List <GitTreeEntry> projectedTreeEntries = new List <GitTreeEntry>();

            foreach (GitTreeEntry entry in treeEntries)
            {
                string entryVirtualPath = Path.Combine(virtualPath, entry.Name);
                if (sparseCheckoutAndDoNotProject.ShouldPathBeProjected(entryVirtualPath, entry.IsTree))
                {
                    projectedTreeEntries.Add(entry);
                }
            }

            return(projectedTreeEntries);
        }
Esempio n. 15
0
        private static string MergeHooks(GVFSContext context, string configSettingName, string hookName)
        {
            GitProcess configProcess = new GitProcess(context.Enlistment);
            string     filename;

            string[] defaultHooksLines = { };

            if (configProcess.TryGetFromConfig(configSettingName, forceOutsideEnlistment: true, value: out filename) && filename != null)
            {
                filename          = filename.Trim(' ', '\n');
                defaultHooksLines = File.ReadAllLines(filename);
            }

            return(HooksInstaller.MergeHooksData(defaultHooksLines, filename, hookName));
        }
Esempio n. 16
0
        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);
            }

            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.Instance), "Failed to create src folder callbacks");

            int persistedVersion;

            if (!RepoMetadata.Instance.TryGetOnDiskLayoutVersion(out persistedVersion, out error))
            {
                this.FailMountAndExit("Error: {0}", error);
            }

            if (persistedVersion != RepoMetadata.DiskLayoutVersion.CurrentDiskLayoutVersion)
            {
                this.FailMountAndExit(
                    "Error: On disk version ({0}) does not match current version ({1})",
                    persistedVersion,
                    RepoMetadata.DiskLayoutVersion.CurrentDiskLayoutVersion);
            }

            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());
            }

            this.AcquireFolderLocks(context);

            this.heartbeat = new HeartbeatThread(this.tracer, this.gvfltCallbacks);
            this.heartbeat.Start();
        }
Esempio n. 17
0
        public void Mount(EventLevel verbosity, Keywords keywords)
        {
            this.currentState = MountState.Mounting;

            // We must initialize repo metadata before starting the pipe server so it
            // can immediately handle status requests
            string error;

            if (!RepoMetadata.TryInitialize(this.tracer, this.enlistment.DotGVFSRoot, out error))
            {
                this.FailMountAndExit("Failed to load repo metadata: {0}", error);
            }

            using (NamedPipeServer pipeServer = this.StartNamedPipe())
            {
                GVFSContext context = this.CreateContext();

                if (context.Unattended)
                {
                    this.tracer.RelatedEvent(EventLevel.Critical, GVFSConstants.UnattendedEnvironmentVariable, null);
                }

                this.ValidateMountPoints();
                this.UpdateHooks();
                this.SetVisualStudioRegistryKey();

                this.gvfsLock = context.Repository.GVFSLock;
                this.MountAndStartWorkingDirectoryCallbacks(context, this.cacheServer);

                Console.Title = "GVFS " + ProcessHelper.GetCurrentProcessVersion() + " - " + this.enlistment.EnlistmentRoot;

                this.tracer.RelatedEvent(
                    EventLevel.Critical,
                    "Mount",
                    new EventMetadata
                {
                    // Use TracingConstants.MessageKey.InfoMessage rather than TracingConstants.MessageKey.CriticalMessage
                    // as this message should not appear as an error
                    { TracingConstants.MessageKey.InfoMessage, "Virtual repo is ready" },
                });

                this.currentState = MountState.Ready;

                this.unmountEvent.WaitOne();
            }
        }
Esempio n. 18
0
        public void Dispose()
        {
            if (this.BlobSizes != null)
            {
                this.BlobSizes.Dispose();
                this.BlobSizes = null;
            }

            if (this.fileSystemVirtualizer != null)
            {
                this.fileSystemVirtualizer.Dispose();
                this.fileSystemVirtualizer = null;
            }

            if (this.GitIndexProjection != null)
            {
                this.GitIndexProjection.Dispose();
                this.GitIndexProjection = null;
            }

            if (this.modifiedPaths != null)
            {
                this.modifiedPaths.Dispose();
                this.modifiedPaths = null;
            }

            if (this.gitStatusCache != null)
            {
                this.gitStatusCache.Dispose();
                this.gitStatusCache = null;
            }

            if (this.backgroundFileSystemTaskRunner != null)
            {
                this.backgroundFileSystemTaskRunner.Dispose();
                this.backgroundFileSystemTaskRunner = null;
            }

            if (this.context != null)
            {
                this.context.Dispose();
                this.context = null;
            }
        }
Esempio n. 19
0
        public static bool InstallHooks(GVFSContext context, out string error)
        {
            error = string.Empty;
            try
            {
                string installedReadObjectHookPath = Path.Combine(ExecutingDirectory, GVFSConstants.GVFSReadObjectHookExecutableName);
                string targetReadObjectHookPath    = Path.Combine(context.Enlistment.WorkingDirectoryRoot, GVFSConstants.DotGit.Hooks.ReadObjectPath + GVFSConstants.ExecutableExtension);
                if (!TryAction(() => CopyHook(context, installedReadObjectHookPath, targetReadObjectHookPath), out error))
                {
                    error = "Failed to copy " + installedReadObjectHookPath + "\n" + error;
                    return(false);
                }

                string installedVirtualFileSystemHookPath = Path.Combine(ExecutingDirectory, GVFSConstants.GVFSVirtualFileSystemHookExecutableName);
                string targetVirtualFileSystemHookPath    = Path.Combine(context.Enlistment.WorkingDirectoryRoot, GVFSConstants.DotGit.Hooks.VirtualFileSystemPath + GVFSConstants.ExecutableExtension);
                if (!TryAction(() => CopyHook(context, installedVirtualFileSystemHookPath, targetVirtualFileSystemHookPath), out error))
                {
                    error = "Failed to copy " + installedVirtualFileSystemHookPath + "\n" + error;
                    return(false);
                }

                string precommandHookPath = Path.Combine(context.Enlistment.WorkingDirectoryRoot, GVFSConstants.DotGit.Hooks.PreCommandPath);
                if (!TryInstallGitCommandHooks(context, GVFSConstants.DotGit.Hooks.PreCommandHookName, precommandHookPath, out error))
                {
                    return(false);
                }

                string postcommandHookPath = Path.Combine(context.Enlistment.WorkingDirectoryRoot, GVFSConstants.DotGit.Hooks.PostCommandPath);
                if (!TryInstallGitCommandHooks(context, GVFSConstants.DotGit.Hooks.PostCommandHookName, postcommandHookPath, out error))
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                error = e.ToString();
                return(false);
            }

            return(true);
        }
Esempio n. 20
0
        public GVFltFolder(
            GVFSContext context,
            GVFSGitObjects gitObjects,
            DotGit.SparseCheckoutAndDoNotProject sparseCheckoutAndDoNotProject,
            PersistentDictionary <string, long> blobSizes,
            string virtualPath,
            string projectedCommitId)
        {
            List <GitTreeEntry> treeEntries = context.Repository.GetTreeEntries(projectedCommitId, virtualPath).ToList();

            treeEntries = GetProjectedEntries(context, sparseCheckoutAndDoNotProject, virtualPath, treeEntries);
            this.PopulateNamedEntrySizes(gitObjects, blobSizes, virtualPath, context, treeEntries);

            this.entries = new List <GVFltFileInfo>();
            foreach (GitTreeEntry entry in treeEntries)
            {
                this.entries.Add(new GVFltFileInfo(entry.Name, entry.IsBlob ? entry.Size : 0, entry.IsTree));
            }

            this.entries.Sort(GVFltFileInfo.SortAlphabeticallyIgnoreCase());
        }
Esempio n. 21
0
        private bool TryPrefetchCommitsAndTrees(ITracer tracer, GVFSEnlistment enlistment, GitObjectsHttpRequestor objectRequestor)
        {
            PhysicalFileSystem fileSystem = new PhysicalFileSystem();
            GitRepo            repo       = new GitRepo(tracer, enlistment, fileSystem);
            GVFSContext        context    = new GVFSContext(tracer, fileSystem, repo, enlistment);
            GitObjects         gitObjects = new GVFSGitObjects(context, objectRequestor);

            string[] packs = gitObjects.ReadPackFileNames(GVFSConstants.PrefetchPackPrefix);
            long     max   = -1;

            foreach (string pack in packs)
            {
                long?timestamp = this.GetTimestamp(pack);
                if (timestamp.HasValue && timestamp > max)
                {
                    max = timestamp.Value;
                }
            }

            return(gitObjects.TryDownloadPrefetchPacks(max));
        }
Esempio n. 22
0
        public static void CreateHookCommandConfig(GVFSContext context, string hookName, string commandHookPath)
        {
            string targetPath = commandHookPath + GVFSConstants.GitConfig.HooksExtension;

            try
            {
                string configSetting = GVFSConstants.GitConfig.HooksPrefix + hookName;
                string mergedHooks   = MergeHooks(context, configSetting, hookName);

                string    contents = string.Format(HooksConfigContentTemplate, configSetting, mergedHooks);
                Exception ex;
                if (!context.FileSystem.TryWriteTempFileAndRename(targetPath, contents, out ex))
                {
                    throw new RetryableException("Error installing " + targetPath, ex);
                }
            }
            catch (IOException io)
            {
                throw new RetryableException("Error installing " + targetPath, io);
            }
        }
Esempio n. 23
0
        public void SetUp()
        {
            MockTracer tracer = new MockTracer();

            string enlistmentRoot  = Path.Combine("mock:", "GVFS", "UnitTests", "Repo");
            string statusCachePath = Path.Combine("mock:", "GVFS", "UnitTests", "Repo", GVFSPlatform.Instance.Constants.DotGVFSRoot, "gitStatusCache");

            this.gitProcess = new MockGitProcess();
            this.gitProcess.SetExpectedCommandResult($"--no-optional-locks status \"--serialize={statusCachePath}", () => new GitProcess.Result(string.Empty, string.Empty, 0), true);
            MockGVFSEnlistment enlistment = new MockGVFSEnlistment(enlistmentRoot, "fake://repoUrl", "fake://gitBinPath", this.gitProcess);

            enlistment.InitializeCachePathsFromKey("fake:\\gvfsSharedCache", "fakeCacheKey");

            this.gitParentPath    = enlistment.WorkingDirectoryBackingRoot;
            this.gvfsMetadataPath = enlistment.DotGVFSRoot;

            this.enlistmentDirectory = new MockDirectory(
                enlistmentRoot,
                new MockDirectory[]
            {
                new MockDirectory(this.gitParentPath, folders: null, files: null),
            },
                null);

            this.enlistmentDirectory.CreateFile(Path.Combine(this.gitParentPath, ".git", "config"), ".git config Contents", createDirectories: true);
            this.enlistmentDirectory.CreateFile(Path.Combine(this.gitParentPath, ".git", "HEAD"), ".git HEAD Contents", createDirectories: true);
            this.enlistmentDirectory.CreateFile(Path.Combine(this.gitParentPath, ".git", "logs", "HEAD"), "HEAD Contents", createDirectories: true);
            this.enlistmentDirectory.CreateFile(Path.Combine(this.gitParentPath, ".git", "info", "always_exclude"), "always_exclude Contents", createDirectories: true);
            this.enlistmentDirectory.CreateDirectory(Path.Combine(this.gitParentPath, ".git", "objects", "pack"));

            this.fileSystem = new MockFileSystem(this.enlistmentDirectory);
            this.fileSystem.AllowMoveFile = true;
            this.fileSystem.DeleteNonExistentFileThrowsException = false;

            this.context = new GVFSContext(
                tracer,
                this.fileSystem,
                new MockGitRepo(tracer, enlistment, this.fileSystem),
                enlistment);
        }
Esempio n. 24
0
        private static bool TryInstallGitCommandHooks(GVFSContext context, string hookName, string commandHookPath, out string errorMessage)
        {
            // The GitHooksLoader requires the following setup to invoke a hook:
            //      Copy GithooksLoader.exe to hook-name.exe
            //      Create a text file named hook-name.hooks that lists the applications to execute for the hook, one application per line

            string gitHooksloaderPath = Path.Combine(ExecutingDirectory, GVFSConstants.DotGit.Hooks.LoaderExecutable);

            if (!TryAction(() => CopyHook(context, gitHooksloaderPath, commandHookPath + GVFSConstants.ExecutableExtension), out errorMessage))
            {
                errorMessage = "Failed to copy " + GVFSConstants.DotGit.Hooks.LoaderExecutable + " to " + commandHookPath + GVFSConstants.ExecutableExtension + "\n" + errorMessage;
                return(false);
            }

            if (!TryAction(() => CreateHookCommandConfig(context, hookName, commandHookPath), out errorMessage))
            {
                errorMessage = "Failed to create " + commandHookPath + GVFSConstants.GitConfig.HooksExtension + "\n" + errorMessage;
                return(false);
            }

            return(true);
        }
Esempio n. 25
0
        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;
        }
Esempio n. 26
0
        public void Mount(EventLevel verbosity, Keywords keywords)
        {
            this.currentState = MountState.Mounting;
            if (Environment.CurrentDirectory != this.enlistment.EnlistmentRoot)
            {
                Environment.CurrentDirectory = this.enlistment.EnlistmentRoot;
            }

            using (NamedPipeServer pipeServer = this.StartNamedPipe())
            {
                this.AcquireRepoMutex();

                GVFSContext context = this.CreateContext();

                this.ValidateMountPoints();
                this.UpdateHooks();
                this.SetVisualStudioRegistryKey();

                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;

                this.unmountEvent.WaitOne();
            }
        }
Esempio n. 27
0
        public static bool InstallHooks(GVFSContext context, out string error)
        {
            error = string.Empty;
            try
            {
                foreach (HookData hook in NativeHooks)
                {
                    string installedHookPath = Path.Combine(ExecutingDirectory, hook.ExecutableName);
                    string targetHookPath    = Path.Combine(context.Enlistment.WorkingDirectoryBackingRoot, hook.Path + GVFSPlatform.Instance.Constants.ExecutableExtension);
                    if (!TryHooksInstallationAction(() => CopyHook(context, installedHookPath, targetHookPath), out error))
                    {
                        error = "Failed to copy " + installedHookPath + "\n" + error;
                        return(false);
                    }
                }

                string precommandHookPath = Path.Combine(context.Enlistment.WorkingDirectoryBackingRoot, GVFSConstants.DotGit.Hooks.PreCommandPath);
                if (!GVFSPlatform.Instance.TryInstallGitCommandHooks(context, ExecutingDirectory, GVFSConstants.DotGit.Hooks.PreCommandHookName, precommandHookPath, out error))
                {
                    return(false);
                }

                string postcommandHookPath = Path.Combine(context.Enlistment.WorkingDirectoryBackingRoot, GVFSConstants.DotGit.Hooks.PostCommandPath);
                if (!GVFSPlatform.Instance.TryInstallGitCommandHooks(context, ExecutingDirectory, GVFSConstants.DotGit.Hooks.PostCommandHookName, postcommandHookPath, out error))
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                error = e.ToString();
                return(false);
            }

            return(true);
        }
Esempio n. 28
0
        public static bool TryUpdateHooks(GVFSContext context, out string errorMessage)
        {
            if (!TryUpdateHook(
                    context,
                    GVFSConstants.DotGit.Hooks.ReadObjectName,
                    GVFSConstants.DotGit.Hooks.ReadObjectPath,
                    GVFSConstants.GVFSReadObjectHookExecutableName,
                    out errorMessage))
            {
                return(false);
            }

            if (!TryUpdateHook(
                    context,
                    GVFSConstants.DotGit.Hooks.VirtualFileSystemName,
                    GVFSConstants.DotGit.Hooks.VirtualFileSystemPath,
                    GVFSConstants.GVFSVirtualFileSystemHookExecutableName,
                    out errorMessage))
            {
                return(false);
            }

            return(true);
        }
Esempio n. 29
0
 public override bool TryInstallGitCommandHooks(GVFSContext context, string executingDirectory, string hookName, string commandHookPath, out string errorMessage)
 {
     throw new NotSupportedException();
 }
 public MacFileSystemVirtualizer(GVFSContext context, GVFSGitObjects gitObjects)
     : this(context, gitObjects, virtualizationInstance : null)
 {
 }