public void GetChangedFilesTest1()
        {
            var stopwatch = new Stopwatch();

            string workingFolder = @"D:\Users\Public\My Projects Tryout\orchard-1.0.20\src";
            GitFileStatusTracker target = new GitFileStatusTracker(workingFolder);

            stopwatch.Start();
            var list = target.GetChangedFiles();
            stopwatch.Stop();
            Debug.WriteLine(list.Count() + ":" + stopwatch.ElapsedMilliseconds);

            stopwatch.Reset();
            stopwatch.Start();
            var changes = target.ChangedFiles;

            stopwatch.Stop();
            Debug.WriteLine(changes.Count() + ":" + stopwatch.ElapsedMilliseconds);

            Assert.AreEqual(list.Count(), changes.Count());

             GitBash.GitExePath = @"C:\Program Files (x86)\Git\bin\sh.exe";
            stopwatch.Reset();
            stopwatch.Start();
            GitBash.Run("status --porcelain -z --untracked-files", workingFolder);

            stopwatch.Stop();
            Debug.WriteLine(stopwatch.ElapsedMilliseconds);
        }
Beispiel #2
0
        internal void Refresh(GitFileStatusTracker tracker)
        {
            try
            {
                this.branchList.ItemsSource = null;
                this.tagList.ItemsSource    = null;

                CloseCommitDetails_Executed(this, null);
                selectedCommits.Clear();
                SetSelectedCommitCount();
                this.HistoryGraph.Show(tracker);
                this.tracker = tracker;
                if (tracker != null)
                {
                    //double delta = DateTime.Now.Subtract(lastTimeRefresh).TotalMilliseconds;
                    //if (delta < 1000) return; //no refresh within 1 second

                    this.branchList.ItemsSource = tracker.RepositoryGraph.Refs
                                                  .Where(r => r.Type == RefTypes.Branch)
                                                  .Select(r => r.Name);

                    this.tagList.ItemsSource = tracker.RepositoryGraph.Refs
                                               .Where(r => r.Type == RefTypes.Tag)
                                               .Select(r => r.Name);
                }
            }
            catch (Exception ex)
            {
                ShowStatusMessage(ex.Message);
                Log.WriteLine("History View Refresh: {0}", ex.ToString());
            }

            lastTimeRefresh = DateTime.Now;
        }
        internal void Refresh(GitFileStatusTracker tracker, bool force = false)
        {
            //var frame = this.Frame as IVsWindowFrame;
            //if (frame == null || frame.IsVisible() == 1) return;

            try
            {
                var repository = (tracker == null || !tracker.HasGitRepository) ? "" :
                                 string.Format(" - {0}", tracker.CurrentBranch, tracker.GitWorkingDirectory);

                this.Caption = Resources.ResourceManager.GetString("PendingChangesToolWindowCaption") + repository;

                if (!GitSccOptions.Current.DisableAutoRefresh || force || tracker == null)
                {
                    ((PendingChangesView)control).Refresh(tracker);
                }
                if (GitSccOptions.Current.DisableAutoRefresh)
                {
                    this.Caption += " - [AUTO REFRESH DISABLED]";
                }
            }
            catch (Exception ex)
            {
                Log.WriteLine("Pending Changes Tool Window Refresh: {0}", ex.ToString());
            }
        }
        internal void Refresh(GitFileStatusTracker tracker)
        {
            try
            {
                this.branchList.ItemsSource = null;
                this.tagList.ItemsSource = null;

                CloseCommitDetails_Executed(this, null);
                selectedCommits.Clear();
                SetSelectedCommitCount();
                this.HistoryGraph.Show(tracker);

                this.tracker = tracker;
                if (tracker != null)
                {
                    double delta = DateTime.Now.Subtract(lastTimeRefresh).TotalMilliseconds;
                    if (delta < 1000) return; //no refresh within 1 second

                    this.branchList.ItemsSource = tracker.RepositoryGraph.Refs
                        .Where(r => r.Type == RefTypes.Branch)
                        .Select(r => r.Name);

                    this.tagList.ItemsSource = tracker.RepositoryGraph.Refs
                        .Where(r => r.Type == RefTypes.Tag)
                        .Select(r => r.Name);

                    lastTimeRefresh = DateTime.Now;
                }
            }
            catch (Exception ex)
            {
                Log.WriteLine("History View Refresh: {0}", ex.ToString());
            }
        }
        internal static IEnumerable<string> GetOptions(GitFileStatusTracker tracker, string command)
        {
            if (tracker == null) return new string[] { };
            var options = Commands.Where(i => Regex.IsMatch(command, i.Key)).Select(i => i.Value).FirstOrDefault();
            if (options == null) return new string[] { };
            switch (options[0])
            {
                case "*branches*":
                    return tracker.RepositoryGraph.Refs
                        .Where(r => r.Type == RefTypes.Branch)
                        .Select(r => r.Name);

                case "*tags*":
                    return tracker.RepositoryGraph.Refs
                        .Where(r => r.Type == RefTypes.Tag)
                        .Select(r => r.Name);

                case "*remotes*":
                    return tracker.Remotes;

                case "*configs*":
                    return tracker.Configs.Keys;

                case "*commits*":
                    return tracker.RepositoryGraph.Commits
                        .OrderByDescending(c=>c.AuthorDate)
                        .Select(r => r.ShortId);
            }

            if (options[0].Contains("|")) 
                return options[0].Split('|');
            else
                return options;
        }
        internal void InitRepo()
        {
            var solutionPath = Path.GetDirectoryName(GetSolutionFileName());

            GitFileStatusTracker.Init(solutionPath);
            File.WriteAllText(Path.Combine(solutionPath, ".gitignore"),
                              @"Thumbs.db
*.obj
*.exe
*.pdb
*.user
*.aps
*.pch
*.vspscc
*_i.c
*_p.c
*.ncb
*.suo
*.sln.docstates
*.tlb
*.tlh
*.bak
*.cache
*.ilk
*.log
[Bb]in
[Dd]ebug*/
*.lib
*.sbr
obj/
[Rr]elease*/
_ReSharper*/
[Tt]est[Rr]esult*"
                              );
        }
        public void Clear()
        {
            foreach (var repo in _repositories)
            {
                repo.FilesChanged     -= Repo_FilesChanged;
                repo.FileStatusUpdate -= Repo_FileStatusUpdate;
            }

            if (_solutionTracker != null)
            {
                _solutionTracker.BranchChanged -= _solutionTracker_BranchChanged;
                _solutionTracker = null;
            }
            ActiveTracker = null;

            //if (_activeTracker != null)
            //{
            //    _activeTracker.BranchChanged -= _solutionTracker_BranchChanged;
            //    _activeTracker = null;
            //}

            _repositories       = new List <GitFileStatusTracker>();
            _fileRepoLookup     = new ConcurrentDictionary <string, GitFileStatusTracker>();
            _basePathRepoLookup = new ConcurrentDictionary <string, GitFileStatusTracker>();
        }
        public void GetFileContentTest()
        {
            var tempFolder = Environment.CurrentDirectory + "\\_gitscc_test_3";
            var tempFile = Path.Combine(tempFolder, "test");

            GitFileStatusTracker.Init(tempFolder);

            string[] lines = { "First line", "Second line", "Third line" };
            File.WriteAllLines(tempFile, lines);

            GitFileStatusTracker tracker = new GitFileStatusTracker(tempFolder);
            tracker.StageFile(tempFile);
            tracker.Commit("test");

            var fileContent = tracker.GetFileContent(tempFile);

            using (var binWriter = new BinaryWriter(File.Open(tempFile + ".bk", FileMode.Create)))
            {
                binWriter.Write(fileContent);
            }

            var newlines = File.ReadAllLines(tempFile + ".bk");
            Assert.AreEqual(lines[0], newlines[0]);
            Assert.AreEqual(lines[1], newlines[1]);
            Assert.AreEqual(lines[2], newlines[2]);
        }
        internal void Refresh(GitFileStatusTracker tracker, bool force = false)
        {
            //var frame = this.Frame as IVsWindowFrame;
            //if (frame == null || frame.IsVisible() == 1) return;

            try
            {
                var repository = (tracker == null || !tracker.HasGitRepository) ? "" :
                    string.Format(" - {0}", tracker.CurrentBranch, tracker.GitWorkingDirectory);

                this.Caption = Resources.ResourceManager.GetString("PendingChangesToolWindowCaption") + repository;

                if (!GitSccOptions.Current.DisableAutoRefresh || force || tracker == null)
                {
                    ((PendingChangesView)control).Refresh(tracker);
                }
                if (GitSccOptions.Current.DisableAutoRefresh)
                {
                    this.Caption += " - [AUTO REFRESH DISABLED]";
                }
            }
            catch (Exception ex)
            {
                Log.WriteLine("Pending Changes Tool Window Refresh: {0}", ex.ToString());
            }
        }
