// Copyright (c) 2025 TerraByte Inc.
//
// This script serves as the clean, public-facing API for all Git operations.
// It creates promises and delegates the actual implementation work to the
// internal GitExecutors class.
using System;
using Terra.Arbitrator.Promises;
using Terra.Arbitrator.Settings;
using System.Collections.Generic;
namespace Terra.Arbitrator.Services
{
///
/// The public static API for interacting with the Git repository.
///
public static class GitService
{
///
/// Synchronously gets the Git status for a single file.
/// Required by UI elements that cannot easily use promises.
///
public static GitChange GetChangeForFile(string filePath)
{
return GitExecutors.GetChangeForFile(filePath);
}
///
/// Gets the number of incoming commits from the tracked remote branch.
///
/// A promise that resolves with the number of commits, or null if not tracked.
public static IPromise GetUpstreamAheadBy()
{
return new Promise(GitExecutors.GetUpstreamAheadByExecutor);
}
///
/// Compares the local repository state to the tracked remote branch.
///
public static IPromise> CompareLocalToRemote()
{
return new Promise>(GitExecutors.GetLocalStatusExecutor);
}
///
/// Commits and pushes the selected files to the remote repository.
///
public static IPromise CommitAndPush(List changesToCommit, string commitMessage, string username, string email, Action onProgress = null)
{
return new Promise((resolve, reject) =>
GitExecutors.CommitAndPushExecutor(resolve, reject, changesToCommit, commitMessage, username, email, onProgress));
}
///
/// Reverts all local changes for a single file.
///
public static IPromise ResetFileChanges(GitChange changeToReset)
{
return new Promise((resolve, reject) =>
GitExecutors.ResetFileExecutor(resolve, reject, changeToReset));
}
///
/// Launches an external diff tool to compare file versions.
///
public static IPromise LaunchExternalDiff(GitChange change)
{
return new Promise((resolve, reject) => GitExecutors.LaunchExternalDiffExecutor(resolve, reject, change));
}
///
/// Analyzes if a pull operation results in conflicts.
///
public static IPromise AnalyzePullConflicts()
{
return new Promise(GitExecutors.FileLevelConflictCheckExecutor);
}
///
/// Performs a "safe" pull, assuming no conflicts will occur.
///
public static IPromise PerformSafePull()
{
return new Promise(GitExecutors.SafePullExecutor);
}
///
/// Performs a pull that may result in merge conflicts.
///
public static IPromise ForcePull()
{
return new Promise(GitExecutors.ForcePullExecutor);
}
///
/// Launches an external merge tool for a conflicted file.
///
public static IPromise LaunchMergeTool(GitChange change)
{
return new Promise((resolve, reject) => GitExecutors.LaunchMergeToolExecutor(resolve, reject, change));
}
///
/// Unstages all files if the repository is in a clean, non-conflicted state.
///
public static IPromise UnstageAllFilesIfSafe()
{
return new Promise(GitExecutors.UnstageAllFilesIfSafeExecutor);
}
///
/// Discards all local changes (tracked and untracked) in the repository.
///
public static IPromise ResetAllChanges()
{
return new Promise(GitExecutors.ResetAllChangesExecutor);
}
}
}