コード例 #1
0
ファイル: CommitsService.cs プロジェクト: waie123/GitMind
        private static string ShortSubject(GitStatus status)
        {
            string subject   = status.MergeMessage?.Trim() ?? "";
            string firstLine = subject.Split("\n".ToCharArray())[0];

            return(firstLine);
        }
コード例 #2
0
 public GitStatus AddEntry(string path, GitStatus status)
 {
     if (string.IsNullOrEmpty(path) || path == ".")
     {
         this._status = status;
         return status;
     }
     if (_entries == null)
         _entries = new Dictionary<string, GitStatusSet>();
     string entry;
     string subpath;
     var pos = path.IndexOf('/');
     if (pos < 0)
     {
         entry = path;
         subpath = null;
     }
     else
     {
         entry = path.Substring(0, pos);
         subpath = path.Substring(pos + 1);
     }
     GitStatusSet subset;
     if (!_entries.TryGetValue(entry, out subset))
         _entries[entry] = subset = new GitStatusSet();
     status = subset.AddEntry(subpath, status);
     if (status == GitStatus.Added || status == GitStatus.Deleted || status == GitStatus.Modified)
     {
         this._status = GitStatus.Modified;
     }
     return this._status;
 }
コード例 #3
0
        public void TestFileCounts_UnstagedOnly()
        {
            string[] lines = @"## u/geevens/test...origin/u/geevens/test
 M second
 M third
 M fourth
 M fifth
 M sixth
 D tenth
 D eleventh
 D twelveth
 D thirteenth
 D fourteenth
 D fifteenth
 A seventeenth
 A eighteenth
 A nineteenth
 A twentith
".Split(new string[] { "\r\n" }, StringSplitOptions.None);

            GitStatus status = GitStatus.ParseLines(lines);

            Assert.AreEqual(@"u/geevens/test", status.Branch);
            Assert.AreEqual(GitStatus.UpToDateString, status.RemoteChanges);
            Assert.AreEqual(@"[ +0 ~0 -0 | +4 ~5 -6 ! ]", status.AllLocalChanges);
            Assert.AreEqual(@"[ +4 ~5 -6 ! ]", status.MimimalLocalChanges);
        }
コード例 #4
0
        public async Task <MRepository> UpdateAsync(
            MRepository mRepository, GitStatus status, IReadOnlyList <string> repoIds)
        {
            return(await Task.Run(async() =>
            {
                MRepository repository = mRepository;
                string workingFolder = repository.WorkingFolder;

                try
                {
                    await UpdateRepositoryAsync(repository, status, repoIds);
                }
                catch (Exception e)
                {
                    Log.Exception(e, "Failed to update repository");

                    Log.Debug("Retry from scratch using a new repository ...");

                    repository = new MRepository()
                    {
                        WorkingFolder = workingFolder
                    };

                    await UpdateRepositoryAsync(repository, status, repoIds);
                }

                return repository;
            }));
        }
