Overview
The Git Repository provides a complete abstraction over Git operations using LibGit2Sharp. It supports commits, branches, remotes, stashing, tagging, and authentication. Interface:IGitRepositoryImplementation:
LibGit2SharpRepositoryNamespace:
Chapi.Domain.Interfaces / Chapi.Infrastructure.Git
Commits
CommitAsync
Creates a new commit with specified files and message.Path to the Git repository
Commit message
Files to stage and commit
Returns commit details including Hash, Message, Author, Date, and RelativeDate
GetCommitsAsync
Retrieves commit history with specified limit.Path to the Git repository
Maximum number of commits to retrieve
Collection of commits with Hash, Message, Description, Author, Date, RelativeDate, and Tags
GetUnpushedCommitsAsync
Gets commits that exist locally but haven’t been pushed to remote.Set of commit hashes that are ahead of the remote branch
Changes
GetChangesAsync
Retrieves all file changes in the working directory.Collection of FileChange objects with FilePath, Status (Added/Modified/Deleted/Renamed), Additions, and Deletions
StageFilesAsync
Stages specified files for commit.UnstageFilesAsync
Unstages previously staged files.DiscardChangesAsync
Discards uncommitted changes.Specific files to discard. If null, discards all changes
Branches
GetBranchesAsync
Retrieves all local and remote branches.List of branch names (local branches and remote branches not tracked locally)
GetCurrentBranchAsync
Gets the name of the current branch.Current branch name, or short SHA if in detached HEAD state
SwitchBranchAsync
Switches to a different branch.Name of branch to switch to (local or remote)
CreateBranchAsync
Creates a new branch.Starting point for the new branch (defaults to current HEAD)
DeleteBranchAsync
Deletes a branch locally and optionally remotely.Force deletion even if branch has unmerged changes
Also delete the branch from remote repository
MergeBranchAsync
Merges a source branch into the current branch.SquashMergeBranchAsync
Performs a squash merge.RebaseBranchAsync
Rebases current branch onto target branch.CheckMergeConflictsAsync
Checks if merging would cause conflicts.ResetAsync
Resets current branch to a specific commit.Reset mode: Soft (keeps changes staged), Mixed (keeps changes unstaged), or Hard (discards all changes)
Remote Operations
PushAsync
Pushes commits to remote repository.Force push (overwrites remote history)
PullAsync
Pulls changes from remote repository.FetchAsync
Fetches changes from remote without merging.GetAheadBehindCountAsync
Gets how many commits ahead/behind the remote branch.GetRemoteUrlAsync
Gets the URL of a remote.SetRemoteUrlAsync
Updates the URL of a remote.Lifecycle
CloneAsync
Clones a remote repository.InitAsync
Initializes a new Git repository.AddRemoteAsync
Adds a new remote.Stash
StashChangesAsync
Stashes current changes.ListStashesAsync
Lists all stashes.StashPopAsync
Applies and removes a stash.StashDropAsync
Removes a stash without applying.StashClearAsync
Removes all stashes.Tags
CreateTagAsync
Creates a new annotated tag.DeleteTagLocalAsync
Deletes a local tag.PushTagAsync
Pushes a tag to remote.GetTagsAsync
Retrieves all tags.Configuration
GetConfigAsync
Gets a configuration value.SetConfigAsync
Sets a configuration value.UnsetConfigAsync
Removes a configuration value.Utilities
IsGitInstalled
Checks if Git is available (always returns true with LibGit2Sharp).HasUpstreamAsync
Checks if a branch has an upstream remote.GetDiffAsync
Gets diff for a specific file.GetFileStatsAsync
Gets addition/deletion statistics for a file.GetMetadataAsync
Gets repository metadata.Includes UserName, UserEmail, RemoteUrl, CurrentBranch, IsDetached, Ahead, Behind, HasUpstream