Beispiel #10
0
        private void AddProject(IVsHierarchy pHierarchy)
        {
            string projectName = GetProjectFileName(pHierarchy);

            if (string.IsNullOrEmpty(projectName))
            {
                return;
            }
            string projectDirecotry = Path.GetDirectoryName(projectName);

            //Debug.WriteLine("==== Adding project: " + projectDirecotry);

            string gitfolder = GitFileStatusTracker.GetRepositoryDirectory(projectDirecotry);

            if (string.IsNullOrEmpty(gitfolder) ||
                trackers.Any(t => t.HasGitRepository &&
                             string.Compare(t.GitWorkingDirectory, gitfolder, true) == 0))
            {
                return;
            }

            if (gitfolder.Length < monitorFolder.Length)
            {
                monitorFolder = gitfolder;
            }
            trackers.Add(new GitFileStatusTracker(gitfolder));

            //Debug.WriteLine("==== Added git tracker: " + gitfolder);
        }
 public void GetRepositoryDirectoryTest()
 {
     GitFileStatusTracker.Init(tempFolder);
     var newFolder = tempFolder + "\\t t\\a a";
     Directory.CreateDirectory(newFolder);
     GitFileStatusTracker tracker = new GitFileStatusTracker(newFolder);
     Assert.AreEqual(tempFolder, tracker.GitWorkingDirectory);
 }
        internal void Refresh(GitFileStatusTracker tracker)
        {
            if (((IVsWindowFrame)this.Frame).IsVisible() == VSConstants.S_FALSE) return;

            control.Refresh(tracker);

            this.Caption = Resources.ResourceManager.GetString("PendingChangesToolWindowCaption") +
                (tracker.HasGitRepository ? " (" + tracker.CurrentBranch + ")" : "");
        }
        internal void Refresh(GitFileStatusTracker tracker)
        {
            ((HistoryView) control).Refresh(tracker);

            var repository = (tracker == null || !tracker.HasGitRepository) ? "" :
                string.Format(" - {1} - ({0})", tracker.CurrentBranch, tracker.GitWorkingDirectory);

            this.Caption = Resources.ResourceManager.GetString("HistoryToolWindowCaption") + repository;
        }
        internal void Refresh(GitFileStatusTracker tracker)
        {
            this.tracker = tracker;

            this.dataGrid1.ItemsSource = tracker.ChangedFiles;
            ICollectionView view = CollectionViewSource.GetDefaultView(this.dataGrid1.ItemsSource);
            view.SortDescriptions.Clear();
            view.SortDescriptions.Add(new SortDescription(sortMemberPath, sortDirection));
            view.Refresh();
        }
 internal static string GetPrompt(GitFileStatusTracker tracker)
 {
     if(tracker==null || !tracker.HasGitRepository) return "No Git Repository";
     var changed = tracker.ChangedFiles;
     return string.Format("{0} +{1} ~{2} -{3} !{4}", tracker.CurrentBranch,
         changed.Where(f=> f.Status == GitFileStatus.New || f.Status == GitFileStatus.Added).Count(),
         changed.Where(f => f.Status == GitFileStatus.Modified || f.Status == GitFileStatus.Staged).Count(),
         changed.Where(f => f.Status == GitFileStatus.Deleted || f.Status == GitFileStatus.Removed).Count(),
         changed.Where(f => f.Status == GitFileStatus.Conflict).Count()
     );
 }
        internal void Refresh(GitFileStatusTracker tracker)
        {
            //if (((IVsWindowFrame)this.Frame).IsVisible() == VSConstants.S_FALSE) return;

            control.Refresh(tracker);

            var repository = (tracker == null || !tracker.HasGitRepository) ? " (no repository)" :
                string.Format(" - {1} - ({0})", tracker.CurrentBranch, tracker.GitWorkingDirectory);

            this.Caption = Resources.ResourceManager.GetString("PendingChangesToolWindowCaption") + repository;
        }
        public void DiffFileTest()
        {
            GitFileStatusTracker.Init(tempFolder);
            File.WriteAllLines(tempFile, lines);

            GitFileStatusTracker tracker = new GitFileStatusTracker(tempFolder);
            tracker.StageFile(tempFile);
            tracker.Commit("test message");
            File.WriteAllText(tempFile, "changed text");
            var diff = tracker.DiffFile(tempFile);
            Console.WriteLine(diff);
            Assert.IsTrue(diff.StartsWith("@@ -1,3 +1 @@"));
        }
        public async Task SetSolutionTracker(string solutionFilePath)
        {
            if (!string.IsNullOrWhiteSpace(solutionFilePath))
            {
                if (_solutionTracker != null)
                {
                    _solutionTracker.BranchChanged -= _solutionTracker_BranchChanged;
                }
                _solutionTracker = await GetTrackerForPathAsync(solutionFilePath, true, true);

                if (_solutionTracker != null)
                {
                    _solutionTracker.BranchChanged += _solutionTracker_BranchChanged;
                }
            }
        }
        public void AmendCommitTest()
        {
            GitFileStatusTracker.Init(tempFolder);
            File.WriteAllLines(tempFile, lines);

            GitFileStatusTracker tracker = new GitFileStatusTracker(tempFolder);
            tracker.StageFile(tempFile);

            tracker.Commit("test message");
            Assert.IsTrue(tracker.LastCommitMessage.StartsWith("test message"));

            File.WriteAllText(tempFile, "changed text");
            tracker.StageFile(tempFile);
            tracker.AmendCommit("new message");
            Assert.IsTrue(tracker.LastCommitMessage.StartsWith("new message"));
        }
        public void CheckOutFileTest()
        {
            GitFileStatusTracker.Init(tempFolder);
            File.WriteAllLines(tempFile, lines);

            GitFileStatusTracker tracker = new GitFileStatusTracker(tempFolder);
            tracker.StageFile(tempFile);
            tracker.Commit("test");

            File.WriteAllText(tempFile, "changed text");
            tracker.CheckOutFile(tempFile);
            var newlines = File.ReadAllLines(tempFile);
            Assert.AreEqual(lines[0], newlines[0]);
            Assert.AreEqual(lines[1], newlines[1]);
            Assert.AreEqual(lines[2], newlines[2]);
        }
        internal void Refresh(GitFileStatusTracker tracker)
        {
            var frame = this.Frame as IVsWindowFrame;
            if (frame == null || frame.IsVisible() == VSConstants.S_FALSE) return;

            this.Caption = Resources.ResourceManager.GetString("PendingChangesToolWindowCaption");
            try
            {
                ((PendingChangesView)control).Refresh(tracker);

                var repository = (tracker == null || !tracker.HasGitRepository) ? "" :
                    string.Format(" - {1} - ({0})", tracker.CurrentBranch, tracker.GitWorkingDirectory);

                this.Caption = Resources.ResourceManager.GetString("PendingChangesToolWindowCaption") + repository;
            }
            catch { } // better than crash
        }
        public async Task <GitFileStatusTracker> GetTrackerForPathAsync(string filename, bool setActiveTracker = false, bool createTracker = true)
        {
            if (string.IsNullOrWhiteSpace(filename))
            {
                return(null);
            }

            GitFileStatusTracker repo = null;

            filename = filename.ToLower();

            //check out quick list to see if we have he file first.
            if (!_fileRepoLookup.TryGetValue(filename, out repo))
            {
                var basePath = await GetGitRepositoryAsync(filename);

                if (!string.IsNullOrWhiteSpace(basePath) && !_basePathRepoLookup.TryGetValue(basePath, out repo))
                {
                    repo = new GitFileStatusTracker(basePath);
                    repo.EnableRepositoryWatcher();
                    repo.FilesChanged     += Repo_FilesChanged;
                    repo.FileStatusUpdate += Repo_FileStatusUpdate;
                    repo.OnCommitChanged  += Repo_OnCommitChanged;
                    //repo.BranchChanged += Repo_BranchChanged;

                    //add our refrences so we can do a quick lookup later
                    _repositories.Add(repo);
                    _basePathRepoLookup.TryAdd(basePath, repo);
                }
                _fileRepoLookup.TryAdd(filename, repo);
            }


            if (repo == null)
            {
                return(ActiveTracker);
            }

            if (setActiveTracker)
            {
                ActiveTracker = repo;
            }

            return(repo);
        }
		internal void Open(string directory)
		{
			workingDirectory = directory;

			tracker = new GitFileStatusTracker(directory);
			if (tracker.HasGitRepository) directory = tracker.GitWorkingDirectory;

			if (Directory.Exists(directory))
			{
				fileSystemWatcher = new FileSystemWatcher(directory);
				fileSystemWatcher.IncludeSubdirectories = true;
				//fileSystemWatcher.Created += new FileSystemEventHandler(fileSystemWatcher_Changed);
				fileSystemWatcher.Deleted += new FileSystemEventHandler(fileSystemWatcher_Changed);
				//fileSystemWatcher.Renamed += new FileSystemEventHandler(fileSystemWatcher_Changed);
				fileSystemWatcher.Changed += new FileSystemEventHandler(fileSystemWatcher_Changed);
				fileSystemWatcher.EnableRaisingEvents = true;
			}
		}
