Task attempt 47ade56e-79e4-4ee1-a4d1-1504308826ef - Final changes

This commit is contained in:
Louis Knight-Webb
2025-06-24 23:40:48 +01:00
parent 41e3801d84
commit cf2040f889
3 changed files with 20 additions and 21 deletions

View File

@@ -127,6 +127,7 @@ pub struct BranchStatus {
pub up_to_date: bool, pub up_to_date: bool,
pub merged: bool, pub merged: bool,
pub has_uncommitted_changes: bool, pub has_uncommitted_changes: bool,
pub base_branch_name: String,
} }
impl TaskAttempt { impl TaskAttempt {
@@ -252,7 +253,7 @@ impl TaskAttempt {
// Now we need to merge the worktree branch into the main repository // Now we need to merge the worktree branch into the main repository
let branch_name = format!("attempt-{}", attempt_id); let branch_name = format!("attempt-{}", attempt_id);
// Get the main branch (usually "main" or "master") // Get the current base branch name (e.g., "main", "master", "develop", etc.)
let main_branch = main_repo.head()?.shorthand().unwrap_or("main").to_string(); let main_branch = main_repo.head()?.shorthand().unwrap_or("main").to_string();
// Fetch the worktree branch into the main repository // Fetch the worktree branch into the main repository
@@ -273,7 +274,7 @@ impl TaskAttempt {
"Import worktree changes", "Import worktree changes",
)?; )?;
// Now merge the branch into main // Now merge the branch into the base branch
let main_branch_commit = main_repo let main_branch_commit = main_repo
.reference_to_annotated_commit(&main_repo.find_reference(&main_branch_ref)?)?; .reference_to_annotated_commit(&main_repo.find_reference(&main_branch_ref)?)?;
let worktree_branch_commit = main_repo let worktree_branch_commit = main_repo
@@ -1222,7 +1223,10 @@ impl TaskAttempt {
// Open the worktree repository // Open the worktree repository
let worktree_repo = Repository::open(&attempt.worktree_path)?; let worktree_repo = Repository::open(&attempt.worktree_path)?;
// Get the current HEAD of main branch in the main repo // Get the base branch name from the main repository
let base_branch_name = main_repo.head()?.shorthand().unwrap_or("main").to_string();
// Get the current HEAD of base branch in the main repo
let main_head = main_repo.head()?.peel_to_commit()?; let main_head = main_repo.head()?.peel_to_commit()?;
let main_oid = main_head.id(); let main_oid = main_head.id();
@@ -1250,6 +1254,7 @@ impl TaskAttempt {
up_to_date: true, up_to_date: true,
merged: attempt.merge_commit.is_some(), merged: attempt.merge_commit.is_some(),
has_uncommitted_changes, has_uncommitted_changes,
base_branch_name,
}); });
} }
@@ -1274,6 +1279,7 @@ impl TaskAttempt {
up_to_date: commits_behind == 0 && commits_ahead == 0, up_to_date: commits_behind == 0 && commits_ahead == 0,
merged: attempt.merge_commit.is_some(), merged: attempt.merge_commit.is_some(),
has_uncommitted_changes, has_uncommitted_changes,
base_branch_name,
}) })
} }

View File

