Esempio n. 1
0
    public IEnumerator RepositoryHandlesLockedFileWhenWithIgnoreStatus()
    {
        File.AppendAllText(injectionHelper.GetInstance <GitInitializer>().GitIgnoreFilePath, "testFile.txt");
        string lockedFilePathName = "testFile.txt";
        string lockedFilePath     = UniGitPathHelper.Combine(gitManager.GetCurrentRepoPath(), lockedFilePathName);

        using (var lockFileStream = File.CreateText(lockedFilePath))
        {
            lockFileStream.WriteLine("This is a locked test file");
        }
        injectionHelper.Bind <GitProjectOverlay>().WithArguments(new InjectionArgument("cullNonAssetPaths", false));
        var projectOverlays = injectionHelper.GetInstance <GitProjectOverlay>();
        var prefs           = injectionHelper.GetInstance <IGitPrefs>();

        prefs.SetBool(GitProjectOverlay.ForceUpdateKey, true);

        Assert.IsTrue(File.Exists(lockedFilePath));
        GitCommands.Stage(gitManager.Repository, lockedFilePathName);
        FileStream lockedFileStream = new FileStream(lockedFilePath, FileMode.Open, FileAccess.Read, FileShare.None);

        try
        {
            gitManager.MarkDirty();
            yield return(null);

            Assert.AreEqual(FileStatus.Ignored, projectOverlays.StatusTree.GetStatus(lockedFilePathName).State);
        }
        finally
        {
            lockedFileStream.Dispose();
        }
    }
Esempio n. 2
0
        public override void Execute(IUniBuilderConfiguration buildParameters)
        {
            var outputFilename  = buildParameters.BuildParameters.OutputFile;
            var outputExtension = string.IsNullOrEmpty(artifactExtension)?
                                  Path.GetExtension(outputFilename) : artifactExtension;

            var fileName = Path.GetFileNameWithoutExtension(outputFilename);

            var artifactName = useProductName ?
                               PlayerSettings.productName :
                               fileName;

            if (useNameTemplate)
            {
                artifactName = string.Format(artifactNameTemplate, artifactName);
            }

            if (includeGitBranch)
            {
                var branch = GitCommands.GetGitBranch();
                if (string.IsNullOrEmpty(branch) == false)
                {
                    artifactName = string.Format(nameFormatTemplate, artifactName, branch);
                }
            }

            if (includeBundleVersion)
            {
                artifactName = string.Format(nameFormatTemplate, artifactName, PlayerSettings.bundleVersion);
            }

            artifactName += $"{outputExtension}";
            buildParameters.BuildParameters.OutputFile = artifactName;
        }
Esempio n. 3
0
        public void AllLinesHistoryTest()
        {
            var lineHistory          = Helpers.LoadResource(Paths.GitLineLogOutput, typeof(GitCommandsTest).Assembly);
            var executorMock         = new Mock <ICommandLineExecutor>();
            var fileName             = "dir/bla.js";
            var gitCommandFirstLine  = $"log --pretty='commit-%h;auth-%an' -L 1,1:\"{fileName}\" --no-patch";
            var gitCommandSecondLine = $"log --pretty='commit-%h;auth-%an' -L 2,2:\"{fileName}\" --no-patch";

            executorMock
            .Setup(mock => mock.Execute("git", It.Is <string>(command => command == gitCommandFirstLine), "dir"))
            .Returns(lineHistory.Split('\n'));
            executorMock
            .Setup(mock => mock.Execute("git", It.Is <string>(command => command == gitCommandSecondLine), "dir"))
            .Returns(lineHistory.Split('\n'));
            var gitCommands = new GitCommands(executorMock.Object);

            var result = gitCommands.NumberOfChangesForEachLine(fileName, 2)
                         .ToArray();

            executorMock.Verify(mock => mock.Execute("git", It.Is <string>(s => s == gitCommandFirstLine), "dir"),
                                Times.Once);
            executorMock.Verify(mock => mock.Execute("git", It.Is <string>(s => s == gitCommandSecondLine), "dir"),
                                Times.Once);
            result.Should()
            .BeEquivalentTo(new[] { 9, 9 });
        }