コード例 #5
0
        public async Task ShouldRefreshAndReturnCombinedStatusAndLockInformation1()
        {
            var responseGitStatus = new GitStatus {
                LocalBranch = "master",
                Entries     =
                    new List <GitStatusEntry> {
                    new GitStatusEntry("SomeLockedBinary.psd", null, "SomeLockedBinary.psd", GitFileStatus.Modified),
                    new GitStatusEntry("subFolder/AnotherLockedBinary.psd", null, "subFolder/AnotherLockedBinary.psd", GitFileStatus.Modified),
                    new GitStatusEntry("subFolder/UnLockedBinary.psd", null, "subFolder/UnLockedBinary.psd", GitFileStatus.Modified),
                }
            };

            var responseGitLocks = new List <GitLock> {
                new GitLock("SomeLockedBinary.psd", "SomeLockedBinary.psd", "Someone", 1),
                new GitLock("SomeoneElsesBinary.psd", "SomeoneElsesBinary.psd", "SomeoneElse", 2),
                new GitLock("subFolder/AnotherLockedBinary.psd", "subFolder/AnotherLockedBinary.psd", "Someone", 3),
            };

            var expectedGitStatus = new GitStatus {
                LocalBranch = "master",
                Entries     =
                    new List <GitStatusEntry> {
                    new GitStatusEntry("SomeLockedBinary.psd", null, "SomeLockedBinary.psd",
                                       GitFileStatus.Modified),
                    new GitStatusEntry("subFolder/AnotherLockedBinary.psd", null, "subFolder/AnotherLockedBinary.psd",
                                       GitFileStatus.Modified),
                    new GitStatusEntry("subFolder/UnLockedBinary.psd", null, "subFolder/UnLockedBinary.psd", GitFileStatus.Modified),
                }
            };

            var repositoryProcessRunner = CreateRepositoryProcessRunner(responseGitStatus, responseGitLocks);

            var repositoryManager = CreateRepositoryManager(repositoryProcessRunner);

            repositoryManager.Initialize();
            repositoryManager.Start();

            var repositoryManagerListener = Substitute.For <IRepositoryManagerListener>();

            repositoryManagerListener.AttachListener(repositoryManager);

            GitStatus?result = null;

            repositoryManager.OnStatusUpdated += s => { result = s; };

            repositoryManager.Refresh();

            await TaskEx.Delay(1000);

            repositoryManagerListener.Received(1).OnStatusUpdate(Args.GitStatus);

            result.HasValue.Should().BeTrue();
            result.Value.AssertEqual(expectedGitStatus);

            repositoryManagerListener.DidNotReceive().OnActiveBranchChanged(Arg.Any <ConfigBranch?>());
            repositoryManagerListener.DidNotReceive().OnActiveRemoteChanged(Arg.Any <ConfigRemote?>());
            repositoryManagerListener.DidNotReceive().OnHeadChanged();
            repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged();
            repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged();
        }
コード例 #6
0
        private async Task <Repository> UpdateRepositoryAsync(
            Repository sourcerepository, GitStatus status, IReadOnlyList <string> branchIds)
        {
            using (await syncRootAsync.LockAsync())
            {
                Log.Debug($"Updating repository");

                MRepository mRepository = sourcerepository.MRepository;
                mRepository.IsCached = false;

                Timing t = new Timing();

                await repositoryStructureService.UpdateAsync(mRepository, status, branchIds);

                t.Log("Updated mRepository");

                if (mRepository.TimeToCreateFresh > MinCreateTimeBeforeCaching)
                {
                    Log.Usage($"Caching repository ({t.Elapsed} ms)");
                    await cacheService.CacheAsync(mRepository);
                }

                Repository repository    = ToRepository(mRepository);
                int        branchesCount = repository.Branches.Count;
                int        commitsCount  = repository.Commits.Count;

                t.Log($"Updated repository {branchesCount} branches, {commitsCount} commits");
                Log.Debug("Updated to repository");

                return(repository);
            }
        }
コード例 #7
0
ファイル: AssertExtensions.cs プロジェクト: zvinless/Unity
 public static void AssertEqual(this GitStatus gitStatus, GitStatus other)
 {
     gitStatus.Ahead.Should().Be(other.Ahead);
     gitStatus.Behind.Should().Be(other.Behind);
     gitStatus.LocalBranch.Should().Be(other.LocalBranch);
     gitStatus.RemoteBranch.Should().Be(other.RemoteBranch);
     gitStatus.Entries.AssertEqual(other.Entries);
 }
コード例 #8
0
ファイル: GitStatusData.cs プロジェクト: windygu/AnkhSVN
 GitStatusData(NoSccStatus noSccStatus)
 {
     // TODO: Complete member initialization
     //this.noSccStatus = noSccStatus;
     _indexStatus = GitStatus.Normal;
     _workStatus  = GitStatus.Normal;
     _kind        = SvnNodeKind.Unknown;
 }
