Remove base commit

This commit is contained in:
Louis Knight-Webb
2025-06-19 21:28:36 -04:00
parent da041545e6
commit 12f471cc58
7 changed files with 53 additions and 112 deletions

View File

@@ -1,6 +1,6 @@
{
"db_name": "SQLite",
"query": "INSERT INTO task_attempts (id, task_id, worktree_path, base_commit, merge_commit, executor, stdout, stderr) \n VALUES ($1, $2, $3, $4, $5, $6, $7, $8) \n RETURNING id as \"id!: Uuid\", task_id as \"task_id!: Uuid\", worktree_path, base_commit, merge_commit, executor, stdout, stderr, created_at as \"created_at!: DateTime<Utc>\", updated_at as \"updated_at!: DateTime<Utc>\"",
"query": "INSERT INTO task_attempts (id, task_id, worktree_path, merge_commit, executor, stdout, stderr) \n VALUES ($1, $2, $3, $4, $5, $6, $7) \n RETURNING id as \"id!: Uuid\", task_id as \"task_id!: Uuid\", worktree_path, merge_commit, executor, stdout, stderr, created_at as \"created_at!: DateTime<Utc>\", updated_at as \"updated_at!: DateTime<Utc>\"",
"describe": {
"columns": [
{
@@ -19,43 +19,38 @@
"type_info": "Text"
},
{
"name": "base_commit",
"name": "merge_commit",
"ordinal": 3,
"type_info": "Text"
},
{
"name": "merge_commit",
"name": "executor",
"ordinal": 4,
"type_info": "Text"
},
{
"name": "executor",
"name": "stdout",
"ordinal": 5,
"type_info": "Text"
},
{
"name": "stdout",
"name": "stderr",
"ordinal": 6,
"type_info": "Text"
},
{
"name": "stderr",
"name": "created_at!: DateTime<Utc>",
"ordinal": 7,
"type_info": "Text"
},
{
"name": "created_at!: DateTime<Utc>",
"ordinal": 8,
"type_info": "Text"
},
{
"name": "updated_at!: DateTime<Utc>",
"ordinal": 9,
"ordinal": 8,
"type_info": "Text"
}
],
"parameters": {
"Right": 8
"Right": 7
},
"nullable": [
true,
@@ -65,10 +60,9 @@
true,
true,
true,
true,
false,
false
]
},
"hash": "bc2603a54513425d0ab6fab1f2f58845650e51b5270c60a428a85f9e219f0ede"
"hash": "32932b7fbc42de6c671d44d5e9a4ec7f73aadf48a482d4a8a9102cb503a9ffb9"
}

View File

@@ -1,6 +1,6 @@
{
"db_name": "SQLite",
"query": "SELECT id as \"id!: Uuid\", task_id as \"task_id!: Uuid\", worktree_path, base_commit, merge_commit, executor, stdout, stderr, created_at as \"created_at!: DateTime<Utc>\", updated_at as \"updated_at!: DateTime<Utc>\"\n FROM task_attempts \n WHERE id = $1",
"query": "SELECT id as \"id!: Uuid\", task_id as \"task_id!: Uuid\", worktree_path, merge_commit, executor, stdout, stderr, created_at as \"created_at!: DateTime<Utc>\", updated_at as \"updated_at!: DateTime<Utc>\"\n FROM task_attempts \n WHERE task_id = $1 \n ORDER BY created_at DESC",
"describe": {
"columns": [
{
@@ -19,38 +19,33 @@
"type_info": "Text"
},
{
"name": "base_commit",
"name": "merge_commit",
"ordinal": 3,
"type_info": "Text"
},
{
"name": "merge_commit",
"name": "executor",
"ordinal": 4,
"type_info": "Text"
},
{
"name": "executor",
"name": "stdout",
"ordinal": 5,
"type_info": "Text"
},
{
"name": "stdout",
"name": "stderr",
"ordinal": 6,
"type_info": "Text"
},
{
"name": "stderr",
"name": "created_at!: DateTime<Utc>",
"ordinal": 7,
"type_info": "Text"
},
{
"name": "created_at!: DateTime<Utc>",
"ordinal": 8,
"type_info": "Text"
},
{
"name": "updated_at!: DateTime<Utc>",
"ordinal": 9,
"ordinal": 8,
"type_info": "Text"
}
],
@@ -65,10 +60,9 @@
true,
true,
true,
true,
false,
false
]
},
"hash": "a58a2bdcf1545b9a854e799a2fbb0ddd843886ecbfb8ff15b82fb4bb6c382e4d"
"hash": "3c109510d6e312b21f74508040a14c4f3c264cc8e53d864473b35e54662e99d5"
}

