/// <summary>
        /// Method to translate from <see cref="CheckoutFileConflictStrategy"/> to <see cref="CheckoutStrategy"/> flags.
        /// </summary>
        internal static CheckoutStrategy CheckoutStrategyFromFileConflictStrategy(CheckoutFileConflictStrategy fileConflictStrategy)
        {
            CheckoutStrategy flags = default(CheckoutStrategy);

            switch (fileConflictStrategy)
            {
            case CheckoutFileConflictStrategy.Ours:
                flags = CheckoutStrategy.GIT_CHECKOUT_USE_OURS;
                break;

            case CheckoutFileConflictStrategy.Theirs:
                flags = CheckoutStrategy.GIT_CHECKOUT_USE_THEIRS;
                break;

            case CheckoutFileConflictStrategy.Merge:
                flags = CheckoutStrategy.GIT_CHECKOUT_CONFLICT_STYLE_MERGE;
                break;

            case CheckoutFileConflictStrategy.Diff3:
                flags = CheckoutStrategy.GIT_CHECKOUT_CONFLICT_STYLE_DIFF3;
                break;
            }

            return(flags);
        }
        /// <summary>
        /// Method to translate from <see cref="CheckoutFileConflictStrategy"/> to <see cref="CheckoutStrategy"/> flags.
        /// </summary>
        internal static CheckoutStrategy CheckoutStrategyFromFileConflictStrategy(CheckoutFileConflictStrategy fileConflictStrategy)
        {
            CheckoutStrategy flags = default(CheckoutStrategy);

            switch (fileConflictStrategy)
            {
                case CheckoutFileConflictStrategy.Ours:
                    flags = CheckoutStrategy.GIT_CHECKOUT_USE_OURS;
                    break;

                case CheckoutFileConflictStrategy.Theirs:
                    flags = CheckoutStrategy.GIT_CHECKOUT_USE_THEIRS;
                    break;

                case CheckoutFileConflictStrategy.Merge:
                    flags = CheckoutStrategy.GIT_CHECKOUT_CONFLICT_STYLE_MERGE;
                    break;

                case CheckoutFileConflictStrategy.Diff3:
                    flags = CheckoutStrategy.GIT_CHECKOUT_CONFLICT_STYLE_DIFF3;
                    break;
            }

            return flags;
        }