コード例 #9
0
 public static void AssertEqual(this GitStatus gitStatus, GitStatus other)
 {
     gitStatus.Ahead.Should().Be(other.Ahead, "Ahead should be equal");
     gitStatus.Behind.Should().Be(other.Behind, "Behind should be equal");
     gitStatus.LocalBranch.Should().Be(other.LocalBranch, "LocalBranch should be equal");
     gitStatus.RemoteBranch.Should().Be(other.RemoteBranch, "RemoteBranch should be equal");
     gitStatus.Entries.AssertEqual(other.Entries);
 }
コード例 #10
0
 public CreateRepositoryProcessRunnerOptions(Dictionary <GitConfigGetKey, string> getConfigResults = null,
                                             GitStatus gitStatusResults         = new GitStatus(),
                                             List <GitLock> gitListLocksResults = null)
 {
     GitListLocksResults = gitListLocksResults;
     GitStatusResults    = gitStatusResults;
     GitConfigGetResults = getConfigResults ?? new Dictionary <GitConfigGetKey, string>();
 }
コード例 #11
0
        public async Task TestGetStatus()
        {
            await git.InitRepoAsync();

            GitStatus status = await git.GetStatusAsync();

            Assert.AreEqual(0, status.AllChanges);
        }
コード例 #12
0
        public void TaskStatusTest()
        {
            GitStatus t = new GitStatus();
            t.BuildEngine = new DummyBuildEngine();

            bool result = t.Execute();

            Assert.IsTrue(result, "Execution failed");
        }
コード例 #13
0
ファイル: GitItem.cs プロジェクト: windygu/AnkhSVN
        static bool MaxModified(GitStatus status)
        {
            switch(status)
            {
                case GitStatus.None:
                case GitStatus.Normal:
                    return true;
            }

            return false;
        }
コード例 #14
0
        public void TestBranchAhead()
        {
            string[]  lines  = @"## u/geevens/test...origin/u/geevens/test [ahead 1]
".Split(new string[] { "\r\n" }, StringSplitOptions.None);
            GitStatus status = GitStatus.ParseLines(lines);

            Assert.AreEqual(@"u/geevens/test", status.Branch);
            Assert.AreEqual("1 ahead", status.RemoteChanges);
            Assert.AreEqual(@"[ +0 ~0 -0 | +0 ~0 -0 ! ]", status.AllLocalChanges);
            Assert.AreEqual(@"", status.MimimalLocalChanges);
        }
コード例 #15
0
        public async Task <CommitDetails> GetAsync(CommitSha commitSha, GitStatus status)
        {
            if (commitSha == CommitSha.NoCommits)
            {
                return(new CommitDetails(new CommitFile[0], null));
            }

            // Get fresh list of uncomitted files or try to get them from cach, otherwise get from repo
            if (commitSha == CommitSha.Uncommitted || !commitsFiles.TryGetValue(commitSha, out CommitDetails commitDetails))
            {
                nextIdToGet = commitSha;
                await currentTask;
                if (nextIdToGet != commitSha)
                {
                    // This commit id is no longer relevant
                    return(new CommitDetails(new CommitFile[0], null));
                }

                string message = (commitSha == CommitSha.Uncommitted || commitSha == CommitSha.NoCommits)
                                        ? null
                                        : (await gitCommitService.GetCommitMessageAsync(commitSha.Sha, CancellationToken.None)).Or(null);

                Task <R <IReadOnlyList <GitFile> > > commitsFilesForCommitTask =
                    CommitsFilesForCommitTask(commitSha, status);

                GitConflicts conflicts = GitConflicts.None;
                if (commitSha == CommitSha.Uncommitted && status.HasConflicts)
                {
                    conflicts = (await gitStatusService.GetConflictsAsync(CancellationToken.None)).Or(GitConflicts.None);
                }

                currentTask = commitsFilesForCommitTask;

                if ((await commitsFilesForCommitTask).HasValue(out var commitsFilesForCommit))
                {
                    var files = commitsFilesForCommit.Select(f =>
                    {
                        GitConflictFile conflict = conflicts.Files.FirstOrDefault(cf => cf.FilePath == f.FilePath);
                        return(new CommitFile(f, conflict));
                    })
                                .ToList();

                    commitDetails = new CommitDetails(files, message);
                    // Cache the list of files
                    commitsFiles[commitSha] = commitDetails;
                    return(commitDetails);
                }

                Log.Error($"Failed to get files for {commitSha}");
                return(new CommitDetails(new CommitFile[0], message));
            }

            return(commitDetails);
        }