@@ -50,7 +50,6 @@ export function TaskAttemptComparePage() {
const [error, setError] = useState<string | null>(null); const [error, setError] = useState<string | null>(null);
const [merging, setMerging] = useState(false); const [merging, setMerging] = useState(false);
const [rebasing, setRebasing] = useState(false); const [rebasing, setRebasing] = useState(false);
const [mergeSuccess, setMergeSuccess] = useState(false);
const [rebaseSuccess, setRebaseSuccess] = useState(false); const [rebaseSuccess, setRebaseSuccess] = useState(false);
const [expandedSections, setExpandedSections] = useState<Set<string>>( const [expandedSections, setExpandedSections] = useState<Set<string>>(
new Set() new Set()
@@ -150,7 +149,6 @@ export function TaskAttemptComparePage() {
if (response.ok) { if (response.ok) {
const result: ApiResponse<string> = await response.json(); const result: ApiResponse<string> = await response.json();
if (result.success) { if (result.success) {
setMergeSuccess(true);
// Refetch both diff and branch status to show updated state // Refetch both diff and branch status to show updated state
fetchDiff(); fetchDiff();
fetchBranchStatus(); fetchBranchStatus();
@@ -493,15 +491,15 @@ export function TaskAttemptComparePage() {
{branchStatus.up_to_date ? ( {branchStatus.up_to_date ? (
<span className="text-green-600">Up to date</span> <span className="text-green-600">Up to date</span>
) : branchStatus.is_behind === true ? ( ) : branchStatus.is_behind === true ? (
<span className="text-orange-600"> <span className="text-orange-600">
{branchStatus.commits_behind} commit {branchStatus.commits_behind} commit
{branchStatus.commits_behind !== 1 ? "s" : ""} behind main {branchStatus.commits_behind !== 1 ? "s" : ""} behind {branchStatus.base_branch_name}
</span> </span>
) : ( ) : (
<span className="text-blue-600"> <span className="text-blue-600">
{branchStatus.commits_ahead} commit {branchStatus.commits_ahead} commit
{branchStatus.commits_ahead !== 1 ? "s" : ""} ahead of main {branchStatus.commits_ahead !== 1 ? "s" : ""} ahead of {branchStatus.base_branch_name}
</span> </span>
)} )}
</div> </div>
{branchStatus.has_uncommitted_changes && ( {branchStatus.has_uncommitted_changes && (
@@ -524,11 +522,6 @@ export function TaskAttemptComparePage() {
Branch rebased successfully! Branch rebased successfully!
</div> </div>
)} )}
{mergeSuccess && (
<div className="text-green-600 text-sm">
Changes merged successfully!
</div>
)}
{/* Action Buttons */} {/* Action Buttons */}
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">
@@ -544,7 +537,7 @@ export function TaskAttemptComparePage() {
<RefreshCw <RefreshCw
className={`mr-2 h-4 w-4 ${rebasing ? "animate-spin" : ""}`} className={`mr-2 h-4 w-4 ${rebasing ? "animate-spin" : ""}`}
/> />
{rebasing ? "Rebasing..." : "Rebase onto Main"} {rebasing ? "Rebasing..." : `Rebase onto ${branchStatus.base_branch_name}`}
</Button> </Button>
)} )}
{!branchStatus?.merged && ( {!branchStatus?.merged && (
@@ -762,7 +755,7 @@ export function TaskAttemptComparePage() {
<div className="bg-yellow-50 border border-yellow-200 rounded-md p-3"> <div className="bg-yellow-50 border border-yellow-200 rounded-md p-3">
<p className="text-sm text-yellow-800"> <p className="text-sm text-yellow-800">
<strong>Warning:</strong> The worktree contains uncommitted changes (modified, added, or deleted files) <strong>Warning:</strong> The worktree contains uncommitted changes (modified, added, or deleted files)
that have not been committed to git. These changes will be permanently merged into the main branch. that have not been committed to git. These changes will be permanently merged into the {branchStatus?.base_branch_name || 'base'} branch.
</p> </p>
</div> </div>
</div> </div>

View File

@@ -70,7 +70,7 @@ export type FileDiff = { path: string, chunks: Array<DiffChunk>, };
export type WorktreeDiff = { files: Array<FileDiff>, }; export type WorktreeDiff = { files: Array<FileDiff>, };
export type BranchStatus = { is_behind: boolean, commits_behind: number, commits_ahead: number, up_to_date: boolean, merged: boolean, has_uncommitted_changes: boolean, }; export type BranchStatus = { is_behind: boolean, commits_behind: number, commits_ahead: number, up_to_date: boolean, merged: boolean, has_uncommitted_changes: boolean, base_branch_name: string, };
export type ExecutionProcess = { id: string, task_attempt_id: string, process_type: ExecutionProcessType, executor_type: string | null, status: ExecutionProcessStatus, command: string, args: string | null, working_directory: string, stdout: string | null, stderr: string | null, exit_code: bigint | null, started_at: string, completed_at: string | null, created_at: string, updated_at: string, }; export type ExecutionProcess = { id: string, task_attempt_id: string, process_type: ExecutionProcessType, executor_type: string | null, status: ExecutionProcessStatus, command: string, args: string | null, working_directory: string, stdout: string | null, stderr: string | null, exit_code: bigint | null, started_at: string, completed_at: string | null, created_at: string, updated_at: string, };