Beispiel #1
0
 public void Checkout(string branchName)
 {
     _logger.Detailed($"Git checkout '{branchName}'");
     using (var repo = MakeRepo())
     {
         GitCommands.Checkout(repo, repo.Branches[branchName]);
     }
 }
 public void Commit(string message)
 {
     _logger.Detailed($"Git commit with message '{message}'");
     using (var repo = MakeRepo())
     {
         var signature = GetSignature(repo);
         GitCommands.Stage(repo, "*");
         repo.Commit(message, signature, signature);
     }
 }
 public void Checkout(string branchName)
 {
     _logger.Detailed($"Git checkout '{branchName}'");
     using (var repo = MakeRepo())
     {
         if (BranchExists(branchName))
         {
             GitCommands.Checkout(repo, repo.Branches[branchName]);
         }
         else
         {
             throw new NuKeeperException(
                       $"Git Cannot checkout branch: the branch named '{branchName}' doesn't exist");
         }
     }
 }
Beispiel #4
0
        public void CheckoutNewBranch(string branchName)
        {
            var qualifiedBranchName = "origin/" + branchName;

            if (BranchExists(qualifiedBranchName))
            {
                throw new NuKeeperException($"Git Cannot checkout new branch: a branch named '{qualifiedBranchName}' already exists");
            }

            _logger.Detailed($"Git checkout new branch '{branchName}'");
            using (var repo = MakeRepo())
            {
                var branch = repo.CreateBranch(branchName);
                GitCommands.Checkout(repo, branch);
            }
        }
        public Task CheckoutNewBranch(string branchName)
        {
            return(Task.Run(() =>
            {
                var qualifiedBranchName = "origin/" + branchName;
                if (BranchExists(qualifiedBranchName))
                {
                    _logger.Normal($"Git Cannot checkout new branch: a branch named '{qualifiedBranchName}' already exists");
                    return;
                }

                _logger.Detailed($"Git checkout new branch '{branchName}'");
                using (var repo = MakeRepo())
                {
                    var branch = repo.CreateBranch(branchName);
                    GitCommands.Checkout(repo, branch);
                }
            }));
        }
Beispiel #6
0
 public Task Checkout(string branchName)
 {
     return(Task.Run(() =>
     {
         _logger.Detailed($"Git checkout '{branchName}'");
         using (var repo = MakeRepo())
         {
             if (BranchExists(branchName))
             {
                 _logger.Normal($"Git checkout local branch '{branchName}'");
                 GitCommands.Checkout(repo, repo.Branches[branchName]);
             }
             else
             {
                 throw new NuKeeperException(
                     $"Git Cannot checkout branch: the branch named '{branchName}' doesn't exist");
             }
         }
     }));
 }
Beispiel #7
0
 public void Fetch(IEnumerable <Remote> remotes, CredentialsHandler credentials, IEventStream?eventStream = null, bool prune = false)
 {
     foreach (var remote in remotes)
     {
         Git.Fetch(
             (Repository)repository,
             remote.Name,
             remote.FetchRefSpecs.Select(x => x.Specification), new FetchOptions
         {
             Prune = prune,
             CredentialsProvider = credentials,
             OnProgress          = serverProgressOutput =>
             {
                 eventStream?.Push(new Status(serverProgressOutput));
                 return(true);
             },
             OnTransferProgress = progress =>
             {
                 eventStream?.Push(new Status($"Received {progress.ReceivedObjects} of {progress.TotalObjects}", progress.ReceivedObjects / (float)progress.TotalObjects));
                 return(true);
             }
         }, string.Empty);
     }
 }
Beispiel #8
0
 public void Remove(string filepath) =>
 Git.Remove(repository, filepath);
Beispiel #9
0
 public void Stage(string filepath) =>
 Git.Stage(repository, filepath);
Beispiel #10
0
 public void Checkout(Branch branch) =>
 Git.Checkout(repository, branch);
Beispiel #11
0
        public override int Execute(UpdateSettings settings, ILookup <string, string> remaining)
        {
            // Get the user.
            var client = new GitHubClient(new ProductHeaderValue("Cake-Addin-Updater"))
            {
                Credentials = new Octokit.Credentials(settings.Token)
            };

            // Validate the provided version.
            if (!System.Version.TryParse(settings.Version, out var _))
            {
                _log.Error("The provided version is not valid.");
                return(1);
            }

            // Get the root.
            var root = settings.WorkingDirectory ?? new DirectoryPath(".");

            root = root.MakeAbsolute(_environment);

            // Get the user.
            var user      = client.User.Get(settings.User).Result;
            var userEmail = GetUserEmail(client);

            // Get the repository parts.
            var info = GetRepositoryInfo(settings);

            // Does the directory contains anything?
            var path = CreateRepositoryDirectory(root, info);

            if (_filesystem.Directory.GetFiles(path, "*.*", SearchScope.Current).Any() ||
                _filesystem.Directory.GetDirectories(path, "*.*", SearchScope.Current).Any())
            {
                _log.Error($"Repository '{path}' already exist on disk.");
                _log.Write("Remove it and try again.");
                return(1);
            }

            // Fork the repository.
            var repository = ForkRepository(client, info);

            if (string.IsNullOrWhiteSpace(repository?.Name))
            {
                _log.Error("Could not fork repository.");
                return(1);
            }

            // Get the default branch.
            var defaultBranch = repository.DefaultBranch;

            if (string.IsNullOrWhiteSpace(defaultBranch))
            {
                _log.Error("Could not get default branch for repository.");
                return(1);
            }

            // Clone the repository at the specified path.
            _log.Write("Cloning repository...");
            GitRepository.Clone($"https://github.com/{settings.User}/{repository.Name}", path.FullPath, new CloneOptions
            {
                Checkout = true
            });

            using (var gitRepository = new GitRepository(path.FullPath))
            {
                // Create a new branch in the repository.
                _log.Write("Creating branch...");
                gitRepository.CreateBranch($"feature/cake-{settings.Version}");
                _log.Write("Checking out branch...");
                GitCommands.Checkout(gitRepository, $"feature/cake-{settings.Version}");

                // Update all package references in project.
                var processed = _processor.Process(root, path, settings.Version);
                if (processed == 0)
                {
                    _log.Error("Nothing was updated. Probably a newer repository.");
                    return(1);
                }

                // Commit?
                if (settings.Commit)
                {
                    _log.Write("Staging changes...");
                    GitCommands.Stage(gitRepository, "*");

                    var status = gitRepository.RetrieveStatus();
                    if (status.Any())
                    {
                        _log.Write("Committing changes...");
                        var author = new GitSignature(user.Name, userEmail, DateTime.Now);
                        gitRepository.Commit($"Updated to Cake {settings.Version}.", author, author);

                        // Push?
                        if (settings.Push)
                        {
                            // Build everything first.
                            if (!BuildProject(path))
                            {
                                return(1);
                            }

                            // Push the commit.
                            if (!Push(settings, path))
                            {
                                return(1);
                            }

                            // Create a pull request?
                            if (settings.OpenPullRequest)
                            {
                                CreatePullRequest(client, settings, info);
                            }
                        }
                    }
                    else
                    {
                        _log.Error("No changes in repository. Already updated?");
                    }
                }
            }

            return(0);
        }