Esempio n. 4
0
        public void CheckoutNthCommitOnBranch()
        {
            var          output               = Helpers.LoadResource(Paths.GitSingleCommitOutput, typeof(GitCommandsTest).Assembly);
            var          executorMock         = new Mock <ICommandLineExecutor>();
            const string repoPath             = "dir";
            const string commitCountCommand   = "rev-list --count HEAD";
            const int    nthCommit            = 5;
            const int    allCommits           = 123;
            var          nthCommitHashCommand = $"log -1 HEAD~{allCommits - nthCommit + 1}";

            executorMock
            .Setup(mock => mock.Execute("git", It.Is <string>(command => command == commitCountCommand), repoPath))
            .Returns(new[] { allCommits.ToString() });
            executorMock
            .Setup(mock => mock.Execute("git", It.Is <string>(command => command == nthCommitHashCommand), repoPath))
            .Returns(output.Split('\n'));
            var gitCommands = new GitCommands(executorMock.Object);

            gitCommands.CheckoutNthCommitOnBranch(repoPath, nthCommit);

            executorMock.Verify(mock => mock.Execute("git", commitCountCommand, repoPath), Times.Exactly(2));
            executorMock.Verify(mock => mock.Execute("git", nthCommitHashCommand, repoPath), Times.Once);
            executorMock.Verify(mock => mock.Execute("git",
                                                     "checkout abb3cc3d7e405c39eae91b22c41d1281b9075cd4",
                                                     repoPath),
                                Times.Once);
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            foreach (string reference in GitCommands.RunGit("branch").Split('\n'))
            {
                if (string.IsNullOrEmpty(reference))
                {
                    continue;
                }

                string branchName = reference.Trim('*', ' ', '\n', '\r');

                DateTime date = new DateTime();
                foreach (string dateString in GitCommands.RunGit(string.Concat("log --pretty=%ci ", branchName, "^1..", branchName)).Split('\n'))
                {
                    DateTime singleDate;
                    if (DateTime.TryParse(dateString, out singleDate))
                    {
                        if (singleDate > date)
                        {
                            date = singleDate;
                        }
                    }
                }
                Branches.Add(new Branch(branchName, date, date < (DateTime.Now.AddDays(-Days))));
            }

            BranchesGrid.DataSource = Branches;
        }
Esempio n. 6
0
    public void RepositoryHandlesLockedFileWhenWithIgnoreStatus()
    {
        File.AppendAllText(gitManager.GitIgnoreFilePath, "testFile.txt");
        string lockedFilePathName = "testFile.txt";
        string lockedFilePath     = UniGitPath.Combine(gitManager.RepoPath, lockedFilePathName);

        using (var lockFileStream = File.CreateText(lockedFilePath))
        {
            lockFileStream.WriteLine("This is a locked test file");
        }
        injectionHelper.Bind <GitProjectOverlay>();
        var projectOverlays = injectionHelper.GetInstance <GitProjectOverlay>();

        Assert.IsTrue(File.Exists(lockedFilePath));
        GitCommands.Stage(gitManager.Repository, lockedFilePathName);
        FileStream lockedFileStream = new FileStream(lockedFilePath, FileMode.Open, FileAccess.Read, FileShare.None);

        try
        {
            gitManager.MarkDirty();
            injectionHelper.GetInstance <GitCallbacks>().IssueEditorUpdate();
            Assert.AreEqual(FileStatus.Ignored, projectOverlays.StatusTree.GetStatus(lockedFilePathName).State);
        }
        finally
        {
            lockedFileStream.Dispose();
        }
    }