Beispiel #24
0
        public GitFileStatusTracker GetTrackerForPath(string filename, bool setActiveTracker = false, bool createTracker = true)
        {
            if (string.IsNullOrWhiteSpace(filename))
            {
                return(null);
            }

            GitFileStatusTracker repo = null;
            var filePath = filename.ToLower();

            //check out quick list to see if we have he file first.
            if (!_fileRepoLookup.TryGetValue(filePath, out repo))
            {
                var basePath = GetGitRepository(filePath);
                if (createTracker &&
                    !string.IsNullOrWhiteSpace(basePath) && !_basePathRepoLookup.TryGetValue(basePath, out repo))
                {
                    repo = new GitFileStatusTracker(basePath);
                    repo.EnableRepositoryWatcher();
                    repo.FilesChanged     += Repo_FilesChanged;
                    repo.FileStatusUpdate += Repo_FileStatusUpdate;
                    //repo.BranchChanged += Repo_BranchChanged;

                    //add our refrences so we can do a quick lookup later
                    _repositories.Add(repo);
                    _basePathRepoLookup.TryAdd(basePath, repo);
                }
                _fileRepoLookup.TryAdd(filePath, repo);
            }


            //if (repo == null)
            //{
            //    return ActiveTracker;
            //}

            if (setActiveTracker && repo != null)
            {
                ActiveTracker = repo;
            }

            return(repo);
        }
