Overview
The Git Operations use cases provide comprehensive Git functionality including commits, branches, stashing, and remote operations.
CommitChangesUseCase
Commits staged changes to the Git repository.
Request Model
public class CommitRequest
{
public string ProjectPath { get ; set ; } = string . Empty ;
public string Message { get ; set ; } = string . Empty ;
public IEnumerable < string > Files { get ; set ; } = Enumerable . Empty < string >();
}
Method Signature
public async Task < Result < GitCommit >> ExecuteAsync ( CommitRequest request )
The commit request parameters Path to the project repository
Files
IEnumerable<string>
required
List of file paths to commit
Result containing the created commit True if the commit was successful
The created commit object
Error message if the operation failed
Example Usage
var useCase = new CommitChangesUseCase ( gitRepo , notifications );
var request = new CommitRequest
{
ProjectPath = "C: \\ Projects \\ MyApp" ,
Message = "Add user authentication feature" ,
Files = new [] { "src/Auth/Login.cs" , "src/Auth/Register.cs" }
};
var result = await useCase . ExecuteAsync ( request );
if ( result . IsSuccess )
{
Console . WriteLine ( $"Committed: { result . Data . Sha } " );
}
CreateBranchUseCase
Creates a new Git branch.
Method Signature
public async Task < Result > ExecuteAsync (
string projectPath ,
string branchName ,
string ? fromCommitOrBranch = null
)
Path to the project repository
Optional commit SHA or branch name to create from (defaults to HEAD)
Result indicating success or failure
Example Usage
var useCase = new CreateBranchUseCase ( gitRepo , notificationService );
// Create from HEAD
var result = await useCase . ExecuteAsync (
projectPath : "C: \\ Projects \\ MyApp" ,
branchName : "feature/new-feature"
);
// Create from specific branch
var result2 = await useCase . ExecuteAsync (
projectPath : "C: \\ Projects \\ MyApp" ,
branchName : "hotfix/bug-fix" ,
fromCommitOrBranch : "develop"
);
SwitchBranchUseCase
Switches to a different Git branch.
Method Signature
public async Task < Result > ExecuteAsync (
string projectPath ,
string branchName ,
bool stashChanges = false
)
Path to the project repository
Name of the branch to switch to
Whether to automatically stash uncommitted changes before switching
Result indicating success or failure
Example Usage
var useCase = new SwitchBranchUseCase ( gitRepo , notifications );
// Switch without stashing
var result = await useCase . ExecuteAsync (
projectPath : "C: \\ Projects \\ MyApp" ,
branchName : "develop"
);
// Switch with automatic stashing
var result2 = await useCase . ExecuteAsync (
projectPath : "C: \\ Projects \\ MyApp" ,
branchName : "main" ,
stashChanges : true
);
PushChangesUseCase
Pushes local commits to the remote repository.
Method Signature
public async Task < Result > ExecuteAsync ( string projectPath , string branch )
Path to the project repository
Name of the branch to push
Result indicating success or failure
Example Usage
var useCase = new PushChangesUseCase ( gitRepo , notifications );
var result = await useCase . ExecuteAsync (
projectPath : "C: \\ Projects \\ MyApp" ,
branch : "main"
);
if ( result . IsSuccess )
{
Console . WriteLine ( "Changes pushed successfully" );
}
PullChangesUseCase
Pulls changes from the remote repository.
Method Signature
public async Task < Result > ExecuteAsync ( string projectPath )
Path to the project repository
Result indicating success or failure
LoadChangesUseCase
Loads the current working directory changes.
Method Signature
public async Task < IEnumerable < FileChange >> ExecuteAsync ( string projectPath )
Path to the project repository
Collection of file changes
FileChange Entity
public class FileChange
{
public string FilePath { get ; set ; }
public ChangeStatus Status { get ; set ; }
public int Additions { get ; set ; }
public int Deletions { get ; set ; }
}
public enum ChangeStatus
{
Modified ,
Added ,
Deleted ,
Renamed ,
Untracked ,
Conflict
}
Example Usage
var useCase = new LoadChangesUseCase ( gitRepo );
var changes = await useCase . ExecuteAsync ( "C: \\ Projects \\ MyApp" );
foreach ( var change in changes )
{
Console . WriteLine ( $" { change . Status } : { change . FilePath } " );
Console . WriteLine ( $" + { change . Additions } - { change . Deletions } " );
}
StashChangesUseCase
Stashes uncommitted changes.
Method Signature
public async Task < Result > ExecuteAsync (
string projectPath ,
string message ,
IEnumerable < string >? files = null
)
Path to the project repository
Message describing the stash
Optional list of specific files to stash (null = all changes)
Result indicating success or failure
Example Usage
var useCase = new StashChangesUseCase ( gitRepo , notificationService );
// Stash all changes
var result = await useCase . ExecuteAsync (
projectPath : "C: \\ Projects \\ MyApp" ,
message : "WIP: Working on authentication"
);
// Stash specific files
var result2 = await useCase . ExecuteAsync (
projectPath : "C: \\ Projects \\ MyApp" ,
message : "Save config changes" ,
files : new [] { "appsettings.json" }
);
StashPopUseCase
Applies and removes the most recent stash.
Method Signature
public async Task < Result > ExecuteAsync ( string projectPath , int index = 0 )
Path to the project repository
Index of the stash to pop (0 = most recent)
CreateTagUseCase
Creates a Git tag.
Method Signature
public async Task < Result > ExecuteAsync (
string projectPath ,
string tagName ,
string message = null
)
Path to the project repository
Name of the tag (e.g., “v1.0.0”)
Optional tag message (creates annotated tag if provided)
Example Usage
var useCase = new CreateTagUseCase ( gitRepo );
var result = await useCase . ExecuteAsync (
projectPath : "C: \\ Projects \\ MyApp" ,
tagName : "v1.0.0" ,
message : "Release version 1.0.0"
);
LoadHistoryUseCase
Loads the commit history of the repository.
Method Signature
public async Task < IEnumerable < GitCommit >> ExecuteAsync (
string projectPath ,
int maxCount = 100
)
Path to the project repository
Maximum number of commits to retrieve
Example Usage
var useCase = new LoadHistoryUseCase ( gitRepo );
var commits = await useCase . ExecuteAsync (
projectPath : "C: \\ Projects \\ MyApp" ,
maxCount : 50
);
foreach ( var commit in commits )
{
Console . WriteLine ( $" { commit . Sha . Substring ( 0 , 7 )} - { commit . Message } " );
}
FetchChangesUseCase
Fetches changes from the remote repository without merging.
Method Signature
public async Task < Result > ExecuteAsync ( string projectPath , bool isSilent = false )
Path to the project repository
If true, suppresses notifications
Example Usage
var useCase = new FetchChangesUseCase ( gitRepo , notifications );
var result = await useCase . ExecuteAsync ( "C: \\ Projects \\ MyApp" );
if ( result . IsSuccess )
{
Console . WriteLine ( "Fetch completed successfully" );
}
Source: FetchChangesUseCase.cs:21-42
DiscardChangesUseCase
Discards uncommitted changes in specific files or all files.
Method Signature
public async Task < Result > ExecuteAsync (
string projectPath ,
IEnumerable < string >? files = null
)
Path to the project repository
Specific files to discard changes from. If null or empty, discards all changes.
Example Usage
// Discard changes in specific files
var useCase = new DiscardChangesUseCase ( gitRepo , notifications );
var files = new [] { "src/Program.cs" , "README.md" };
await useCase . ExecuteAsync ( "C: \\ Projects \\ MyApp" , files );
// Discard all changes
await useCase . ExecuteAsync ( "C: \\ Projects \\ MyApp" , null );
This operation is irreversible. Discarded changes cannot be recovered.
ResetCommitUseCase
Resets (undoes) the last commit with different reset modes.
Method Signature
public async Task < Result > ExecuteAsync (
string projectPath ,
ResetMode mode = ResetMode . Soft
)
Path to the project repository
Reset mode determining what happens to changes
Soft : Keeps changes in staging area
Mixed : Keeps changes in working directory (unstaged)
Hard : Discards all changes permanently
Example Usage
var useCase = new ResetCommitUseCase ( gitRepo , notifications );
// Soft reset - keep changes staged
await useCase . ExecuteAsync ( "C: \\ Projects \\ MyApp" , ResetMode . Soft );
// Hard reset - discard all changes
await useCase . ExecuteAsync ( "C: \\ Projects \\ MyApp" , ResetMode . Hard );
Hard reset is destructive : Using ResetMode.Hard permanently discards all changes from the last commit. Use with caution.
StashClearUseCase
Clears all stashed changes from the stash list.
Method Signature
public async Task < Result > ExecuteAsync ( string projectPath )
Path to the project repository
This operation permanently removes all stashed changes. This cannot be undone.
StashDropUseCase
Drops (removes) a specific stash entry.
Method Signature
public async Task < Result > ExecuteAsync ( string projectPath , int stashIndex = 0 )
Path to the project repository
Index of the stash to drop (0 is the most recent)
Example Usage
var useCase = new StashDropUseCase ( gitRepo , notifications );
// Drop the most recent stash
await useCase . ExecuteAsync ( "C: \\ Projects \\ MyApp" , 0 );
// Drop a specific stash by index
await useCase . ExecuteAsync ( "C: \\ Projects \\ MyApp" , 2 );
DeleteTagUseCase
Deletes a Git tag from the repository.
Method Signature
public async Task < Result > ExecuteAsync ( string projectPath , string tagName )
Path to the project repository
Name of the tag to delete
Example Usage
var useCase = new DeleteTagUseCase ( gitRepo , notifications );
await useCase . ExecuteAsync ( "C: \\ Projects \\ MyApp" , "v1.0.0-beta" );
GetBranchesUseCase
Retrieves all branches in the repository.
Method Signature
public async Task < IEnumerable < string >> ExecuteAsync ( string projectPath )
Path to the project repository
Example Usage
var useCase = new GetBranchesUseCase ( gitRepo );
var branches = await useCase . ExecuteAsync ( "C: \\ Projects \\ MyApp" );
foreach ( var branch in branches )
{
Console . WriteLine ( branch );
}