Esempio n. 7
0
        public void GetOrderOfCurrentHeadRelativeToFirstCommitOfBranchTest()
        {
            var       output       = Helpers.LoadResource(Paths.GitSingleCommitOutput, typeof(GitCommandsTest).Assembly);
            var       executorMock = new Mock <ICommandLineExecutor>();
            var       gitCommands  = new GitCommands(executorMock.Object);
            const int nthCommit    = 1;
            const int allCommits   = 123;

            executorMock.Setup(mock => mock.Execute("git", "rev-list --count HEAD", "dir"))
            .Returns(new[] { "123" });
            var nthCommitHashCommand = $"log -1 HEAD~{allCommits - nthCommit + 1}";

            executorMock.Setup(mock => mock.Execute("git", nthCommitHashCommand, "dir"))
            .Returns(output.Split('\n'));
            executorMock.Setup(mock => mock.Execute("git",
                                                    "rev-list abb3cc3d7e405c39eae91b22c41d1281b9075cd4..HEAD --count",
                                                    "dir"))
            .Returns(new[] { "42" });

            var result = gitCommands.GetOrderOfCurrentHeadRelativeToFirstCommitOfBranch("dir");

            executorMock.Verify(mock => mock.Execute("git", "rev-list --count HEAD", "dir"), Times.Once);
            executorMock.Verify(mock => mock.Execute("git", nthCommitHashCommand, "dir"), Times.Once);
            executorMock.Verify(mock => mock.Execute("git",
                                                     "rev-list abb3cc3d7e405c39eae91b22c41d1281b9075cd4..HEAD --count",
                                                     "dir"),
                                Times.Once);
            result.Should()
            .Be(42);
        }
Esempio n. 8
0
        public async Task RunAsync(CommandLineOptions options)
        {
            var git   = new GitCommands(options.GetGitOptions());
            var files = await git.GetFilesAsync().ConfigureAwait(false);

            var gitFileAnalyzer = new GitFileAnalyzer(options.GetFileAnalyzerOptions(), git);

            ICollection <AuthorStatistics> authorStatistics;

            using (var progressBar = CreateProgressBar(files.Count))
            {
                // ReSharper disable once AccessToDisposedClosure => false positive
                authorStatistics = await gitFileAnalyzer.BlameFilesAsync(files, progress => AdvanceProgressBar(progressBar, progress)).ConfigureAwait(false);

                var commitStatistics = await git.ShortlogAsync().ConfigureAwait(false);

                foreach (var commitStatistic in commitStatistics)
                {
                    var authorStatistic = authorStatistics.SingleOrDefault(x => x.Author.Equals(commitStatistic.Key));
                    if (authorStatistic == null)
                    {
                        authorStatistic = new AuthorStatistics(commitStatistic.Key);
                        authorStatistics.Add(authorStatistic);
                    }

                    authorStatistic.CommitCount = commitStatistic.Value;
                }

                var merger = new AuthorsMerger(options.GetAuthorMergeOptions());
                authorStatistics = merger.Merge(authorStatistics);
            }

            WriteOutput(options, authorStatistics);
            DisplaySummary(authorStatistics);
        }
Esempio n. 9
0
        private async void CreateProjectRepository()
        {
            Auth();

            var exists = await IsRemoteRepoExists();

            if (!exists)
            {
                var newRepository = await CreateRepo();

                if (newRepository != null)
                {
                    WriteLog("New Repo Successfully created");

                    _slugNameField.value = newRepository.Slug;
                    _gitHelperData.lastRepositoryData.repositorySlugName = newRepository.Slug;
                    SaveData();

                    string link = newRepository.Links.Clone.FirstOrDefault(cloneLink => cloneLink.Href.Contains("https"))?.Href;
                    _gitHelperData.lastRepositoryData.repositoryUrl = link;
                    _repoUrlField.value = link;

                    GitCommands.Instance().AddRemoteBranch(link);
                }
                else
                {
                    WriteLog("Something went wrong. New repo not created");
                }
            }
            else
            {
                WriteLog("Repo already exists");
            }
        }
Esempio n. 10
0
 public Commit()
 {
     if (lastFile == null)
     {
         lastFile = string.Empty;
     }
     showCurrentBranch = GitCommands.GetShowCurrentBranchSetting();
 }
Esempio n. 11
0
 public WebhookRegistry.HTTPResponseData gitHook(List <string> arguments, string body, string method, NameValueCollection headers)
 {
     GitCommands.Process(body, headers.Get("X-Github-Event"));
     WebhookRegistry.HTTPResponseData reply = new WebhookRegistry.HTTPResponseData();
     reply.ReplyString = "Done";
     reply.Status      = 200;
     // removed a line here that triggered a git refresh
     return(reply);
 }
Esempio n. 12
0
        public void NumberOfChangesForLineThrowsArgumentExceptionIfFilePathIsInvalid()
        {
            var gitCommands = new GitCommands(Mock.Of <ICommandLineExecutor>());

            Action act = () => gitCommands.NumberOfChangesForLine(string.Empty, 2);

            act.Should()
            .Throw <ArgumentException>();
        }