コード例 #16
0
        public void TestDeletedRemote()
        {
            string[]  lines  = @"## improve-status-parsing...origin/improve-status-parsing [gone]
".Split(new string[] { "\r\n" }, StringSplitOptions.None);
            GitStatus status = GitStatus.ParseLines(lines);

            Assert.AreEqual(@"improve-status-parsing", status.Branch);
            Assert.AreEqual("remote-gone", status.RemoteChanges);
            Assert.AreEqual(@"[ +0 ~0 -0 | +0 ~0 -0 ! ]", status.AllLocalChanges);
            Assert.AreEqual(@"", status.MimimalLocalChanges);
        }
コード例 #17
0
        public async Task ShouldDetectFileChanges()
        {
            await Initialize(TestRepoMasterCleanSynchronized);

            var managerAutoResetEvent = new RepositoryManagerAutoResetEvent();

            var repositoryManagerListener = Substitute.For <IRepositoryManagerListener>();

            repositoryManagerListener.AttachListener(RepositoryManager, managerAutoResetEvent);

            var expected = new GitStatus {
                Behind       = 1,
                LocalBranch  = "master",
                RemoteBranch = "origin/master",
                Entries      =
                    new List <GitStatusEntry> {
                    new GitStatusEntry("foobar.txt", TestRepoMasterCleanSynchronized.Combine("foobar.txt"),
                                       "foobar.txt", GitFileStatus.Untracked)
                }
            };

            var result = new GitStatus();

            RepositoryManager.OnRepositoryChanged += status => { result = status; };

            Logger.Trace("Issuing Changes");

            var foobarTxt = TestRepoMasterCleanSynchronized.Combine("foobar.txt");

            foobarTxt.WriteAllText("foobar");

            await TaskManager.Wait();

            // give the fs watcher a bit of time to catch up
            await TaskEx.Delay(200);

            await TaskManager.Wait();

            managerAutoResetEvent.OnRepositoryChanged.WaitOne(TimeSpan.FromSeconds(2)).Should().BeTrue();

            Logger.Trace("Continue test");

            repositoryManagerListener.Received().OnRepositoryChanged(Args.GitStatus);
            result.AssertEqual(expected);

            repositoryManagerListener.ReceivedWithAnyArgs().OnIsBusyChanged(Args.Bool);
            repositoryManagerListener.DidNotReceive().OnActiveBranchChanged();
            repositoryManagerListener.DidNotReceive().OnActiveRemoteChanged();
            repositoryManagerListener.DidNotReceive().OnHeadChanged();
            repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged();
            repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged();
            repositoryManagerListener.DidNotReceive().OnRemoteOrTrackingChanged();
            repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock);
        }
コード例 #18
0
        static void Main(string[] args)
        {
            OldLogger.AnnounceStartStopActions = false;
#if DEBUG
            OldLogger.AnnounceStartStopActions = true;
#endif

            GitStatus status = GitStatus.Get();
            string    root   = Environment.GetEnvironmentVariable("REPO_ROOT");
            OldLogger.LogLine(String.Join(" ", new string[] { root, status.Branch, status.RemoteChanges, status.AllLocalChanges }));
        }
コード例 #19
0
        private async Task UpdateRepositoryAsync(GitStatus status, IReadOnlyList <string> repoIds)
        {
            if (Repository == null)
            {
                Log.Warn("No repository yet to update");
                return;
            }

            Repository = await UpdateRepositoryAsync(Repository, status, repoIds);

            RepositoryUpdated?.Invoke(this, new RepositoryUpdatedEventArgs());
        }