View File

@@ -1,12 +0,0 @@
{
"db_name": "SQLite",
"query": "UPDATE task_attempts SET base_commit = ?, updated_at = datetime('now') WHERE id = ?",
"describe": {
"columns": [],
"parameters": {
"Right": 2
},
"nullable": []
},
"hash": "501ae2ecc428a7de30055b1b2b195ee772fbcec729bb5f58c5fefe8dadc1c460"
}

View File

@@ -1,6 +1,6 @@
{
"db_name": "SQLite",
"query": "SELECT ta.id as \"id!: Uuid\", ta.task_id as \"task_id!: Uuid\", ta.worktree_path, ta.base_commit, ta.merge_commit, ta.executor, ta.stdout, ta.stderr, ta.created_at as \"created_at!: DateTime<Utc>\", ta.updated_at as \"updated_at!: DateTime<Utc>\"\n FROM task_attempts ta \n JOIN tasks t ON ta.task_id = t.id \n WHERE ta.id = $1 AND t.id = $2 AND t.project_id = $3",
"query": "SELECT ta.id as \"id!: Uuid\", ta.task_id as \"task_id!: Uuid\", ta.worktree_path, ta.merge_commit, ta.executor, ta.stdout, ta.stderr, ta.created_at as \"created_at!: DateTime<Utc>\", ta.updated_at as \"updated_at!: DateTime<Utc>\"\n FROM task_attempts ta \n JOIN tasks t ON ta.task_id = t.id \n WHERE ta.id = $1 AND t.id = $2 AND t.project_id = $3",
"describe": {
"columns": [
{
@@ -19,38 +19,33 @@
"type_info": "Text"
},
{
"name": "base_commit",
"name": "merge_commit",
"ordinal": 3,
"type_info": "Text"
},
{
"name": "merge_commit",
"name": "executor",
"ordinal": 4,
"type_info": "Text"
},
{
"name": "executor",
"name": "stdout",
"ordinal": 5,
"type_info": "Text"
},
{
"name": "stdout",
"name": "stderr",
"ordinal": 6,
"type_info": "Text"
},
{
"name": "stderr",
"name": "created_at!: DateTime<Utc>",
"ordinal": 7,
"type_info": "Text"
},
{
"name": "created_at!: DateTime<Utc>",
"ordinal": 8,
"type_info": "Text"
},
{
"name": "updated_at!: DateTime<Utc>",
"ordinal": 9,
"ordinal": 8,
"type_info": "Text"
}
],
@@ -65,10 +60,9 @@
true,
true,
true,
true,
false,
false
]
},
"hash": "3c39fa95b7cf269831467950e5f873f8e0b93bf512a226ccf4d22d2252d80f1b"
"hash": "6c31a378ab5073e71dea882d4bdbe27c4091b5995f9c214f4e1b1043f6bcfeae"
}

View File