Esempio n. 13
0
        public void Test_ALL()
        {
            DirectoryInfo rootDire = new DirectoryInfo(rootDirePath);

            // 未完全实现
            if (Directory.Exists(rootDirePath))
            {
                DirectoryInfo[] haveDires = rootDire.GetDirectories();
                for (int i = 0; i < haveDires.Length; i++)
                {
                    haveDires[i].Delete(true);
                }
                FileInfo[] havefiles = rootDire.GetFiles();
                for (int i = 0; i < havefiles.Length; i++)
                {
                    havefiles[i].Delete();
                }
            }
            else
            {
                Directory.CreateDirectory(rootDirePath);
            }

            IGit git = new GitCommands(new Repository()
            {
                RootPath = new DirectoryInfo(rootDirePath),
            });

            git.Init().OnCommand();
            Assert.AreEqual(true, Directory.Exists(rootDirePath));
            Assert.AreEqual(true, Directory.Exists(Path.Combine(rootDirePath, ".git")));

            string json = JsonConvert.SerializeObject(new { });

            File.WriteAllText(Path.Combine(rootDirePath, "1.json"), json);

            git.Add().OnCommand("1.json");

            IList <string> msgs;

            msgs = git.Status().OnCommand();
            msgs.Test(new string[] {
                "On branch master",
                "No commits yet",
                "Changes to be committed:",
                "  (use \"git rm --cached <file>...\" to unstage)",
                "        new file:   1.json",
            });

            git.Commit().OnCommand("save data");
            msgs = git.Status().OnCommand();
            msgs.Test(new string[] {
                "On branch master",
                "nothing to commit, working tree clean",
            });
        }
Esempio n. 14
0
        private void InitGit()
        {
            var gitCommands = new GitCommands();

            var gitRepository = new GitRepository(_repositoryURL, _localDirectory, _repositoryName);

            var repositoryManager = new RepositoryManager(gitCommands, gitRepository);

            _gitHubStorageCoordinator = new GitHubStorageCoordinator(gitCommands, gitRepository, repositoryManager);
        }
Esempio n. 15
0
        public override bool IsEnabled(_DTE application)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            bool enabled = base.IsEnabled(application);

            string fileName = GetSelectedFile(application);

            if (fileName != lastFile || DateTime.Now - lastBranchCheck > TimeSpan.FromSeconds(2))
            {
                string newCaption = "&Commit";
                if (enabled)
                {
                    bool showCurrentBranch = GitCommands.GetShowCurrentBranchSetting();
                    if (showCurrentBranch && !string.IsNullOrEmpty(fileName))
                    {
                        string head = GitCommands.GetCurrentBranch(fileName);
                        if (!string.IsNullOrEmpty(head))
                        {
                            string headShort;
                            if (head.Length > 27)
                            {
                                headShort = "..." + head.Substring(head.Length - 23);
                            }
                            else
                            {
                                headShort = head;
                            }

                            newCaption = "&Commit (" + headShort + ")";
                        }
                    }

                    lastBranchCheck = DateTime.Now;
                    lastFile        = fileName;
                }

                // This guard required not only for performance, but also for prevent StackOverflowException.
                // IDE.QueryStatus -> Commit.IsEnabled -> Plugin.UpdateCaption -> IDE.QueryStatus ...
                if (_lastUpdatedCaption != newCaption)
                {
                    _lastUpdatedCaption = newCaption;

                    // try apply new caption (operation can fail)
                    if (!PluginHelpers.ChangeCommandCaption(application, PluginHelpers.GitCommandBarName, "Commit changes", newCaption))
                    {
                        _lastUpdatedCaption = null;
                    }
                }
            }

            return(enabled);
        }
Esempio n. 16
0
 public override void OnCommand(EnvDTE80.DTE2 application, OutputWindowPane pane)
 {
     ThreadPool.QueueUserWorkItem(
         o =>
     {
         string file = GitCommands.RunGitExWait("searchfile", application.Solution.FullName);
         if (file == null || string.IsNullOrEmpty(file.Trim()))
         {
             return;
         }
         application.ExecuteCommand("File.OpenFile", file);
     });
 }
 private void Delete_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Are you sure to delete the selected branches?" + Environment.NewLine + "Only branches that are not fully merged will be deleted.", "Delete", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         foreach (Branch branch in Branches)
         {
             if (branch.Delete)
             {
                 branch.Result = GitCommands.RunGit(string.Concat("branch -d " + branch.Name)).Trim();
                 BranchesGrid.Refresh();
             }
         }
     }
 }