コード例 #20
0
ファイル: BranchService.cs プロジェクト: waie123/GitMind
        public void AddActiveBranches(IReadOnlyList <GitBranch> branches, MRepository repository)
        {
            GitStatus status = repository.Status;

            //GitBranch2 currentBranch = branches.GetCurrent();

            foreach (GitBranch gitBranch in branches)
            {
                BranchName branchName = gitBranch.Name;
                if (branchName == BranchName.OriginHead || branchName == BranchName.Head)
                {
                    continue;
                }

                MSubBranch subBranch = ToBranch(gitBranch, repository);
                repository.SubBranches[subBranch.SubBranchId] = subBranch;

                if (!status.OK && gitBranch.IsCurrent && !gitBranch.IsRemote)
                {
                    // Setting virtual uncommitted commit as tip of the current branch
                    subBranch.TipCommitId           = repository.Uncommitted.Id;
                    subBranch.TipCommit.SubBranchId = subBranch.SubBranchId;
                }
            }

            if (!branches.Any())
            {
                MSubBranch subBranch = ToEmptyMasterBranch(repository);
                repository.SubBranches[subBranch.SubBranchId] = subBranch;

                if (!status.OK)
                {
                    // Setting virtual uncommitted commit as tip of the current branch
                    subBranch.TipCommitId           = repository.Uncommitted.Id;
                    subBranch.TipCommit.SubBranchId = subBranch.SubBranchId;
                }
            }

            if (branches.TryGetCurrent(out GitBranch currentBranch) && currentBranch.IsDetached)
            {
                MSubBranch subBranch = ToBranch(currentBranch, repository);
                repository.SubBranches[subBranch.SubBranchId] = subBranch;

                if (!status.OK)
                {
                    // Setting virtual uncommitted commit as tip of the detached branch
                    subBranch.TipCommitId           = repository.Uncommitted.Id;
                    subBranch.TipCommit.SubBranchId = subBranch.SubBranchId;
                }
            }
        }
コード例 #21
0
        public void TestMergeConflict()
        {
            string[]  lines  = @"## improve-status-parsing...origin/improve-status-parsing [ahead 5]
M  zune/client/xaml/music/UI/Music.UI.vcxproj
UU zune/client/xaml/music/UI/Music.UI.vcxproj.filters
M  zune/client/xaml/music/UI/Services/NowPlayingViewManager.cpp
".Split(new string[] { "\r\n" }, StringSplitOptions.None);
            GitStatus status = GitStatus.ParseLines(lines);

            Assert.AreEqual(@"improve-status-parsing", status.Branch);
            Assert.AreEqual("5 ahead", status.RemoteChanges);
            Assert.AreEqual(@"[ +0 ~2 -0 #1 | +0 ~0 -0 #1 ! ]", status.AllLocalChanges);
            Assert.AreEqual(@"[ +0 ~2 -0 #1 | +0 ~0 -0 #1 ! ]", status.MimimalLocalChanges);
        }
コード例 #22
0
ファイル: GitStatusData.cs プロジェクト: windygu/AnkhSVN
        public GitStatusData(GitStatusEventArgs status)
        {
            if (status == null)
            {
                throw new ArgumentNullException("status");
            }

            _conflicted  = status.Conflicted;
            _indexStatus = status.IndexStatus;
            _workStatus  = status.WorkingDirectoryStatus;
            _ignored     = status.Ignored;
            _conflicted  = status.Conflicted;
            _kind        = (SvnNodeKind)(int)status.NodeKind;
            _modified    = status.IndexModified || status.WorkingDirectoryModified;
        }