Example #3
0
        public void RevertWithFileConflictStrategyOption(CheckoutFileConflictStrategy conflictStrategy)
        {
            // The branch name to perform the revert on,
            // and the file which we expect conflicts as result of the revert.
            const string revertBranchName   = "refs/heads/revert";
            const string conflictedFilePath = "a.txt";

            string path = SandboxRevertTestRepo();

            using (var repo = new Repository(path))
            {
                // Checkout the revert branch.
                Branch branch = repo.Checkout(revertBranchName);
                Assert.NotNull(branch);

                // Specify FileConflictStrategy.
                RevertOptions options = new RevertOptions()
                {
                    FileConflictStrategy = conflictStrategy,
                };

                RevertResult result = repo.Revert(repo.Head.Tip.Parents.First(), Constants.Signature, options);
                Assert.Equal(RevertStatus.Conflicts, result.Status);

                // Verify there is a conflict.
                Assert.False(repo.Index.IsFullyMerged);

                Conflict conflict = repo.Index.Conflicts[conflictedFilePath];
                Assert.NotNull(conflict);

                Assert.NotNull(conflict);
                Assert.NotNull(conflict.Theirs);
                Assert.NotNull(conflict.Ours);

                // Get the blob containing the expected content.
                Blob expectedBlob = null;
                switch (conflictStrategy)
                {
                case CheckoutFileConflictStrategy.Theirs:
                    expectedBlob = repo.Lookup <Blob>(conflict.Theirs.Id);
                    break;

                case CheckoutFileConflictStrategy.Ours:
                    expectedBlob = repo.Lookup <Blob>(conflict.Ours.Id);
                    break;

                default:
                    throw new Exception("Unexpected FileConflictStrategy");
                }

                Assert.NotNull(expectedBlob);

                // Check the content of the file on disk matches what is expected.
                string expectedContent = expectedBlob.GetContentText(new FilteringOptions(conflictedFilePath));
                Assert.Equal(expectedContent, File.ReadAllText(Path.Combine(repo.Info.WorkingDirectory, conflictedFilePath)));
            }
        }
        public void CanSpecifyConflictFileStrategy(CheckoutFileConflictStrategy conflictStrategy)
        {
            const string conflictFile       = "a.txt";
            const string conflictBranchName = "conflicts";

            string path = SandboxMergeTestRepo();

            using (var repo = new Repository(path))
            {
                Branch branch = repo.Branches[conflictBranchName];
                Assert.NotNull(branch);

                CherryPickOptions cherryPickOptions = new CherryPickOptions()
                {
                    FileConflictStrategy = conflictStrategy,
                };

                CherryPickResult result = repo.CherryPick(branch.Tip, Constants.Signature, cherryPickOptions);
                Assert.Equal(CherryPickStatus.Conflicts, result.Status);

                // Get the information on the conflict.
                Conflict conflict = repo.Index.Conflicts[conflictFile];

                Assert.NotNull(conflict);
                Assert.NotNull(conflict.Theirs);
                Assert.NotNull(conflict.Ours);

                // Get the blob containing the expected content.
                Blob expectedBlob = null;
                switch (conflictStrategy)
                {
                case CheckoutFileConflictStrategy.Theirs:
                    expectedBlob = repo.Lookup <Blob>(conflict.Theirs.Id);
                    break;

                case CheckoutFileConflictStrategy.Ours:
                    expectedBlob = repo.Lookup <Blob>(conflict.Ours.Id);
                    break;

                default:
                    throw new Exception("Unexpected FileConflictStrategy");
                }

                Assert.NotNull(expectedBlob);

                // Check the content of the file on disk matches what is expected.
                string expectedContent = expectedBlob.GetContentText(new FilteringOptions(conflictFile));
                Assert.Equal(expectedContent, File.ReadAllText(Path.Combine(repo.Info.WorkingDirectory, conflictFile)));
            }
        }
        public void CanSpecifyConflictFileStrategy(CheckoutFileConflictStrategy conflictStrategy)
        {
            const string conflictFile = "a.txt";
            const string conflictBranchName = "conflicts";

            string path = SandboxMergeTestRepo();
            using (var repo = new Repository(path))
            {
                Branch branch = repo.Branches[conflictBranchName];
                Assert.NotNull(branch);

                CherryPickOptions cherryPickOptions = new CherryPickOptions()
                {
                    FileConflictStrategy = conflictStrategy,
                };

                CherryPickResult result = repo.CherryPick(branch.Tip, Constants.Signature, cherryPickOptions);
                Assert.Equal(CherryPickStatus.Conflicts, result.Status);

                // Get the information on the conflict.
                Conflict conflict = repo.Index.Conflicts[conflictFile];

                Assert.NotNull(conflict);
                Assert.NotNull(conflict.Theirs);
                Assert.NotNull(conflict.Ours);

                // Get the blob containing the expected content.
                Blob expectedBlob = null;
                switch (conflictStrategy)
                {
                    case CheckoutFileConflictStrategy.Theirs:
                        expectedBlob = repo.Lookup<Blob>(conflict.Theirs.Id);
                        break;
                    case CheckoutFileConflictStrategy.Ours:
                        expectedBlob = repo.Lookup<Blob>(conflict.Ours.Id);
                        break;
                    default:
                        throw new Exception("Unexpected FileConflictStrategy");
                }

                Assert.NotNull(expectedBlob);

                // Check the content of the file on disk matches what is expected.
                string expectedContent = expectedBlob.GetContentText(new FilteringOptions(conflictFile));
                Assert.Equal(expectedContent, File.ReadAllText(Path.Combine(repo.Info.WorkingDirectory, conflictFile)));
            }
        }
Example #6
0
        public void RevertWithFileConflictStrategyOption(CheckoutFileConflictStrategy conflictStrategy)
        {
            // The branch name to perform the revert on,
            // and the file which we expect conflicts as result of the revert.
            const string revertBranchName = "refs/heads/revert";
            const string conflictedFilePath = "a.txt";

            string path = SandboxRevertTestRepo();
            using (var repo = new Repository(path))
            {
                // Checkout the revert branch.
                Branch branch = Commands.Checkout(repo, revertBranchName);
                Assert.NotNull(branch);

                // Specify FileConflictStrategy.
                RevertOptions options = new RevertOptions()
                {
                    FileConflictStrategy = conflictStrategy,
                };

                RevertResult result =  repo.Revert(repo.Head.Tip.Parents.First(), Constants.Signature, options);
                Assert.Equal(RevertStatus.Conflicts, result.Status);

                // Verify there is a conflict.
                Assert.False(repo.Index.IsFullyMerged);

                Conflict conflict = repo.Index.Conflicts[conflictedFilePath];
                Assert.NotNull(conflict);

                Assert.NotNull(conflict);
                Assert.NotNull(conflict.Theirs);
                Assert.NotNull(conflict.Ours);

                // Get the blob containing the expected content.
                Blob expectedBlob = null;
                switch (conflictStrategy)
                {
                    case CheckoutFileConflictStrategy.Theirs:
                        expectedBlob = repo.Lookup<Blob>(conflict.Theirs.Id);
                        break;
                    case CheckoutFileConflictStrategy.Ours:
                        expectedBlob = repo.Lookup<Blob>(conflict.Ours.Id);
                        break;
                    default:
                        throw new Exception("Unexpected FileConflictStrategy");
                }

                Assert.NotNull(expectedBlob);

                // Check the content of the file on disk matches what is expected.
                string expectedContent = expectedBlob.GetContentText(new FilteringOptions(conflictedFilePath));
                Assert.Equal(expectedContent, File.ReadAllText(Path.Combine(repo.Info.WorkingDirectory, conflictedFilePath)));
            }
        }