public IndexViewModel(IRepository repo) { this.repo = repo; this.refreshCommand = ReactiveCommand.Create(); this.repositoryStatus = this.refreshCommand.Select(u => { return repo.RetrieveStatus(new StatusOptions() { Show = StatusShowOption.IndexAndWorkDir }); }).ToProperty(this, vm => vm.RepositoryStatus); this.statusEntries = this .WhenAny(vm => vm.RepositoryStatus, change => { var status = change.GetValue(); return status.CreateDerivedCollection(s => s, null, null, null, this.refreshCommand); }).ToProperty(this, vm => vm.StatusEntries); var resetSignal = this.WhenAny(vm => vm.StatusEntries, change => { return 0; }); var allEntries = this.WhenAny(vm => vm.StatusEntries, change => change.GetValue()); this.unstagedEntries = allEntries.Select(s => { return s.CreateDerivedCollection(i => i, i => Unstaged(i.State), null, resetSignal); }).ToProperty(this, vm => vm.UnstagedEntries); this.stagedEntries = allEntries.Select(s => { return s.CreateDerivedCollection(i => i, i => Staged(i.State), null, resetSignal); }).ToProperty(this, vm => vm.StagedEntries); }
public Model(IRepository repository) { mRepository = repository; mRevision = new Lazy<string>(() => mRepository.Commits.Count().ToString(CultureInfo.InvariantCulture)); mShortHash = new Lazy<string>(() => mRepository.Commits.Last().Sha.Substring(0, 7)); mBranch = new Lazy<string>(() => mRepository.Head.CanonicalName); mHasLocalChange = new Lazy<string>(() => mRepository.RetrieveStatus().IsDirty.ToString(CultureInfo.InvariantCulture)); #if DEBUG mBuildConfig = "DEBUG"; #else mBuildConfig = "RELEASE"; #endif }
private static void AssertStatus(bool shouldIgnoreCase, FileStatus expectedFileStatus, IRepository repo, string path) { try { Assert.Equal(expectedFileStatus, repo.RetrieveStatus(path)); } catch (ArgumentException) { Assert.False(shouldIgnoreCase); } }
private static IEnumerable<string> RemoveStagedItems(IRepository repository, IEnumerable<string> paths, bool removeFromWorkingDirectory = true, ExplicitPathsOptions explicitPathsOptions = null) { var removed = new List<string>(); using (var changes = repository.Diff.Compare<TreeChanges>(DiffModifiers.IncludeUnmodified | DiffModifiers.IncludeUntracked, paths, explicitPathsOptions)) { var index = repository.Index; foreach (var treeEntryChanges in changes) { var status = repository.RetrieveStatus(treeEntryChanges.Path); switch (treeEntryChanges.Status) { case ChangeKind.Added: case ChangeKind.Deleted: removed.Add(treeEntryChanges.Path); index.Remove(treeEntryChanges.Path); break; case ChangeKind.Unmodified: if (removeFromWorkingDirectory && ( status.HasFlag(FileStatus.ModifiedInIndex) || status.HasFlag(FileStatus.NewInIndex))) { throw new RemoveFromIndexException("Unable to remove file '{0}', as it has changes staged in the index. You can call the Remove() method with removeFromWorkingDirectory=false if you want to remove it from the index only.", treeEntryChanges.Path); } removed.Add(treeEntryChanges.Path); index.Remove(treeEntryChanges.Path); continue; case ChangeKind.Modified: if (status.HasFlag(FileStatus.ModifiedInWorkdir) && status.HasFlag(FileStatus.ModifiedInIndex)) { throw new RemoveFromIndexException("Unable to remove file '{0}', as it has staged content different from both the working directory and the HEAD.", treeEntryChanges.Path); } if (removeFromWorkingDirectory) { throw new RemoveFromIndexException("Unable to remove file '{0}', as it has local modifications. You can call the Remove() method with removeFromWorkingDirectory=false if you want to remove it from the index only.", treeEntryChanges.Path); } removed.Add(treeEntryChanges.Path); index.Remove(treeEntryChanges.Path); continue; default: throw new RemoveFromIndexException("Unable to remove file '{0}'. Its current status is '{1}'.", treeEntryChanges.Path, treeEntryChanges.Status); } } index.Write(); return removed; } }
/// <summary> /// Get a value indicating if there are modifications in the current working directory. /// </summary> private void GitModifications(IRepository repo) { var status = repo.RetrieveStatus(new StatusOptions()); this.gitInfo.Added = status.Added.Count(); this.gitInfo.Missing = status.Missing.Count(); this.gitInfo.Modified = status.Modified.Count(); this.gitInfo.Removed = status.Removed.Count(); this.gitInfo.Staged = status.Staged.Count(); this.gitInfo.Changes = this.gitInfo.Added + this.gitInfo.Missing + this.gitInfo.Modified + this.gitInfo.Removed + this.gitInfo.Staged; this.gitInfo.HasModifications = Convert.ToBoolean(this.gitInfo.Changes); }
private static void FeedTheRepository(IRepository repo) { string fullPath = Touch(repo.Info.WorkingDirectory, "a.txt", "Hello\n"); repo.Stage(fullPath); repo.Commit("Initial commit", Constants.Signature, Constants.Signature); repo.ApplyTag("mytag"); File.AppendAllText(fullPath, "World\n"); repo.Stage(fullPath); Signature shiftedSignature = Constants.Signature.TimeShift(TimeSpan.FromMinutes(1)); repo.Commit("Update file", shiftedSignature, shiftedSignature); repo.CreateBranch("mybranch"); repo.Checkout("mybranch"); Assert.False(repo.RetrieveStatus().IsDirty); }
private static void AssertStage(bool? ignorecase, IRepository repo, string path) { try { repo.Stage(path); Assert.Equal(FileStatus.Added, repo.RetrieveStatus(path)); repo.Reset(); Assert.Equal(FileStatus.Untracked, repo.RetrieveStatus(path)); } catch (ArgumentException) { Assert.False(ignorecase ?? true); } }
private static void AssertStage(bool? ignorecase, IRepository repo, string path) { try { Commands.Stage(repo, path); Assert.Equal(FileStatus.NewInIndex, repo.RetrieveStatus(path)); repo.Index.Replace(repo.Head.Tip); Assert.Equal(FileStatus.NewInWorkdir, repo.RetrieveStatus(path)); } catch (ArgumentException) { Assert.False(ignorecase ?? true); } }
private static Tuple<string, FileStatus> BuildFrom(IRepository repository, string path) { string relativePath = repository.BuildRelativePathFrom(path); return new Tuple<string, FileStatus>(relativePath, repository.RetrieveStatus(relativePath)); }