Beispiel #25
0
        internal void Refresh(GitFileStatusTracker tracker)
        {
            try
            {
                var repository = (tracker == null || !tracker.HasGitRepository) ? "" :
                                 string.Format(" ({0})", tracker.CurrentBranch, tracker.GitWorkingDirectory);

                this.Caption = Resources.ResourceManager.GetString("PendingChangesToolWindowCaption") + repository;

                control.Refresh(tracker);
                if (GitSccOptions.Current.DisableAutoRefresh)
                {
                    this.Caption += " - [AUTO REFRESH DISABLED]";
                }
            }
            catch (Exception ex)
            {
                Log.WriteLine("Pending Changes Tool Window Refresh: {0}", ex.ToString());
            }
        }
        internal void Refresh(GitFileStatusTracker tracker)
        {
            var frame = this.Frame as IVsWindowFrame;
            if (frame == null || frame.IsVisible() == 1) return;

            try
            {
                this.Caption = Resources.ResourceManager.GetString("HistoryToolWindowCaption");

                ((HistoryView)control).Refresh(tracker);

                var repository = (tracker == null || !tracker.HasGitRepository) ? "" :
                    string.Format(" - {1} - ({0})", tracker.CurrentBranch, tracker.GitWorkingDirectory);

                this.Caption = Resources.ResourceManager.GetString("HistoryToolWindowCaption") + repository;
            }
            catch (Exception ex)
            {
                Log.WriteLine("History Tool Window Refresh: {0}", ex.ToString());
            }
        }