Esempio n. 18
0
        private static void FirstInit()
        {
            PlayerSettings.assemblyVersionValidation = false;

            string gitFolderPath = Application.dataPath.Replace("/Assets", "");

            gitFolderPath = $"{gitFolderPath}/.git";

            if (!Directory.Exists(gitFolderPath))
            {
                GitCommands.Instance().SetGitIgnore();
                GitCommands.Instance().InitGit();
            }
        }
Esempio n. 19
0
 static void OnToolbarGUI()
 {
     GUILayout.FlexibleSpace();
     GUI.color = Color.yellow;
     if (GUILayout.Button(new GUIContent("Commit", "Start Scene 1")))
     {
         GitCommands.Instance().CommitChanges();
     }
     GUI.color = Color.green;
     if (GUILayout.Button(new GUIContent("Push", "Start Scene 2")))
     {
         GitCommands.Instance().Push();
     }
 }
Esempio n. 20
0
        public void handle(string text, UUID User, string agentName, Destinations src, UUID originator)
        {
            OCBotMemory ocb = OCBotMemory.Memory;

            //BotSession.Instance.MHE(MessageHandler.Destinations.DEST_LOCAL, UUID.Zero, $"Got data \n\n[HandleMiscInputs.cs]:handle(\"{text}\", {User.ToString()}, \"{agentName}\", {src.ToString()}, {originator.ToString()})");
            if (ocb.ActiveReportSessions.ContainsKey(User) && ocb.ActiveReportSessions.Count > 0)
            {
                // Send report response to GitCommands
                GitCommands gc = new GitCommands();
                gc.BugResponse(originator, User, ocb.ActiveReportSessions[User].ReportStage, text, src, agentName);
                return;
            }

            if (ocb.ActiveFeatureSessions.ContainsKey(User) && ocb.ActiveFeatureSessions.Count > 0)
            {
                GitCommands gc = new GitCommands();
                gc.FeatureResponse(originator, User, ocb.ActiveFeatureSessions[User].ReportStage, text, src, agentName);
                return;
            }

            if (ocb.ActiveCommentSessions.ContainsKey(User) && ocb.ActiveCommentSessions.Count > 0)
            {
                GitCommands gc = new GitCommands();
                gc.comment(originator, User, ocb.ActiveCommentSessions[User].ReportStage, text, src, agentName);
                return;
            }

            if (ocb.NoticeSessions.ContainsKey(User) && ocb.NoticeSessions.Count > 0)
            {
                GroupSystem gs = new GroupSystem();
                gs.update_notice_sess(originator, User, text, src, agentName);
                return;
            }

            if (ocb.MailingLists.Count > 0)
            {
                // Scan all mailing lists for a session and agentKey that match.
                foreach (string sML in ocb.MailingLists.Keys)
                {
                    OCBotMemory.MailList ML = ocb.MailingLists[sML];
                    if (ML.PrepFrom == User && ML.PrepState == 1)
                    {
                        MailingLists.MailingLists cML = new MailingLists.MailingLists();
                        cML.HandleMailListData(User, originator, src, sML, text);
                        return;
                    }
                }
            }
        }
Esempio n. 21
0
 public Commit()
     : base(true, true)
 {
     if (lastBranchCheck == null)
     {
         lastBranchCheck = DateTime.MinValue;
     }
     if (lastFile == null)
     {
         lastFile = string.Empty;
     }
     if (showCurrentBranch == null)
     {
         showCurrentBranch = GitCommands.GetShowCurrentBranchSetting();
     }
 }
Esempio n. 22
0
        private static void ParseUnifiedDiff(string path, GitDiffParser diffParser, GitCommit commit)
        {
            commit.Difflets = diffParser.Parse(commit.UnifiedDiff);

            foreach (var file in commit.Files)
            {
                if (file.Status != "A")
                {
                    file.BeforeText = GitCommands.ShowFileBeforeCommit(path, commit.Sha, file.File);
                }
                if (file.Status != "D")
                {
                    file.AfterText = GitCommands.ShowFileAfterCommit(path, commit.Sha, file.File);
                }
            }
        }