コード例 #23
0
        public async Task ShouldDetectGitPull()
        {
            await Initialize(TestRepoMasterCleanSynchronized);

            var managerAutoResetEvent = new RepositoryManagerAutoResetEvent();

            var repositoryManagerListener = Substitute.For <IRepositoryManagerListener>();

            repositoryManagerListener.AttachListener(RepositoryManager, managerAutoResetEvent);

            var expected = new GitStatus {
                LocalBranch  = "master",
                RemoteBranch = "origin/master",
                Entries      = new List <GitStatusEntry>()
            };

            var result = new GitStatus();

            RepositoryManager.OnRepositoryChanged += status => { result = status; };

            Logger.Trace("Issuing Command");

            await RepositoryManager.Pull("origin", "master").StartAsAsync();

            await TaskManager.Wait();

            managerAutoResetEvent.OnRepositoryChanged.WaitOne(TimeSpan.FromSeconds(7)).Should().BeTrue();
            managerAutoResetEvent.OnActiveBranchChanged.WaitOne(TimeSpan.FromSeconds(7)).Should().BeTrue();

            WaitForNotBusy(managerAutoResetEvent, 3);
            WaitForNotBusy(managerAutoResetEvent, 3);

            Logger.Trace("Continue test");

            repositoryManagerListener.ReceivedWithAnyArgs().OnIsBusyChanged(Args.Bool);
            RepositoryManager.IsBusy.Should().BeFalse();

            repositoryManagerListener.Received().OnRepositoryChanged(Args.GitStatus);
            result.AssertEqual(expected);

            repositoryManagerListener.Received(1).OnActiveBranchChanged();
            repositoryManagerListener.DidNotReceive().OnActiveRemoteChanged();
            repositoryManagerListener.DidNotReceive().OnHeadChanged();
            repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged();
            repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged();
            repositoryManagerListener.DidNotReceive().OnRemoteOrTrackingChanged();
            repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock);
        }
コード例 #24
0
        public async Task ShouldDetectBranchChange()
        {
            await Initialize(TestRepoMasterCleanSynchronized);

            var managerAutoResetEvent = new RepositoryManagerAutoResetEvent();

            var repositoryManagerListener = Substitute.For <IRepositoryManagerListener>();

            repositoryManagerListener.AttachListener(RepositoryManager, managerAutoResetEvent);

            var expected = new GitStatus {
                LocalBranch  = "feature/document",
                RemoteBranch = "origin/feature/document",
                Entries      = new List <GitStatusEntry>()
            };

            var result = new GitStatus();

            RepositoryManager.OnRepositoryChanged += status => { result = status; };

            Logger.Trace("Issuing Command");

            await RepositoryManager.SwitchBranch("feature/document").StartAsAsync();

            await TaskManager.Wait();

            // give the fs watcher a bit of time to catch up
            await TaskEx.Delay(100);

            await TaskManager.Wait();

            managerAutoResetEvent.OnActiveBranchChanged.WaitOne(TimeSpan.FromSeconds(3)).Should().BeTrue();
            managerAutoResetEvent.OnRepositoryChanged.WaitOne(TimeSpan.FromSeconds(3)).Should().BeTrue();
            managerAutoResetEvent.OnHeadChanged.WaitOne(TimeSpan.FromSeconds(3)).Should().BeTrue();

            Logger.Trace("Continue test");

            repositoryManagerListener.Received().OnRepositoryChanged(Args.GitStatus);
            result.AssertEqual(expected);
            repositoryManagerListener.ReceivedWithAnyArgs().OnIsBusyChanged(Args.Bool);
            repositoryManagerListener.Received(1).OnActiveBranchChanged();
            repositoryManagerListener.DidNotReceive().OnActiveRemoteChanged();
            repositoryManagerListener.Received(1).OnHeadChanged();
            repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged();
            repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged();
            repositoryManagerListener.DidNotReceive().OnRemoteOrTrackingChanged();
            repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock);
        }
コード例 #25
0
        public async Task <R <GitStatus> > GetStatusAsync(CancellationToken ct)
        {
            // Log.Debug($"Call stack: {new StackTrace(false)}");

            R <CmdResult2> result = await gitCmdService.RunAsync(StatusArgs, ct);

            if (result.IsFaulted)
            {
                return(R.Error("Failed to get status", result.Exception));
            }

            GitStatus status = ParseStatus(result.Value);

            Log.Info($"Status: {status} in {result.Value.WorkingDirectory}");
            return(status);
        }
