Пример #1
0
        private static void RunLockRequest(string[] args, bool unattended, LockRequestDelegate requestToRun)
        {
            try
            {
                if (ShouldLock(args))
                {
                    using (NamedPipeClient pipeClient = new NamedPipeClient(enlistmentPipename))
                    {
                        if (!pipeClient.Connect())
                        {
                            ExitWithError("The repo does not appear to be mounted. Use 'gvfs status' to check.");
                        }

                        int pid = GetParentPid(args);
                        if (pid == Program.InvalidProcessId ||
                            !GSDHooksPlatform.IsProcessActive(pid))
                        {
                            ExitWithError("GSD.Hooks: Unable to find parent git.exe process " + "(PID: " + pid + ").");
                        }

                        requestToRun(unattended, args, pid, pipeClient);
                    }
                }
            }
            catch (Exception exc)
            {
                ExitWithError(
                    "Unable to initialize Git command.",
                    "Ensure that GSD is running.",
                    exc.ToString());
            }
        }
Пример #2
0
        public static void Main(string[] args)
        {
            try
            {
                if (args.Length < 2)
                {
                    ExitWithError("Usage: gvfs.hooks.exe --git-pid=<pid> <hook> <git verb> [<other arguments>]");
                }

                bool unattended = GSDEnlistment.IsUnattended(tracer: null);

                string errorMessage;
                string normalizedCurrentDirectory;
                if (!GSDHooksPlatform.TryGetNormalizedPath(Environment.CurrentDirectory, out normalizedCurrentDirectory, out errorMessage))
                {
                    ExitWithError($"Failed to determine final path for current directory {Environment.CurrentDirectory}. Error: {errorMessage}");
                }

                if (!GSDHooksPlatform.TryGetGSDEnlistmentRoot(Environment.CurrentDirectory, out enlistmentRoot, out errorMessage))
                {
                    // Nothing to hook when being run outside of a GSD repo.
                    // This is also the path when run with --git-dir outside of a GSD directory, see Story #949665
                    Environment.Exit(0);
                }

                enlistmentPipename = GSDHooksPlatform.GetNamedPipeName(enlistmentRoot);

                switch (GetHookType(args))
                {
                case PreCommandHook:
                    CheckForLegalCommands(args);
                    RunPreCommands(args);
                    break;

                case PostCommandHook:
                    RunPostCommands(args, unattended);
                    break;

                default:
                    ExitWithError("Unrecognized hook: " + string.Join(" ", args));
                    break;
                }
            }
            catch (Exception ex)
            {
                ExitWithError("Unexpected exception: " + ex.ToString());
            }
        }
Пример #3
0
        private static void RemindUpgradeAvailable()
        {
            // The idea is to generate a random number between 0 and 100. To make
            // sure that the reminder is displayed only 10% of the times a git
            // command is run, check that the random number is between 0 and 10,
            // which will have a probability of 10/100 == 10%.
            int reminderFrequency = 10;
            int randomValue       = random.Next(0, 100);

            if (randomValue <= reminderFrequency &&
                ProductUpgraderInfo.IsLocalUpgradeAvailable(tracer: null, highestAvailableVersionDirectory: GSDHooksPlatform.GetUpgradeHighestAvailableVersionDirectory()))
            {
                Console.WriteLine(Environment.NewLine + GSDConstants.UpgradeVerbMessages.ReminderNotification);
            }
        }