예제 #1
0
        /// <summary>
        /// Provides the custom hook for VisitDependency. This will only be called if the dependency
        /// was specified in the whitelist.
        /// </summary>
        /// <param name="directory">The directory of the project.</param>
        /// <param name="dependency">The <see cref="Dependency"/> to visit.</param>
        /// <returns></returns>
        protected override ReturnCode OnVisitDependency(string directory, Dependency dependency)
        {
            _git.WorkingDirectory = _fileSystem.Path.Combine(directory, dependency.Directory);
            var currBranch = _git.GetCurrentBranch();

            var code = ReturnCode.Success;

            _console.WriteLine("Verifying the checked out branch");

            if (currBranch != dependency.Branch)
            {
                var oldColor = _console.ForegroundColor;
                _console.ForegroundColor = ConsoleColor.Red;
                _console.WriteLine("Invalid Branch!");
                _console.WriteLine($"    expected {dependency.Branch} but was {currBranch}");
                _console.ForegroundColor = oldColor;

                bool goodChoice = false;
                do
                {
                    _console.WriteLine("What should I do?");
                    _console.WriteLine($"1. Update config to point to {currBranch}");
                    _console.WriteLine($"2. Switch branch to {dependency.Branch}");
                    _console.WriteLine("3. Give up. I'll figure it out myself.");
                    _console.Write("> ");
                    var choice = _console.ReadLine();

                    switch (choice)
                    {
                    case "1":
                        goodChoice = true;
                        code       = dependency.SyncConfigWithCurrentBranch(directory);
                        break;

                    case "2":
                        goodChoice = true;
                        code       = SwitchBranch(directory, dependency);
                        break;

                    case "3":
                        goodChoice = true;
                        code       = ReturnCode.InvalidBranchCheckedOut;
                        break;

                    default:
                        _console.WriteLine("Huh? Try again.");
                        break;
                    }
                } while (!goodChoice);
            }
            else
            {
                _console.WriteLine("everything looks good.");
            }
            _console.WriteLine();

            return(code);
        }
예제 #2
0
        /// <summary>
        /// Executes after all dependencies have been visited.
        /// </summary>
        /// <param name="options">The options for the command.</param>
        /// <returns></returns>
        protected override ReturnCode AfterDependencyTraversal(SyncSubOptions options)
        {
            string     dir;
            ReturnCode code;
            var        config = _factory.LoadFromDirectory(options.Directory, out dir, out code);

            if (code != ReturnCode.Success)
            {
                return(code);
            }

            bool dirty = false;

            foreach (var dep in config.Dependencies)
            {
                var path = _fileSystem.Path.GetFullPath(_fileSystem.Path.Combine(dir, dep.Directory));
                _git.WorkingDirectory = path;
                var branch = _git.GetCurrentBranch();

                if (dep.Branch != branch)
                {
                    dep.Branch = branch;
                    dirty      = true;
                    Console.WriteLine($"using {dep.Branch} for {dep.Configuration.Name}");
                }
            }

            if (dirty)
            {
                _fileSystem.File.WriteAllText(_fileSystem.Path.Combine(dir, "GitDepend.json"), config.ToString());
            }

            Console.WriteLine($"all dependency branches synchronized successfully!");

            return(ReturnCode.Success);
        }