Esempio n. 23
0
        public void LatestCommitDateTest()
        {
            var          executorMock = new Mock <ICommandLineExecutor>();
            const string repoPath     = "dir";
            const string gitCommand   = "log -1 --format=%cd";

            executorMock.Setup(mock => mock.Execute("git", It.Is <string>(command => command == gitCommand), repoPath))
            .Returns(new[] { "Thu Mar 12 23:38:51 2020 +0100" });
            var gitCommands = new GitCommands(executorMock.Object);

            var result = gitCommands.DateOfLatestCommitOnBranch(repoPath);

            executorMock.Verify(mock => mock.Execute("git", gitCommand, repoPath), Times.Once);
            result.Date.Should()
            .BeSameDateAs(new DateTime(2020, 3, 12));
        }
Esempio n. 24
0
        public void HashForLatestCommit()
        {
            var          executorMock = new Mock <ICommandLineExecutor>();
            const string repoPath     = "dir";
            const string command      = "rev-parse HEAD";

            executorMock
            .Setup(mock => mock.Execute("git", It.Is <string>(c => c == command), repoPath))
            .Returns(new[] { "23d81a11e8deb30d2f004cfc5ed2d7430581e70a" });
            var gitCommands = new GitCommands(executorMock.Object);

            var result = gitCommands.GetHashForLatestCommit(repoPath);

            result.Should()
            .Be("23d81a11e8deb30d2f004cfc5ed2d7430581e70a");
        }
Esempio n. 25
0
        public void NumberOfCommitsOnCurrentBranchTest()
        {
            var          executorMock = new Mock <ICommandLineExecutor>();
            const string repoPath     = "dir";
            const string gitCommand   = "rev-list --count HEAD";

            executorMock.Setup(mock => mock.Execute("git", It.Is <string>(command => command == gitCommand), repoPath))
            .Returns(new[] { "123" });
            var gitCommands = new GitCommands(executorMock.Object);

            var result = gitCommands.NumberOfCommitsOnCurrentBranch(repoPath);

            executorMock.Verify(mock => mock.Execute("git", gitCommand, repoPath), Times.Once);
            result.Should()
            .Be(123);
        }
Esempio n. 26
0
        public override bool IsEnabled(EnvDTE80.DTE2 application)
        {
            bool enabled = base.IsEnabled(application);

            string fileName = GetSelectedFile(application);

            if (showCurrentBranch && (fileName != lastFile || DateTime.Now - lastBranchCheck > new TimeSpan(0, 0, 0, 1, 0)))
            {
                string newCaption = "Commit";
                if (enabled)
                {
                    string head = GitCommands.GetCurrentBranch(fileName);
                    if (!string.IsNullOrEmpty(head))
                    {
                        string headShort;
                        if (head.Length > 27)
                        {
                            headShort = "..." + head.Substring(head.Length - 23);
                        }
                        else
                        {
                            headShort = head;
                        }

                        newCaption = "Commit (" + headShort + ")";
                    }
                }

                // This guard required not only for perfromance, but also for prevent StackOverflowException.
                // IDE.QueryStatus -> Commit.IsEnabled -> Plugin.UpdateCaption -> IDE.QueryStatus ...
                if (_lastUpdatedCaption != newCaption)
                {
                    _lastUpdatedCaption = newCaption;

                    // try apply new caption (operation can fail)
                    if (!Plugin.ChangeCommandCaption(application, "GitExtensions", "Commit changes", newCaption))
                    {
                        _lastUpdatedCaption = null;
                    }
                }

                lastBranchCheck = DateTime.Now;
                lastFile        = fileName;
            }

            return(enabled);
        }
Esempio n. 27
0
        public override void OnCommand(_DTE application, OutputWindowPane pane)
        {
            ThreadPool.QueueUserWorkItem(
                o =>
            {
                ThreadHelper.ThrowIfNotOnUIThread();

                string file = GitCommands.RunGitExWait("searchfile", application.Solution.FullName);

                if (string.IsNullOrEmpty(file?.Trim()))
                {
                    return;
                }

                application.ExecuteCommand("File.OpenFile", file);
            });
        }