Beispiel #27
0
		internal void Open(string directory)
		{
			workingDirectory = directory;

			tracker = new GitFileStatusTracker(directory);
			if (tracker.IsGit) directory = tracker.WorkingDirectory;

			if (Directory.Exists(directory))
			{
                if (fileSystemWatcher != null) { fileSystemWatcher.Dispose();  }

                fileSystemWatcher = new FileSystemWatcher(directory);
				fileSystemWatcher.IncludeSubdirectories = true;
				//fileSystemWatcher.Created += new FileSystemEventHandler(fileSystemWatcher_Changed);
				fileSystemWatcher.Deleted += new FileSystemEventHandler(fileSystemWatcher_Changed);
				//fileSystemWatcher.Renamed += new FileSystemEventHandler(fileSystemWatcher_Changed);
				fileSystemWatcher.Changed += new FileSystemEventHandler(fileSystemWatcher_Changed);
				fileSystemWatcher.EnableRaisingEvents = true;
			}

            GraphChanged(this, null);
		}
Beispiel #28
0
        internal async Task Refresh(GitFileStatusTracker tracker)
        {
            try
            {
                var repository = (tracker == null || !tracker.IsGit) ? "" :
                                 string.Format(" ({0})", tracker.CurrentBranchDisplayName, tracker.WorkingDirectory);

                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                UpdateRepositoryName(repository);
                //this.Caption = Resources.ResourceManager.GetString("PendingChangesToolWindowCaption") + repository;

                await control.Refresh();

                //if (GitSccOptions.Current.DisableAutoRefresh)
                //{
                //    this.Caption += " - [AUTO REFRESH DISABLED]";
                //}
            }
            catch (Exception ex)
            {
                Log.WriteLine("Pending Changes Tool Window Refresh: {0}", ex.ToString());
            }
        }
        private void FireActiveTrackerChangedEvent(GitFileStatusTracker repository)
        {
            var eventArgs = new GitRepositoryEvent(repository);

            _onActiveTrackerUpdateEventHandler?.Invoke(this, eventArgs);
        }
        public void HasGitRepositoryTest()
        {
            GitFileStatusTracker.Init(tempFolder);
            GitFileStatusTracker tracker = new GitFileStatusTracker(tempFolder);

            Assert.IsTrue(tracker.HasGitRepository);
            Assert.AreEqual(tempFolder, tracker.GitWorkingDirectory);
            Assert.IsTrue(Directory.Exists(tempFolder + "\\.git"));
        }
        public void GetFileContentTestNegative()
        {
            GitFileStatusTracker tracker = new GitFileStatusTracker(tempFolder);
            var fileContent = tracker.GetFileContent(tempFile + ".bad");
            Assert.IsNull(fileContent);

            GitFileStatusTracker.Init(tempFolder);

            File.WriteAllLines(tempFile, lines);
            tracker = new GitFileStatusTracker(tempFolder);
            fileContent = tracker.GetFileContent(tempFile + ".bad");
            Assert.IsNull(fileContent);

            tracker.StageFile(tempFile);
            fileContent = tracker.GetFileContent(tempFile + ".bad");
            Assert.IsNull(fileContent);

            tracker.Commit("test");

            fileContent = tracker.GetFileContent(tempFile + ".bad");
            Assert.IsNull(fileContent);
        }
        public async Task<GitFileStatusTracker> GetTrackerForPathAsync(string filename,bool setActiveTracker = false ,bool createTracker = true)
        {
            if (string.IsNullOrWhiteSpace(filename)) return null;

            GitFileStatusTracker repo = null;
            filename = filename.ToLower();

            //check out quick list to see if we have he file first. 
            if (!_fileRepoLookup.TryGetValue(filename, out repo))
            {
                var basePath = await GetGitRepositoryAsync(filename);
                if (!string.IsNullOrWhiteSpace(basePath) && !_basePathRepoLookup.TryGetValue(basePath, out repo))
                {
                    repo = new GitFileStatusTracker(basePath);
                    repo.EnableRepositoryWatcher();
                    repo.FilesChanged += Repo_FilesChanged;
                    repo.FileStatusUpdate += Repo_FileStatusUpdate;
                    //repo.BranchChanged += Repo_BranchChanged;

                    //add our refrences so we can do a quick lookup later
                    _repositories.Add(repo);
                    _basePathRepoLookup.TryAdd(basePath, repo);
                }
                _fileRepoLookup.TryAdd(filename, repo);
            }


            if (repo == null)
            {
                return ActiveTracker;
            }

            if (setActiveTracker)
            {
                ActiveTracker = repo;
            }

            return repo;
        }
 public async Task SetSolutionTracker(string solutionFilePath)
 {
     if (!string.IsNullOrWhiteSpace(solutionFilePath))
     {
         if (_solutionTracker != null)
         {
             _solutionTracker.BranchChanged -= _solutionTracker_BranchChanged;
         }
         _solutionTracker = await GetTrackerForPathAsync(solutionFilePath, true, true);
         if (_solutionTracker != null)
         {
             _solutionTracker.BranchChanged += _solutionTracker_BranchChanged;
         }
     }
 }
        public void Clear()
        {
            foreach (var repo in _repositories)
            {
                repo.FilesChanged -= Repo_FilesChanged;
                repo.FileStatusUpdate -= Repo_FileStatusUpdate;
            }

            if (_solutionTracker != null)
            {
                _solutionTracker.BranchChanged -= _solutionTracker_BranchChanged;
                _solutionTracker = null;
            }
            ActiveTracker = null;

            _repositories = new List<GitFileStatusTracker>();
            _fileRepoLookup = new ConcurrentDictionary<string, GitFileStatusTracker>();
            _basePathRepoLookup = new ConcurrentDictionary<string, GitFileStatusTracker>();
        }
        internal void Refresh(GitFileStatusTracker tracker)
        {
            //VerifyGit();

            if (!GitBash.Exists)
            {
                Settings.Show();
                return;
            }
            else
            {
                Settings.Hide();
            }

            this.label3.Content = "Changed files";
            this.tracker        = tracker;
            //this.gitConsole1.tracker = tracker;

            if (tracker == null)
            {
                using (service.DisableRefresh())
                {
                    ClearUI();
                }

                return;
            }

            Func <IEnumerable <GitFile> > getChangedFiles = () =>
            {
                Action action = () => ShowStatusMessage("Getting changed files ...");
                Dispatcher.Invoke(action);
                return(tracker.ChangedFiles);
            };

            Action <IEnumerable <GitFile> > refreshAction = changedFiles =>
            {
                using (service.DisableRefresh())
                {
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();

                    var selectedFile  = GetSelectedFileName();
                    var selectedFiles = this.listView1.Items.Cast <GitFile>()
                                        .Where(i => i.IsSelected)
                                        .Select(i => i.FileName).ToList();

                    this.listView1.BeginInit();

                    try
                    {
                        this.listView1.ItemsSource = changedFiles;

                        SortCurrentColumn();

                        this.listView1.SelectedValue = selectedFile;
                        selectedFiles.ForEach(fn =>
                        {
                            var item = this.listView1.Items.Cast <GitFile>()
                                       .Where(i => i.FileName == fn)
                                       .FirstOrDefault();
                            if (item != null)
                            {
                                item.IsSelected = true;
                            }
                        });

                        ShowStatusMessage("");

                        var changed = changedFiles;
                        this.label3.Content = string.Format("Changed files (+{0} ~{1} -{2} !{3})",
                                                            changed.Where(f => f.Status == GitFileStatus.New || f.Status == GitFileStatus.Added).Count(),
                                                            changed.Where(f => f.Status == GitFileStatus.Modified || f.Status == GitFileStatus.Staged).Count(),
                                                            changed.Where(f => f.Status == GitFileStatus.Deleted || f.Status == GitFileStatus.Removed).Count(),
                                                            changed.Where(f => f.Status == GitFileStatus.Conflict).Count());

                        if (!changedFiles.Any())
                        {
                            this.ClearEditor();
                        }
                    }
                    catch (Exception ex)
                    {
                        ShowStatusMessage(ex.Message);
                    }
                    this.listView1.EndInit();

                    stopwatch.Stop();
                    Debug.WriteLine("**** PendingChangesView Refresh: " + stopwatch.ElapsedMilliseconds);

                    if (!GitSccOptions.Current.DisableAutoRefresh && stopwatch.ElapsedMilliseconds > 1000)
                    {
                        this.label4.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        this.label4.Visibility = Visibility.Collapsed;
                    }
                }
            };

            Action <Task <IEnumerable <GitFile> > > continuationAction = task =>
            {
                Dispatcher.Invoke(refreshAction, task.Result);
            };

            Task.Factory.StartNew(getChangedFiles, CancellationToken.None, TaskCreationOptions.LongRunning, SccProviderService.TaskScheduler)
            .HandleNonCriticalExceptions()
            .ContinueWith(continuationAction, TaskContinuationOptions.ExecuteSynchronously)
            .HandleNonCriticalExceptions();
        }
        internal void Refresh(GitFileStatusTracker tracker)
        {
            this.tracker = tracker;

            if (!GitBash.Exists)
            {
                Settings.Show();
                return;
            }
            else
            {
                Settings.Hide();
            }

            if (tracker == null)
            {
                service.NoRefresh = true;
                ClearUI();
                service.NoRefresh = false;
                return;
            }

            Action act = () =>
            {
                service.NoRefresh = true;
                ShowStatusMessage("Getting changed files ...");

                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();

                var selectedFile  = GetSelectedFileName();
                var selectedFiles = this.dataGrid1.Items.Cast <GitFile>()
                                    .Where(i => i.IsSelected)
                                    .Select(i => i.FileName).ToList();

                this.dataGrid1.BeginInit();

                try
                {
                    this.dataGrid1.ItemsSource = tracker.ChangedFiles;

                    ICollectionView view = CollectionViewSource.GetDefaultView(this.dataGrid1.ItemsSource);
                    if (view != null)
                    {
                        view.SortDescriptions.Clear();
                        view.SortDescriptions.Add(new SortDescription(sortMemberPath, sortDirection));
                        view.Refresh();
                    }

                    this.dataGrid1.SelectedValue = selectedFile;
                    selectedFiles.ForEach(fn => {
                        var item = this.dataGrid1.Items.Cast <GitFile>()
                                   .Where(i => i.FileName == fn)
                                   .FirstOrDefault();
                        if (item != null)
                        {
                            item.IsSelected = true;
                        }
                    });

                    ShowStatusMessage("");
                }
                catch (Exception ex)
                {
                    ShowStatusMessage(ex.Message);
                }
                this.dataGrid1.EndInit();

                stopwatch.Stop();
                Debug.WriteLine("**** PendingChangesView Refresh: " + stopwatch.ElapsedMilliseconds);

                if (!GitSccOptions.Current.DisableAutoRefresh && stopwatch.ElapsedMilliseconds > 1000)
                {
                    this.label4.Visibility = Visibility.Visible;
                }
                else
                {
                    this.label4.Visibility = Visibility.Collapsed;
                }

                service.NoRefresh       = false;
                service.lastTimeRefresh = DateTime.Now; //important!!
            };

            this.Dispatcher.BeginInvoke(act, DispatcherPriority.ApplicationIdle);
        }
 private void FireActiveTrackerChangedEvent(GitFileStatusTracker repository)
 {
     var eventArgs = new GitRepositoryEvent(repository);
     _onActiveTrackerUpdateEventHandler?.Invoke(this, eventArgs);
 }
        public void GetFileContentTest()
        {
            GitFileStatusTracker.Init(tempFolder);
            File.WriteAllLines(tempFile, lines);

            GitFileStatusTracker tracker = new GitFileStatusTracker(tempFolder);
            tracker.StageFile(tempFile);
            tracker.Commit("test");

            var fileContent = tracker.GetFileContent(tempFile);

            using (var binWriter = new BinaryWriter(File.Open(tempFile + ".bk", System.IO.FileMode.Create)))
            {
                binWriter.Write(fileContent);
            }

            var newlines = File.ReadAllLines(tempFile + ".bk");
            Assert.AreEqual(lines[0], newlines[0]);
            Assert.AreEqual(lines[1], newlines[1]);
            Assert.AreEqual(lines[2], newlines[2]);
        }
        public void SaveFileFromRepositoryTest()
        {
            GitFileStatusTracker.Init(tempFolder);
            File.WriteAllLines(tempFile, lines);

            GitFileStatusTracker tracker = new GitFileStatusTracker(tempFolder);
            tracker.StageFile(tempFile);
            tracker.Commit("test");

            tracker.SaveFileFromRepository(tempFile, tempFile + ".bk");
            var newlines = File.ReadAllLines(tempFile + ".bk");
            Assert.AreEqual(lines[0], newlines[0]);
            Assert.AreEqual(lines[1], newlines[1]);
            Assert.AreEqual(lines[2], newlines[2]);
        }
        public void GetFileStatusTest()
        {
            GitFileStatusTracker.Init(tempFolder);
            GitFileStatusTracker tracker = new GitFileStatusTracker(tempFolder);

            File.WriteAllLines(tempFile, lines);
            Assert.AreEqual(GitFileStatus.New, tracker.GetFileStatus(tempFile));

            tracker.StageFile(tempFile);
            Assert.AreEqual(GitFileStatus.Added, tracker.GetFileStatus(tempFile));

            tracker.UnStageFile(tempFile);
            Assert.AreEqual(GitFileStatus.New, tracker.GetFileStatus(tempFile));

            tracker.StageFile(tempFile);
            Assert.AreEqual(GitFileStatus.Added, tracker.GetFileStatus(tempFile));

            tracker.Commit("test commit");
            Assert.AreEqual(GitFileStatus.Tracked, tracker.GetFileStatus(tempFile));

            File.WriteAllText(tempFile, "changed text");
            tracker.Refresh();
            Assert.AreEqual(GitFileStatus.Modified, tracker.GetFileStatus(tempFile));

            tracker.StageFile(tempFile);
            Assert.AreEqual(GitFileStatus.Staged, tracker.GetFileStatus(tempFile));

            tracker.UnStageFile(tempFile);
            Assert.AreEqual(GitFileStatus.Modified, tracker.GetFileStatus(tempFile));

            File.Delete(tempFile);
            tracker.Refresh();
            Assert.AreEqual(GitFileStatus.Deleted, tracker.GetFileStatus(tempFile));

            tracker.StageFile(tempFile);
            Assert.AreEqual(GitFileStatus.Removed, tracker.GetFileStatus(tempFile));

            tracker.UnStageFile(tempFile);
            Assert.AreEqual(GitFileStatus.Deleted, tracker.GetFileStatus(tempFile));
        }
 public FileStatusTracker(string directory)
 {
     tracker = new GitFileStatusTracker(directory);
 }
