/// <summary>
        /// Reset and clean current working directory. This will ensure that the current
        /// working directory matches the current Head commit.
        /// </summary>
        /// <param name="repo">Repository whose current working directory should be operated on.</param>
        private void ResetAndCleanWorkingDirectory(IRepository repo)
        {
            // Reset the index and the working tree.
            repo.Reset(ResetMode.Hard);

            // Clean the working directory.
            repo.RemoveUntrackedFiles();
        }
Example #2
0
 private static void AssertStage(bool? ignorecase, IRepository repo, string path)
 {
     try
     {
         repo.Index.Stage(path);
         Assert.Equal(FileStatus.Added, repo.Index.RetrieveStatus(path));
         repo.Reset();
         Assert.Equal(FileStatus.Untracked, repo.Index.RetrieveStatus(path));
     }
     catch (ArgumentException)
     {
         Assert.False(ignorecase ?? true);
     }
 }
Example #3
0
        bool UpdateGit(IRepository repo)
        {
            var recompileNeeded = true;
            using (var _ = new ChangingOutput("Updating source code . . ."))
            {
                _.FinishLine();

                using (var t = new ChangingOutput("Fetching updates from GitHub . . ."))
                {
                    repo.Fetch("origin", new FetchOptions()
                    {
                        OnTransferProgress = (x) =>
                        {
                            t.PrintProgress((double) x.ReceivedObjects/x.TotalObjects);
                            return true;
                        }
                    });

                    t.PrintResult(true);
                }

                var currentCommit = repo.Head.Tip;
                MergeResult result;
                try
                {
                    using (var t = new ChangingOutput("Merging in updates . . ."))
                    {
                        result = repo.Merge(repo.Head.TrackedBranch, new Signature(Environment.UserName, "[email protected]", DateTime.Now),
                            new MergeOptions
                            {
                                CommitOnSuccess = true,
                                FileConflictStrategy = CheckoutFileConflictStrategy.Ours,
                                MergeFileFavor = MergeFileFavor.Normal,
                                OnCheckoutProgress = (n, processed, total) =>
                                {
                                    t.PrintProgress((double) processed/total);
                                },
                            });

                        t.PrintResult(result.Status != MergeStatus.Conflicts);

                    }

                    if (result.Status == MergeStatus.UpToDate)
                    {
                        Console.WriteLine("Source was already up to date");
                        recompileNeeded = RestoreDeleteFiles(repo);
                        _.PrintResult(true);
                    }
                    else if (result.Status == MergeStatus.Conflicts)
                    {
                        throw new MergeConflictException();
                    }
                    else
                    {
                        Console.WriteLine("Updated to {0} : {1}", result.Commit.Sha.Substring(0, 10), result.Commit.MessageShort);
                        _.PrintResult(true);
                    }
                }
                catch (MergeConflictException)
                {
                    Console.WriteLine("Merge resulted in conflicts. This usually indictates a user-edited source");
                    Console.WriteLine("Your Aura will NOT be updated until you undo your changes to the files.");
                    Console.WriteLine("This is a bad thing, so fix it ASAP.");
                    Console.WriteLine("NOTE: If you're trying to make configuration changes, use the \"user\" folders instead.");
                    Console.WriteLine("Rolling back merge...");
                    repo.Reset(currentCommit);
                    recompileNeeded = false;
                    _.PrintResult(false);
                }

                return recompileNeeded;
            }
        }