Esempio n. 28
0
        public void FileAuthorsTest()
        {
            var fileAuthors  = Helpers.LoadResource(Paths.GitShortlogOutput, typeof(GitCommandsTest).Assembly);
            var executorMock = new Mock <ICommandLineExecutor>();
            var fileName     = "dir/bla.js";
            var gitCommand   = $"shortlog -n -s {fileName}";

            executorMock.Setup(mock => mock.Execute("git", It.Is <string>(command => command == gitCommand), "dir"))
            .Returns(fileAuthors.Split('\n'));
            var gitCommands = new GitCommands(executorMock.Object);

            var result = gitCommands.NumberOfDifferentAuthorsForFile(fileName);

            executorMock.Verify(mock => mock.Execute("git", gitCommand, "dir"), Times.Once);
            result.Should()
            .Be(10);
        }
Esempio n. 29
0
        public void FileHistoryTest()
        {
            var gitLogOutput =
                Helpers.LoadResource(Paths.GitPrettyLogOutput, typeof(GitCommandsTest).Assembly);
            var executorMock = new Mock <ICommandLineExecutor>();
            var fileName     = "dir/bla.js";
            var gitCommand   = $"log --pretty=oneline {fileName}";

            executorMock.Setup(mock => mock.Execute("git", It.Is <string>(command => command == gitCommand), "dir"))
            .Returns(gitLogOutput.Split('\n'));
            var gitCommands = new GitCommands(executorMock.Object);

            var result = gitCommands.NumberOfChangesForFile(fileName);

            executorMock.Verify(mock => mock.Execute("git", gitCommand, "dir"), Times.Once);
            result.Should()
            .Be(4);
        }
Esempio n. 30
0
        public void SingleLineHistoryTest()
        {
            var lineHistory  = Helpers.LoadResource(Paths.GitLineLogOutput, typeof(GitCommandsTest).Assembly);
            var executorMock = new Mock <ICommandLineExecutor>();
            var fileName     = "dir/bla.js";
            var lineNumber   = 2;
            var gitCommand   = $"log --pretty='commit-%h;auth-%an' -L {lineNumber},{lineNumber}:\"{fileName}\" --no-patch";

            executorMock.Setup(mock => mock.Execute("git", It.Is <string>(command => command == gitCommand), "dir"))
            .Returns(lineHistory.Split('\n'));
            var gitCommands = new GitCommands(executorMock.Object);

            var result = gitCommands.NumberOfChangesForLine(fileName, lineNumber);

            executorMock.Verify(mock => mock.Execute("git", It.Is <string>(s => s == gitCommand), "dir"), Times.Once);
            result.Should()
            .Be(9);
        }
Esempio n. 31
0
        public static bool SolveKDiffPath(GitCommands.GitCommands gitCommands)
        {
            string kdiff3path = gitCommands.GetGlobalSetting("mergetool.kdiff3.path");
            if (string.IsNullOrEmpty(kdiff3path) || !File.Exists(kdiff3path))
            {
                kdiff3path = @"c:\Program Files\KDiff3\kdiff3.exe";
                if (string.IsNullOrEmpty(kdiff3path) || !File.Exists(kdiff3path))
                {
                    kdiff3path = @"c:\Program Files (x86)\KDiff3\kdiff3.exe";
                    if (string.IsNullOrEmpty(kdiff3path) || !File.Exists(kdiff3path))
                    {
                        kdiff3path = GetRegistryValue(Registry.LocalMachine, "SOFTWARE\\KDiff3", "") + "\\kdiff3.exe";
                        if (string.IsNullOrEmpty(kdiff3path) || !File.Exists(kdiff3path))
                        {
                            kdiff3path = "";
                            return false;
                        }
                    }
                }
            }
            gitCommands.SetGlobalSetting("mergetool.kdiff3.path", kdiff3path);

            return true;
        }
 public static void AddStringSetting(this SettingsLayout aLayout, string aCaption, GitCommands.Settings.StringSetting aSetting)
 {
     aLayout.AddSetting(new StringISettingAdapter(aCaption, aSetting));
 }
 public StringISettingAdapter(string aCaption, GitCommands.Settings.StringSetting setting)
     : base(setting.FullPath, aCaption, setting.DefaultValue)
 {
 }