コード例 #26
0
        public async Task UpdateRepositoryAfterCommandAsync()
        {
            Task <GitStatus> statusTask = statusService.GetStatusAsync();
            Task <IReadOnlyList <string> > repoIdsTask = statusService.GetRepoIdsAsync();

            GitStatus status = await statusTask;
            IReadOnlyList <string> repoIds = await repoIdsTask;

            if (Repository.Status.IsSame(status) &&
                Repository.MRepository.RepositoryIds.SequenceEqual(repoIds))
            {
                Log.Debug("Repository has not changed after command");
                return;
            }

            await UpdateRepositoryAsync(status, repoIds);
        }
コード例 #27
0
        private void AssertProcessOutput(IEnumerable <string> lines, GitStatus expected)
        {
            var gitObjectFactory = SubstituteFactory.CreateGitObjectFactory(TestRootPath);

            GitStatus?result          = null;
            var       outputProcessor = new GitStatusOutputProcessor(gitObjectFactory);

            outputProcessor.OnEntry += status => { result = status; };

            foreach (var line in lines)
            {
                outputProcessor.LineReceived(line);
            }

            Assert.IsTrue(result.HasValue);
            result.Value.AssertEqual(expected);
        }
コード例 #28
0
ファイル: StatusService.cs プロジェクト: waie123/GitMind
        private async Task StartCheckStatusAsync(FileEventArgs fileEventArgs)
        {
            Log.Debug($"Checking status change at {fileEventArgs.DateTime} ...");

            if (await IsStatusCheckStartedAsync())
            {
                return;
            }

            Task <GitStatus> newStatusTask = GetFreshStatusAsync();

            currentStatusTask = newStatusTask;

            GitStatus newStatus = await newStatusTask;

            TriggerStatusChanged(fileEventArgs, newStatus);
        }
コード例 #29
0
        public void TestFileCounts_StagedOnly()
        {
            string[] lines = @"## u/geevens/test...origin/u/geevens/test
M  first
M  second
D  seventh
D  eighth
D  nineth
A  sixteenth
".Split(new string[] { "\r\n" }, StringSplitOptions.None);

            GitStatus status = GitStatus.ParseLines(lines);

            Assert.AreEqual(@"u/geevens/test", status.Branch);
            Assert.AreEqual(GitStatus.UpToDateString, status.RemoteChanges);
            Assert.AreEqual(@"[ +1 ~2 -3 | +0 ~0 -0 ! ]", status.AllLocalChanges);
            Assert.AreEqual(@"[ +1 ~2 -3 ]", status.MimimalLocalChanges);
        }
コード例 #30
0
        public void TestRename()
        {
            string[]  lines  = @"## improve-status-parsing...origin/improve-status-parsing [ahead 5]
 M tools/FilterWriter.exe
R  WECTools/FilterWriter/FilterWriter.sln -> tools/FilterWriter/FilterWriter.sln
?? tools/FilterWriter/App.config
?? tools/FilterWriter/FilterWriter.csproj
?? tools/FilterWriter/Logger.cs
?? tools/FilterWriter/Node.cs
?? tools/FilterWriter/Program.cs
?? tools/FilterWriter/Properties/
".Split(new string[] { "\r\n" }, StringSplitOptions.None);
            GitStatus status = GitStatus.ParseLines(lines);

            Assert.AreEqual(@"improve-status-parsing", status.Branch);
            Assert.AreEqual("5 ahead", status.RemoteChanges);
            Assert.AreEqual(@"[ +0 ~1 -0 | +6 ~1 -0 ! ]", status.AllLocalChanges);
            Assert.AreEqual(@"[ +0 ~1 -0 | +6 ~1 -0 ! ]", status.MimimalLocalChanges);
        }