@@ -1,6 +1,6 @@
{
"db_name": "SQLite",
"query": "SELECT id as \"id!: Uuid\", task_id as \"task_id!: Uuid\", worktree_path, base_commit, merge_commit, executor, stdout, stderr, created_at as \"created_at!: DateTime<Utc>\", updated_at as \"updated_at!: DateTime<Utc>\"\n FROM task_attempts \n WHERE task_id = $1 \n ORDER BY created_at DESC",
"query": "SELECT id as \"id!: Uuid\", task_id as \"task_id!: Uuid\", worktree_path, merge_commit, executor, stdout, stderr, created_at as \"created_at!: DateTime<Utc>\", updated_at as \"updated_at!: DateTime<Utc>\"\n FROM task_attempts \n WHERE id = $1",
"describe": {
"columns": [
{
@@ -19,38 +19,33 @@
"type_info": "Text"
},
{
"name": "base_commit",
"name": "merge_commit",
"ordinal": 3,
"type_info": "Text"
},
{
"name": "merge_commit",
"name": "executor",
"ordinal": 4,
"type_info": "Text"
},
{
"name": "executor",
"name": "stdout",
"ordinal": 5,
"type_info": "Text"
},
{
"name": "stdout",
"name": "stderr",
"ordinal": 6,
"type_info": "Text"
},
{
"name": "stderr",
"name": "created_at!: DateTime<Utc>",
"ordinal": 7,
"type_info": "Text"
},
{
"name": "created_at!: DateTime<Utc>",
"ordinal": 8,
"type_info": "Text"
},
{
"name": "updated_at!: DateTime<Utc>",
"ordinal": 9,
"ordinal": 8,
"type_info": "Text"
}
],
@@ -65,10 +60,9 @@
true,
true,
true,
true,
false,
false
]
},
"hash": "1b24e3eeb2782cdb4e5b98a1b82eeba8eb9b51a5b09dde436da6800d29277b1c"
"hash": "ab93108e1b1a983b7d7fe2bce4e37ea6cbd1bf7aa7b802d92e7bc33dab90b933"
}

View File

