public CommitWrapper(LibGit2Sharp.Commit commit) { this.commit = commit; Sha = commit.Sha; MessageShort = commit.MessageShort; Message = commit.Message; Author = commit.Author; Committer = commit.Committer; Tree = (async (i) => commit.Tree); Parents = (async (i) => commit.Parents.Select((p) => new CommitWrapper(p))); }
/// <summary> /// A helper method for listing branches that contain the given commit. /// </summary> /// <param name="repo"></param> /// <param name="commitSha"></param> /// <returns></returns> public static IEnumerable<LibGit2Sharp.Branch> GetBranchesContaininingCommit(LibGit2Sharp.Repository repo, string commitSha) { bool directBranchHasBeenFound = false; foreach (var branch in repo.Branches) { if (branch.Tip.Sha != commitSha) { continue; } directBranchHasBeenFound = true; yield return branch; } if (directBranchHasBeenFound) { yield break; } foreach (var branch in repo.Branches) { var commits = repo.Commits.QueryBy(new LibGit2Sharp.Filter { Since = branch }).Where(c => c.Sha == commitSha); if (commits.Count() == 0) { continue; } yield return branch; } }
public Commit(LibGit2Sharp.Commit original) { Id = original.Id; Message = original.Message; Name = original.Author.Name; Files = original.Tree.Select(t => t.Name).ToList(); }
public Branch(string sourceCanonicalName, LibGit2Sharp.Repository repos) { Debug.Assert(string.IsNullOrEmpty(sourceCanonicalName) == false); Debug.Assert(repos != null); CanonicalName = sourceCanonicalName; _repos = repos; UpdateProps(); }
public Branch(string friendlyName, string canonicalName, bool isRemote, bool isCurrentRepositoryHead, LibGit2Sharp.Branch trackedBranch) { Name = friendlyName; CanonicalName = canonicalName; IsRemote = isRemote; IsCurrentHead = isCurrentRepositoryHead; if (trackedBranch != null && trackedBranch.Tip != null) // make sure the online repo exists { TrackingName = trackedBranch.FriendlyName; } }
/// <summary> /// Reads the version.txt file and returns the <see cref="Version"/> and prerelease tag from it. /// </summary> /// <param name="commit">The commit to read the version file from.</param> /// <param name="repoRelativeProjectDirectory">The directory to consider when searching for the version.txt file.</param> /// <returns>The version information read from the file.</returns> public static SemanticVersion GetVersion(LibGit2Sharp.Commit commit, string repoRelativeProjectDirectory = null) { if (commit == null) { return null; } using (var content = GetVersionFileReader(commit, repoRelativeProjectDirectory)) { return content != null ? ReadVersionFile(content) : null; } }
/// <summary> /// Creates a new tag. /// </summary> /// <param name="repo"></param> /// <param name="tag"></param> /// <returns></returns> public static Tag Create(LibGit2Sharp.Repository repo, LibGit2Sharp.Tag tag) { Tag newTag = new Tag { CanonicalName = tag.CanonicalName, Name = tag.Name, //Annotation = tag.Annotation, IsAnnotated = false, //tag.IsAnnotated, TargetSha = tag.Target.Sha, HasCommitAsTarget = tag.Target.GetType().FullName == "LibGit2Sharp.Commit" }; return newTag; }
/// <summary> /// Reads the version.txt file and returns the <see cref="Version"/> and prerelease tag from it. /// </summary> /// <param name="repo">The repo to read the version file from.</param> /// <param name="repoRelativeProjectDirectory">The directory to consider when searching for the version.txt file.</param> /// <returns>The version information read from the file.</returns> public static VersionOptions GetVersion(LibGit2Sharp.Repository repo, string repoRelativeProjectDirectory = null) { if (repo == null) { return null; } if (!repo.Info.IsBare) { string fullDirectory = Path.Combine(repo.Info.WorkingDirectory, repoRelativeProjectDirectory ?? string.Empty); var workingCopyVersion = GetVersion(fullDirectory); } return GetVersion(repo.Head.Commits.FirstOrDefault(), repoRelativeProjectDirectory); }
/// <summary> /// Reads the version.txt file and returns the <see cref="Version"/> and prerelease tag from it. /// </summary> /// <param name="commit">The commit to read the version file from.</param> /// <param name="repoRelativeProjectDirectory">The directory to consider when searching for the version.txt file.</param> /// <returns>The version information read from the file.</returns> public static VersionOptions GetVersion(LibGit2Sharp.Commit commit, string repoRelativeProjectDirectory = null) { if (commit == null) { return null; } bool json; using (var content = GetVersionFileReader(commit, repoRelativeProjectDirectory, out json)) { return content != null ? TryReadVersionFile(content, json) : null; } }
public NetworkWrapper(LibGit2Sharp.Network network) { this.network = network; Remotes = async (i) => network.Remotes; AddRemote = async (dynamic i) => network.Remotes.Add(i.name.ToString(), i.url.ToString()); RemoveRemote = async (i) => { network.Remotes.Remove(i.ToString()); return null; }; ListReferences = async (i) => { if (i.GetType() == typeof(String)) { return network.ListReferences(i.ToString()); } else { return network.ListReferences(network.Remotes.First(r => r.Name == ((dynamic)i).name)); } }; Fetch = async (dynamic i) => { var remote = network.Remotes[i.remote]; network.Fetch(remote, StaticFetchOptionsWrapper.GenerateFetchOptions(i.options)); return null; }; Pull = async (dynamic i) => { var signature = StaticSignatureWrapper.GenerateSignature(i.signature); var options = StaticPullOptionsWrapper.GeneratePullOptions(i.options); return network.Pull(signature, options); }; Push = async (dynamic i) => { var remote = network.Remotes[i.remote]; var objectish = (string)i.objectish; var destinationSpec = (string)i.destinationSpec; var signature = StaticSignatureWrapper.GenerateSignature(i.signature); var options = StaticPushOptionsWrapper.GeneratePushOptions(i.options); var logMessage = (string)i.logMessage; network.Push(remote, objectish, destinationSpec, options, signature, logMessage); return null; }; }
// private GitOBj _object; public RepositoryNavigator(LibGit2Sharp.IRepository git, Location location = null) { this._git = git; this._location = location; // this._object }
/// <summary> /// Loads branches and commits. /// </summary> /// <param name="repo"></param> private void LoadBranchesAndCommits(LibGit2Sharp.Repository repo) { var dispose = false; if (repo == null) { repo = new LibGit2Sharp.Repository(RepositoryFullPath); dispose = true; } // Small performance boosts. Commits.DisableNotifications(); Branches.DisableNotifications(); // Create commits. Commits.Clear(); List<Commit> commitList = new List<Commit>(); foreach (LibGit2Sharp.Commit commit in repo.Commits.QueryBy(new LibGit2Sharp.Filter { Since = repo.Branches }).Take(CommitsPerPage)) { commitList.Add(Commit.Create(repo, commit, Tags)); } Commits.AddRange(commitList); // Create branches. Branches.Clear(); foreach (LibGit2Sharp.Branch branch in repo.Branches) { Branch b = Branch.Create(this, repo, branch); Branches.Add(b); } // Post-process branches (tips and tracking branches). foreach (Branch branch in Branches) { // Set the HEAD property if it matches. if (repo.Head.Name == branch.Name) { Head = branch; branch.Tip.IsHead = true; } branch.PostProcess(Branches, Commits); } // Post-process commits (commit parents). foreach (Commit commit in Commits) { // Set the HEAD property to a DetachedHead branch if the HEAD matched and it was null. if (Head == null && repo.Head.Tip.Sha == commit.Hash) { Head = new DetachedHead { Tip = commit }; commit.IsHead = true; } commit.PostProcess(Commits, Branches); } // Calculate commit visual positions for each branch tree. foreach (Branch branch in Branches) { RepoUtil.IncrementCommitTreeVisualPositionsRecursively(branch.Tip); } Commits.EnableNotifications(); Branches.EnableNotifications(); if (dispose) repo.Dispose(); }
/// <summary> /// Loads the tags. /// </summary> private void LoadTags(LibGit2Sharp.Repository repo) { var dispose = false; if (repo == null) { repo = new LibGit2Sharp.Repository(RepositoryFullPath); dispose = true; } // Small performance boost. Tags.DisableNotifications(); Tags.Clear(); // Add new tags. foreach (LibGit2Sharp.Tag tag in repo.Tags) { Tag t = Tag.Create(repo, tag); if (t.HasCommitAsTarget) Tags.Add(t); } Tags.EnableNotifications(); if (dispose) repo.Dispose(); }
public void Add(string path, string file, LibGit2Sharp.Mode mode) { _treeDefinition.Add(path, file, mode); }
private Signature GetSignature(LibGit2Sharp.IRepository repo) { return repo.Config.BuildSignature(DateTimeOffset.Now); }
static void GetFilesVersionInfoCore (LibGit2Sharp.Repository repo, GitRevision rev, List<FilePath> localPaths, List<VersionInfo> versions) { foreach (var file in repo.ToGitPath (localPaths)) { var status = repo.RetrieveStatus (file); VersionStatus fstatus = VersionStatus.Versioned; if (status != FileStatus.Unaltered) { if ((status & FileStatus.NewInIndex) != 0) fstatus |= VersionStatus.ScheduledAdd; else if ((status & (FileStatus.DeletedFromIndex | FileStatus.DeletedFromWorkdir)) != 0) fstatus |= VersionStatus.ScheduledDelete; else if ((status & (FileStatus.TypeChangeInWorkdir | FileStatus.ModifiedInWorkdir)) != 0) fstatus |= VersionStatus.Modified; else if ((status & (FileStatus.RenamedInIndex | FileStatus.RenamedInWorkdir)) != 0) fstatus |= VersionStatus.ScheduledReplace; else if ((status & (FileStatus.Nonexistent | FileStatus.NewInWorkdir)) != 0) fstatus = VersionStatus.Unversioned; else if ((status & FileStatus.Ignored) != 0) fstatus = VersionStatus.Ignored; } if (repo.Index.Conflicts [file] != null) fstatus = VersionStatus.Versioned | VersionStatus.Conflicted; versions.Add (new VersionInfo (repo.FromGitPath (file), "", false, fstatus, rev, fstatus == VersionStatus.Ignored ? VersionStatus.Unversioned : VersionStatus.Versioned, null)); } }
public FileStatusEntry(string filePath, LibGit2Sharp.FileStatus fileStatus) :this(filePath) { this.FileStatus = (FileStatus)fileStatus; }
public Commit(LibGit2Sharp.Commit commit) :this(commit.Sha, commit.Author.Name, commit.Message) { }
/// <summary> /// Checks whether the version.txt file is defined in the specified commit. /// </summary> /// <param name="commit">The commit to search.</param> /// <param name="projectDirectory">The directory to consider when searching for the version.txt file.</param> /// <returns><c>true</c> if the version.txt file is found; otherwise <c>false</c>.</returns> public static bool IsVersionDefined(LibGit2Sharp.Commit commit, string projectDirectory = null) { return GetVersion(commit, projectDirectory) != null; }
/// <summary> /// Retrives the tree changes for the given commit. /// </summary> /// <returns></returns> public static LibGit2Sharp.TreeChanges GetTreeChangesForCommit(LibGit2Sharp.Repository repo, Commit commit) { // Retrieve the Tree for this commit. LibGit2Sharp.Tree thisTree = ((LibGit2Sharp.Commit) repo.Lookup(commit.ObjectId)).Tree; // Retrieve the Tree for the previous commit (parent). // TODO: What about Merge commits? LibGit2Sharp.Tree parentTree = ((LibGit2Sharp.Commit) repo.Lookup(commit.Parents.ElementAt(0).ObjectId)).Tree; // Take the diff. return repo.Diff.Compare(parentTree, thisTree); }
/// <summary> /// Loads the tags. /// </summary> private void LoadTags(LibGit2Sharp.Repository repo = null) { var dispose = false; if (repo == null) { repo = new LibGit2Sharp.Repository(RepositoryFullPath); dispose = true; } // Small performance boost. Tags.DisableNotifications(); Tags.Clear(); // Add new tags. foreach (var tag in repo.Tags) { var t = Tag.Create(repo, tag); if (t.HasCommitAsTarget) Tags.Add(t); } // Fire notifications for the Tags collection on the UI thread. Application.Current.Dispatcher.Invoke( DispatcherPriority.Normal, (Action) (() => Tags.EnableNotifications(true)) ); if (dispose) repo.Dispose(); }
static Commit GetHeadCommit (LibGit2Sharp.Repository repository) { return repository.Head.Tip; }
public GitRevision (Repository repo, LibGit2Sharp.Repository gitRepository, Commit commit) : base(repo) { GitRepository = gitRepository; Commit = commit; rev = Commit != null ? Commit.Id.Sha : ""; }
static void GetDirectoryVersionInfoCore (LibGit2Sharp.Repository repo, GitRevision rev, FilePath directory, List<VersionInfo> versions, bool recursive) { var relativePath = repo.ToGitPath (directory); var status = repo.RetrieveStatus (new StatusOptions { PathSpec = relativePath != "." ? new [] { relativePath } : null, IncludeUnaltered = true, }); versions.AddRange (status.Added.Select (s => new VersionInfo ( repo.FromGitPath (s.FilePath), "", false, VersionStatus.Versioned | VersionStatus.ScheduledAdd, rev, VersionStatus.Versioned, null))); versions.AddRange (status.Ignored.Select (s => new VersionInfo ( repo.FromGitPath (s.FilePath), "", false, VersionStatus.Ignored, rev, VersionStatus.Unversioned, null))); versions.AddRange (status.Missing.Select (s => new VersionInfo ( repo.FromGitPath (s.FilePath), "", false, VersionStatus.Versioned | VersionStatus.ScheduledDelete, rev, VersionStatus.Versioned, null))); versions.AddRange (status.Modified.Select (s => new VersionInfo ( repo.FromGitPath (s.FilePath), "", false, VersionStatus.Versioned | VersionStatus.Modified, rev, VersionStatus.Versioned, null))); versions.AddRange (status.Removed.Select (s => new VersionInfo ( repo.FromGitPath (s.FilePath), "", false, VersionStatus.Versioned | VersionStatus.ScheduledDelete, rev, VersionStatus.Versioned, null))); versions.AddRange (status.RenamedInIndex.Select (s => new VersionInfo ( repo.FromGitPath (s.FilePath), "", false, VersionStatus.Versioned | VersionStatus.ScheduledReplace, rev, VersionStatus.Versioned, null))); versions.AddRange (status.RenamedInWorkDir.Select (s => new VersionInfo ( repo.FromGitPath (s.FilePath), "", false, VersionStatus.Versioned | VersionStatus.ScheduledReplace, rev, VersionStatus.Versioned, null))); versions.AddRange (status.Unaltered.Select (s => new VersionInfo ( repo.FromGitPath (s.FilePath), "", false, VersionStatus.Versioned, rev, VersionStatus.Versioned, null))); versions.AddRange (status.Untracked.Select (s => new VersionInfo ( repo.FromGitPath (s.FilePath), "", false, VersionStatus.Unversioned, rev, VersionStatus.Unversioned, null))); foreach (var conflict in repo.Index.Conflicts) { FilePath path = conflict.Ours.Path; if (path.IsChildPathOf (directory)) versions.Add (new VersionInfo ( repo.FromGitPath (path), "", false, VersionStatus.Versioned | VersionStatus.Conflicted, rev, VersionStatus.Versioned, null)); } if (!recursive) versions.RemoveAll (v => v.LocalPath.ParentDirectory != directory); }
/// <summary> /// Compares two commits and returns a list of files that have changed /// </summary> public static TreeChanges CompareCommits (LibGit2Sharp.Repository repo, Commit reference, Commit compared) { return repo.Diff.Compare<TreeChanges> (reference != null ? reference.Tree : null, compared != null ? compared.Tree : null); }
/// <summary> /// Sets colors for branches. Colors are chosen randomly from the list of allowed branch colors. /// </summary> private void SetBranchColors(LibGit2Sharp.BranchCollection branches) { foreach (LibGit2Sharp.Branch branch in branches) { BranchColors.Add(branch.Name, AllowedBranchColors.ElementAt(branchColorIndex++)); if (branchColorIndex == AllowedBranchColors.Count) branchColorIndex = 0; } }
public static TreeChanges GetChangedFiles (LibGit2Sharp.Repository repo, string refRev) { return GitUtil.CompareCommits (repo, repo.Lookup<Commit> (refRev), repo.Head.Tip); }
public GitRevision (Repository repo, LibGit2Sharp.Repository gitRepository, Commit commit, DateTime time, string author, string message) : base(repo, time, author, message) { GitRepository = gitRepository; Commit = commit; rev = Commit != null ? Commit.Id.Sha : ""; }
public ConflictPopup(LibGit2Sharp.Conflict conflict,int index = 0) { this.conflict = conflict; this.index = index; this.opts = new string[] { "ours","theirs"}; }
/// <summary> /// Reads the version.txt file that is in the specified commit. /// </summary> /// <param name="commit">The commit to read the version file from.</param> /// <param name="repoRelativeProjectDirectory">The directory to consider when searching for the version.txt file.</param> /// <returns>A text reader with the content of the version.txt file.</returns> private static TextReader GetVersionFileReader(LibGit2Sharp.Commit commit, string repoRelativeProjectDirectory) { string searchDirectory = repoRelativeProjectDirectory ?? string.Empty; while (searchDirectory != null) { string candidatePath = Path.Combine(searchDirectory, FileName); var versionTxtBlob = commit.Tree[candidatePath]?.Target as LibGit2Sharp.Blob; if (versionTxtBlob != null) { return new StreamReader(versionTxtBlob.GetContentStream()); } searchDirectory = searchDirectory.Length > 0 ? Path.GetDirectoryName(searchDirectory) : null; } return null; }