コード例 #31
0
        public async Task ShouldDetectFileChanges()
        {
            await Initialize(TestRepoMasterCleanSynchronized);

            var repositoryManagerListener = Substitute.For <IRepositoryManagerListener>();

            repositoryManagerListener.AttachListener(RepositoryManager, repositoryManagerEvents);

            var expected = new GitStatus {
                Behind       = 1,
                LocalBranch  = "master",
                RemoteBranch = "origin/master",
                Entries      =
                    new List <GitStatusEntry> {
                    new GitStatusEntry("foobar.txt", TestRepoMasterCleanSynchronized.Combine("foobar.txt"),
                                       "foobar.txt", GitFileStatus.Untracked)
                }
            };

            var result = new GitStatus();

            Environment.Repository.OnStatusUpdated += status => { result = status; };

            var foobarTxt = TestRepoMasterCleanSynchronized.Combine("foobar.txt");

            foobarTxt.WriteAllText("foobar");

            await TaskManager.Wait();

            RepositoryManager.WaitForEvents();
            WaitForNotBusy(repositoryManagerEvents, 1);

            repositoryManagerListener.Received().OnStatusUpdate(Args.GitStatus);
            repositoryManagerListener.DidNotReceive().OnActiveBranchChanged(Arg.Any <ConfigBranch?>());
            repositoryManagerListener.DidNotReceive().OnActiveRemoteChanged(Arg.Any <ConfigRemote?>());
            repositoryManagerListener.DidNotReceive().OnHeadChanged();
            repositoryManagerListener.DidNotReceive().OnLocalBranchListChanged();
            repositoryManagerListener.DidNotReceive().OnRemoteBranchListChanged();
            repositoryManagerListener.Received().OnIsBusyChanged(Args.Bool);
            repositoryManagerListener.DidNotReceive().OnLocksUpdated(Args.EnumerableGitLock);

            result.AssertEqual(expected);
        }
コード例 #32
0
        private static void SetCurrentBranchAndCommit(MRepository repository, IReadOnlyList <GitBranch> branches)
        {
            GitStatus status        = repository.Status;
            MBranch   currentBranch = repository.Branches.Values.First(b => b.IsActive && b.IsCurrent);

            repository.CurrentBranchId = currentBranch.Id;
            branches.TryGetCurrent(out GitBranch current);
            repository.CurrentCommitId = status.OK
                                ? current != null
                                        ? repository.Commit(new CommitId(current.TipSha.Sha)).Id
                                        : CommitId.NoCommits
                                : CommitId.Uncommitted;

            if (currentBranch.TipCommit.IsVirtual &&
                currentBranch.TipCommit.FirstParentId == repository.CurrentCommitId)
            {
                repository.CurrentCommitId = currentBranch.TipCommit.Id;
            }
        }
コード例 #33
0
ファイル: VisualGitStatus.cs プロジェクト: pvginkel/VisualGit
        public VisualGitStatus(GitStatusEventArgs args)
        {
            if (args == null)
                throw new ArgumentNullException("args");

            _nodeKind = args.NodeKind;
            _state = args.LocalContentStatus;
            _localCopied = args.LocalCopied;

            if (args.WorkingCopyInfo != null)
            {
                _lastChangeTime = args.WorkingCopyInfo.LastChangeTime;
                _lastChangeRevision = args.WorkingCopyInfo.LastChangeRevision;
                _lastChangeAuthor = args.WorkingCopyInfo.LastChangeAuthor;
                _revision = args.WorkingCopyInfo.Revision;
            }

            _treeConflict = args.TreeConflict;
            if(_treeConflict != null)
                _treeConflict.Detach();
        }
コード例 #34
0
		public static Image GetImage(GitStatus status)
		{
			switch (status) {
				case GitStatus.Added:
					return GetImage(StatusIcon.Added);
				case GitStatus.Deleted:
					return GetImage(StatusIcon.Deleted);
				case GitStatus.Modified:
					return GetImage(StatusIcon.Modified);
				case GitStatus.OK:
					return GetImage(StatusIcon.OK);
				default:
					return null;
			}
		}
コード例 #35
0
ファイル: VisualGitStatus.cs プロジェクト: pvginkel/VisualGit
 /// <summary>
 /// Create non-locked, non-copied item with status specified
 /// </summary>
 /// <param name="allStatuses"></param>
 private VisualGitStatus(GitStatus allStatuses)
 {
     _state = allStatuses;
     //_localLocked = false;
     //_localCopied = false;
 }