@@ -25,7 +25,6 @@ CREATE TABLE task_attempts (
id BLOB PRIMARY KEY,
task_id BLOB NOT NULL,
worktree_path TEXT NOT NULL,
base_commit TEXT,
merge_commit TEXT,
executor TEXT,
stdout TEXT,

View File

@@ -69,7 +69,6 @@ pub struct TaskAttempt {
pub id: Uuid,
pub task_id: Uuid, // Foreign key to Task
pub worktree_path: String,
pub base_commit: Option<String>,
pub merge_commit: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub executor: Option<String>, // Name of the executor to use
@@ -84,7 +83,6 @@ pub struct TaskAttempt {
pub struct CreateTaskAttempt {
pub task_id: Uuid,
pub worktree_path: String,
pub base_commit: Option<String>,
pub merge_commit: Option<String>,
pub executor: Option<String>,
}
@@ -93,7 +91,6 @@ pub struct CreateTaskAttempt {
#[ts(export)]
pub struct UpdateTaskAttempt {
pub worktree_path: Option<String>,
pub base_commit: Option<String>,
pub merge_commit: Option<String>,
}
@@ -138,7 +135,7 @@ impl TaskAttempt {
pub async fn find_by_id(pool: &SqlitePool, id: Uuid) -> Result<Option<Self>, sqlx::Error> {
sqlx::query_as!(
TaskAttempt,
r#"SELECT id as "id!: Uuid", task_id as "task_id!: Uuid", worktree_path, base_commit, merge_commit, executor, stdout, stderr, created_at as "created_at!: DateTime<Utc>", updated_at as "updated_at!: DateTime<Utc>"
r#"SELECT id as "id!: Uuid", task_id as "task_id!: Uuid", worktree_path, merge_commit, executor, stdout, stderr, created_at as "created_at!: DateTime<Utc>", updated_at as "updated_at!: DateTime<Utc>"
FROM task_attempts
WHERE id = $1"#,
id
@@ -153,7 +150,7 @@ impl TaskAttempt {
) -> Result<Vec<Self>, sqlx::Error> {
sqlx::query_as!(
TaskAttempt,
r#"SELECT id as "id!: Uuid", task_id as "task_id!: Uuid", worktree_path, base_commit, merge_commit, executor, stdout, stderr, created_at as "created_at!: DateTime<Utc>", updated_at as "updated_at!: DateTime<Utc>"
r#"SELECT id as "id!: Uuid", task_id as "task_id!: Uuid", worktree_path, merge_commit, executor, stdout, stderr, created_at as "created_at!: DateTime<Utc>", updated_at as "updated_at!: DateTime<Utc>"
FROM task_attempts
WHERE task_id = $1
ORDER BY created_at DESC"#,
@@ -182,13 +179,7 @@ impl TaskAttempt {
let repo = Repository::open(&project.git_repo_path)?;
let worktree_path = Path::new(&data.worktree_path);
// Get base commit
let base_commit = {
let head = repo.head()?;
// Peel it to a commit object and grab its ID
let commit = head.peel_to_commit()?;
commit.id().to_string()
};
// We no longer store base_commit in the database - it's retrieved live via git2
// Create the worktree directory if it doesn't exist
if let Some(parent) = worktree_path.parent() {
@@ -203,13 +194,12 @@ impl TaskAttempt {
// Insert the record into the database
Ok(sqlx::query_as!(
TaskAttempt,
r#"INSERT INTO task_attempts (id, task_id, worktree_path, base_commit, merge_commit, executor, stdout, stderr)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
RETURNING id as "id!: Uuid", task_id as "task_id!: Uuid", worktree_path, base_commit, merge_commit, executor, stdout, stderr, created_at as "created_at!: DateTime<Utc>", updated_at as "updated_at!: DateTime<Utc>""#,
r#"INSERT INTO task_attempts (id, task_id, worktree_path, merge_commit, executor, stdout, stderr)
VALUES ($1, $2, $3, $4, $5, $6, $7)
RETURNING id as "id!: Uuid", task_id as "task_id!: Uuid", worktree_path, merge_commit, executor, stdout, stderr, created_at as "created_at!: DateTime<Utc>", updated_at as "updated_at!: DateTime<Utc>""#,
attempt_id,
data.task_id,
data.worktree_path,
base_commit,
data.merge_commit,
data.executor,
None::<String>, // stdout
@@ -412,7 +402,7 @@ impl TaskAttempt {
// Get the task attempt with validation
let attempt = sqlx::query_as!(
TaskAttempt,
r#"SELECT ta.id as "id!: Uuid", ta.task_id as "task_id!: Uuid", ta.worktree_path, ta.base_commit, ta.merge_commit, ta.executor, ta.stdout, ta.stderr, ta.created_at as "created_at!: DateTime<Utc>", ta.updated_at as "updated_at!: DateTime<Utc>"
r#"SELECT ta.id as "id!: Uuid", ta.task_id as "task_id!: Uuid", ta.worktree_path, ta.merge_commit, ta.executor, ta.stdout, ta.stderr, ta.created_at as "created_at!: DateTime<Utc>", ta.updated_at as "updated_at!: DateTime<Utc>"
FROM task_attempts ta
JOIN tasks t ON ta.task_id = t.id
WHERE ta.id = $1 AND t.id = $2 AND t.project_id = $3"#,
@@ -627,7 +617,7 @@ impl TaskAttempt {
// Get the task attempt with validation
let attempt = sqlx::query_as!(
TaskAttempt,
r#"SELECT ta.id as "id!: Uuid", ta.task_id as "task_id!: Uuid", ta.worktree_path, ta.base_commit, ta.merge_commit, ta.executor, ta.stdout, ta.stderr, ta.created_at as "created_at!: DateTime<Utc>", ta.updated_at as "updated_at!: DateTime<Utc>"
r#"SELECT ta.id as "id!: Uuid", ta.task_id as "task_id!: Uuid", ta.worktree_path, ta.merge_commit, ta.executor, ta.stdout, ta.stderr, ta.created_at as "created_at!: DateTime<Utc>", ta.updated_at as "updated_at!: DateTime<Utc>"
FROM task_attempts ta
JOIN tasks t ON ta.task_id = t.id
WHERE ta.id = $1 AND t.id = $2 AND t.project_id = $3"#,
@@ -651,14 +641,14 @@ impl TaskAttempt {
// Open the worktree repository
let worktree_repo = Repository::open(&attempt.worktree_path)?;
// Get the base commit
let base_commit_str = attempt
.base_commit
.ok_or_else(|| TaskAttemptError::Git(GitError::from_str("No base commit found")))?;
let base_oid =
git2::Oid::from_str(&base_commit_str).map_err(|e| TaskAttemptError::Git(e))?;
// Get the project to access the main repository for base commit
let project = Project::find_by_id(pool, project_id)
.await?
.ok_or(TaskAttemptError::ProjectNotFound)?;
// Get the base commit from the main repository (live data)
let main_repo = Repository::open(&project.git_repo_path)?;
let base_oid = main_repo.head()?.peel_to_commit()?.id();
let base_commit = worktree_repo.find_commit(base_oid)?;
let base_tree = base_commit.tree()?;
@@ -748,7 +738,7 @@ impl TaskAttempt {
// Get the task attempt with validation
let attempt = sqlx::query_as!(
TaskAttempt,
r#"SELECT ta.id as "id!: Uuid", ta.task_id as "task_id!: Uuid", ta.worktree_path, ta.base_commit, ta.merge_commit, ta.executor, ta.stdout, ta.stderr, ta.created_at as "created_at!: DateTime<Utc>", ta.updated_at as "updated_at!: DateTime<Utc>"
r#"SELECT ta.id as "id!: Uuid", ta.task_id as "task_id!: Uuid", ta.worktree_path, ta.merge_commit, ta.executor, ta.stdout, ta.stderr, ta.created_at as "created_at!: DateTime<Utc>", ta.updated_at as "updated_at!: DateTime<Utc>"
FROM task_attempts ta
JOIN tasks t ON ta.task_id = t.id
WHERE ta.id = $1 AND t.id = $2 AND t.project_id = $3"#,
@@ -760,10 +750,6 @@ impl TaskAttempt {
.await?
.ok_or(TaskAttemptError::TaskNotFound)?;
let base_commit = git2::Oid::from_str(&attempt.base_commit.ok_or(
TaskAttemptError::GitOutOfSync(anyhow!("Base commit missing")),
)?)?;
// Get the project
let project = Project::find_by_id(pool, project_id)
.await?
@@ -783,7 +769,7 @@ impl TaskAttempt {
let worktree_head = worktree_repo.head()?.peel_to_commit()?;
let worktree_oid = worktree_head.id();
if main_oid == base_commit {
if main_oid == worktree_oid {
// Branches are at the same commit
return Ok(BranchStatus {
is_behind: false,
@@ -876,7 +862,7 @@ impl TaskAttempt {
// 🔟 final check
let final_oid = repo.head()?.peel_to_commit()?.id();
Ok(final_oid.to_string())
Ok(main_oid.to_string())
}
/// Rebase the worktree branch onto main
@@ -889,7 +875,7 @@ impl TaskAttempt {
// Get the task attempt with validation
let attempt = sqlx::query_as!(
TaskAttempt,
r#"SELECT ta.id as "id!: Uuid", ta.task_id as "task_id!: Uuid", ta.worktree_path, ta.base_commit, ta.merge_commit, ta.executor, ta.stdout, ta.stderr, ta.created_at as "created_at!: DateTime<Utc>", ta.updated_at as "updated_at!: DateTime<Utc>"
r#"SELECT ta.id as "id!: Uuid", ta.task_id as "task_id!: Uuid", ta.worktree_path, ta.merge_commit, ta.executor, ta.stdout, ta.stderr, ta.created_at as "created_at!: DateTime<Utc>", ta.updated_at as "updated_at!: DateTime<Utc>"
FROM task_attempts ta
JOIN tasks t ON ta.task_id = t.id
WHERE ta.id = $1 AND t.id = $2 AND t.project_id = $3"#,
@@ -910,15 +896,7 @@ impl TaskAttempt {
let new_base_commit =
Self::perform_rebase_operation(&attempt.worktree_path, &project.git_repo_path)?;
// Update the base_commit in the database
sqlx::query!(
"UPDATE task_attempts SET base_commit = ?, updated_at = datetime('now') WHERE id = ?",
new_base_commit,
attempt_id
)
.execute(pool)
.await?;
// No need to update database as we now get base_commit live from git
Ok(new_base_commit)
}
}