public override bool Execute() { try { //if (LocalPath == ".") //{ // // User didn't define a Path, find the Git path by expecting this Task to be contained in a Git repo // LocalPath = //} using (var repo = new Repository(LocalPath)) { LastCommitHash = LastCommitShortHash = LastCommitMessage = LastTagName = LastTagMessage = LastTagCommitHash = String.Empty; RevisionCount = 0; Commit commit = null; CommitCollection commits = repo.Commits; if (!String.IsNullOrEmpty(CommitHash)) { // We're looking for a from a particular Commit on back commit = repo.Lookup <Commit>(CommitHash); commits = commits.StartingAt(CommitHash); } else { // We're looking from the most recent Commit commit = repo.Commits.First(); } if (null == commit) { Log.LogError("Can't find a Git Commit with that hash."); return(false); } LastCommitShortHash = GetCommitShortHash(commit); LastCommitHash = commit.Sha; LastCommitMessage = commit.Message; Tag tag = GetMostRecentTagByEnumeration(commits, repo.Tags); if (null != tag) { LastTagName = tag.Annotation.Name; LastTagMessage = tag.Annotation.Message; LastTagCommitHash = tag.Annotation.TargetId.Sha; } } } catch (Exception exception) { Log.LogMessage("StackTrace: " + exception.StackTrace); Log.LogErrorFromException(exception); return(false); } return(true); }
private void UpdateButtonState() { NewCollection.RaiseCanExecuteChanged(); OpenCollection.RaiseCanExecuteChanged(); SaveCollection.RaiseCanExecuteChanged(); EditCollection.RaiseCanExecuteChanged(); DeleteCollection.RaiseCanExecuteChanged(); CommitCollection.RaiseCanExecuteChanged(); ReviewCollection.RaiseCanExecuteChanged(); }
private void UpdateButtonState() { NewCollection.RaiseCanExecuteChanged(); OpenCollection.RaiseCanExecuteChanged(); SaveCollection.RaiseCanExecuteChanged(); EditCollection.RaiseCanExecuteChanged(); DeleteCollection.RaiseCanExecuteChanged(); CommitCollection.RaiseCanExecuteChanged(); ReviewCollection.RaiseCanExecuteChanged(); ViewRecordCommand.RaiseCanExecuteChanged(); //IsSaveVisible = FormArgs == null ? false : FormArgs.HasNoRecords == false && FormArgs.ViewMode != FormMode.DELETEMODE; OnPropertyChanged("IsCommitVisible"); }
public Tag GetMostRecentTagByEnumeration(CommitCollection commits, TagCollection tags) { Tag recentTag = null; foreach (var commit in commits) { // Commits are actually ordered already in reverse chronological order var tag = tags.Where(x => x.Annotation.TargetId.Sha == commit.Sha).FirstOrDefault(); if (tag != null) { recentTag = tag; break; } } return(recentTag); }
/// <summary> /// Cleares the to remove list and add all items from new item to items /// </summary> public void Commit() { var args = new CommitCollectionEventArgs(); CommitCollection?.Invoke(this, args); if (!args.Cancel) { foreach (var newItem in newItems) { items.Add(newItem); } newItems.Clear(); removedItems.Clear(); CollectionCommitted?.Invoke(this, new CollectionCommittedEventArgs()); } }
/// <summary> /// Initializes a new instance of the <see cref = "Repository" /> class. /// <para>For a standard repository, <paramref name="path"/> should point to the ".git" folder. For a bare repository, <paramref name="path"/> should directly point to the repository folder.</para> /// </summary> /// <param name = "path">The path to the git repository to open.</param> public Repository(string path) { Ensure.ArgumentNotNullOrEmptyString(path, "path"); var res = NativeMethods.git_repository_open(out handle, PosixPathHelper.ToPosix(path)); Ensure.Success(res); isBare = NativeMethods.git_repository_is_bare(handle); if (!isBare) { index = new Index(this); } commits = new CommitCollection(this); refs = new ReferenceCollection(this); branches = new BranchCollection(this); tags = new TagCollection(this); }
/// <summary> /// Initializes a new instance of the <see cref = "Repository" /> class. /// <para>For a standard repository, <paramref name="path"/> should point to the ".git" folder. For a bare repository, <paramref name="path"/> should directly point to the repository folder.</para> /// </summary> /// <param name = "path">The path to the git repository to open.</param> public Repository(string path) { Ensure.ArgumentNotNullOrEmptyString(path, "path"); var res = NativeMethods.git_repository_open(out handle, PosixPathHelper.ToPosix(path)); Ensure.Success(res); string normalizedPath = NativeMethods.git_repository_path(handle).MarshallAsString(); string normalizedWorkDir = NativeMethods.git_repository_workdir(handle).MarshallAsString(); Info = new RepositoryInformation(this, normalizedPath, normalizedWorkDir, normalizedWorkDir == null); if (!Info.IsBare) index = new Index(this); commits = new CommitCollection(this); refs = new ReferenceCollection(this); branches = new BranchCollection(this); tags = new TagCollection(this); }
public Tag GetMostRecentTagByEnumeration(CommitCollection commits, TagCollection tags) { Tag recentTag = null; foreach (var commit in commits) { // Commits are actually ordered already in reverse chronological order var tag = tags.Where(x => x.Annotation.TargetId.Sha == commit.Sha).FirstOrDefault(); if (tag != null) { recentTag = tag; break; } } return recentTag; }
/// <summary> /// Called from the Parents getter for lazy loading /// </summary> private void LoadParents() { _parents = new CommitCollection(_parentShas.Count); try { foreach (string parentSha in _parentShas) _parents.Add(Repo.Storage.GetObject<Commit>(parentSha)); } catch (Exception) { // Reset _parents field, otherwise the object would be in an invalid state _parents = null; throw; } }
/// <summary> /// Initializes a new instance of the <see cref = "Repository" /> class, providing ooptional behavioral overrides through <paramref name="options"/> parameter. /// <para>For a standard repository, <paramref name = "path" /> should either point to the ".git" folder or to the working directory. For a bare repository, <paramref name = "path" /> should directly point to the repository folder.</para> /// </summary> /// <param name = "path"> /// The path to the git repository to open, can be either the path to the git directory (for non-bare repositories this /// would be the ".git" folder inside the working directory) or the path to the working directory. /// </param> /// <param name="options"> /// Overrides to the way a repository is opened. /// </param> public Repository(string path, RepositoryOptions options = null) { Ensure.ArgumentNotNullOrEmptyString(path, "path"); Ensure.Success(NativeMethods.git_repository_open(out handle, path)); RegisterForCleanup(handle); bool isBare = NativeMethods.RepositoryStateChecker(handle, NativeMethods.git_repository_is_bare); Func<Index> indexBuilder = () => new Index(this); if (options != null) { bool isWorkDirNull = string.IsNullOrEmpty(options.WorkingDirectoryPath); bool isIndexNull = string.IsNullOrEmpty(options.IndexPath); if (isWorkDirNull && isIndexNull) { throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "At least one member of the {0} instance has to be provided.", typeof(RepositoryOptions).Name)); } if (isBare && (isWorkDirNull ^ isIndexNull)) { throw new ArgumentException("When overriding the opening of a bare repository, both RepositoryOptions.WorkingDirectoryPath an RepositoryOptions.IndexPath have to be provided."); } isBare = false; if (!isIndexNull) { indexBuilder = () => new Index(this, options.IndexPath); } if (!isWorkDirNull) { Ensure.Success(NativeMethods.git_repository_set_workdir(handle, options.WorkingDirectoryPath)); } } if (!isBare) { index = indexBuilder(); } commits = new CommitCollection(this); refs = new ReferenceCollection(this); branches = new BranchCollection(this); tags = new TagCollection(this); info = new Lazy<RepositoryInformation>(() => new RepositoryInformation(this, isBare)); config = new Lazy<Configuration>(() => new Configuration(this)); remotes = new Lazy<RemoteCollection>(() => new RemoteCollection(this)); odb = new Lazy<ObjectDatabase>(() => new ObjectDatabase(this)); diff = new Diff(this); }