Beispiel #42
0
        internal void Refresh(GitFileStatusTracker tracker)
        {
            this.tracker = tracker;

            if (tracker == null)
            {
                service.NoRefresh = true;
                ClearUI();
                service.NoRefresh = false;
                return;
            }

            //double delta = DateTime.Now.Subtract(lastTimeRefresh).TotalMilliseconds;
            //if (delta < 1000) return; //no refresh within 1 second
            //Debug.WriteLine("==== Pending Changes Refresh {0}", delta);

            var    dispatcher = Dispatcher.CurrentDispatcher;
            Action act        = () =>
            {
                service.NoRefresh = true;
                ShowStatusMessage("Getting changed files ...");

                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();

                var selectedFile = GetSelectedFileName();
                this.dataGrid1.BeginInit();

                try
                {
                    this.dataGrid1.ItemsSource = tracker.ChangedFiles;

                    ICollectionView view = CollectionViewSource.GetDefaultView(this.dataGrid1.ItemsSource);
                    if (view != null)
                    {
                        view.SortDescriptions.Clear();
                        view.SortDescriptions.Add(new SortDescription(sortMemberPath, sortDirection));
                        view.Refresh();
                    }

                    this.dataGrid1.SelectedValue = selectedFile;
                    ShowStatusMessage("");
                }
                catch (Exception ex)
                {
                    ShowStatusMessage(ex.Message);
                }
                this.dataGrid1.EndInit();

                stopwatch.Stop();
                Debug.WriteLine("**** PendingChangesView Refresh: " + stopwatch.ElapsedMilliseconds);

                if (!GitSccOptions.Current.DisableAutoRefresh && stopwatch.ElapsedMilliseconds > 1000)
                {
                    this.label4.Visibility = Visibility.Visible;
                }
                else
                {
                    this.label4.Visibility = Visibility.Collapsed;
                }

                service.NoRefresh       = false;
                service.lastTimeRefresh = DateTime.Now; //important!!
            };

            dispatcher.BeginInvoke(act, DispatcherPriority.ApplicationIdle);

            lastTimeRefresh = DateTime.Now;
        }
 public void Close()
 {
     tracker.Dispose();
     tracker = null;
 }
        public void GetChangedFilesTest()
        {
            GitFileStatusTracker.Init(tempFolder);

            File.WriteAllLines(tempFile, lines);

            GitFileStatusTracker tracker = new GitFileStatusTracker(tempFolder);
            Assert.AreEqual(GitFileStatus.New, tracker.ChangedFiles.ToList()[0].Status);

            tracker.StageFile(tempFile);
            Assert.AreEqual(GitFileStatus.Added, tracker.ChangedFiles.ToList()[0].Status);

            tracker.Commit("test");

            Assert.AreEqual(0, tracker.ChangedFiles.Count());

            File.WriteAllText(tempFile, "a");
            tracker.Refresh();
            Assert.AreEqual(GitFileStatus.Modified, tracker.ChangedFiles.ToList()[0].Status);

            tracker.StageFile(tempFile);
            Assert.AreEqual(GitFileStatus.Staged, tracker.ChangedFiles.ToList()[0].Status);
        }
        private void FireOnCommitChangedEvent(GitFileStatusTracker repository)
        {
            var eventArgs = new GitRepositoryEvent(repository);

            _onTrackerCommitChanged?.Invoke(this, eventArgs);
        }