Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an undo button to the git panel #24593

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion assets/keymaps/vim.json
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@
}
},
{
"context": "GitPanel || EmptyPane || SharedScreen || MarkdownPreview || KeyContextView || Welcome",
"context": "ChangesList || EmptyPane || SharedScreen || MarkdownPreview || KeyContextView || Welcome",
"bindings": {
":": "command_palette::Toggle",
"g /": "pane::DeploySearch"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ CREATE TABLE "worktree_repositories" (
"scan_id" INTEGER NOT NULL,
"is_deleted" BOOL NOT NULL,
"current_merge_conflicts" VARCHAR,
"branch_summary" VARCHAR,
PRIMARY KEY(project_id, worktree_id, work_directory_id),
FOREIGN KEY(project_id, worktree_id) REFERENCES worktrees (project_id, id) ON DELETE CASCADE,
FOREIGN KEY(project_id, worktree_id, work_directory_id) REFERENCES worktree_entries (project_id, worktree_id, id) ON DELETE CASCADE
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE worktree_repositories
ADD COLUMN worktree_repositories VARCHAR NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE worktree_repositories ADD COLUMN branch_summary TEXT NULL;
40 changes: 30 additions & 10 deletions crates/collab/src/db/queries/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,16 +326,26 @@ impl Database {

if !update.updated_repositories.is_empty() {
worktree_repository::Entity::insert_many(update.updated_repositories.iter().map(
|repository| worktree_repository::ActiveModel {
project_id: ActiveValue::set(project_id),
worktree_id: ActiveValue::set(worktree_id),
work_directory_id: ActiveValue::set(repository.work_directory_id as i64),
scan_id: ActiveValue::set(update.scan_id as i64),
branch: ActiveValue::set(repository.branch.clone()),
is_deleted: ActiveValue::set(false),
current_merge_conflicts: ActiveValue::Set(Some(
serde_json::to_string(&repository.current_merge_conflicts).unwrap(),
)),
|repository| {
worktree_repository::ActiveModel {
project_id: ActiveValue::set(project_id),
worktree_id: ActiveValue::set(worktree_id),
work_directory_id: ActiveValue::set(
repository.work_directory_id as i64,
),
scan_id: ActiveValue::set(update.scan_id as i64),
branch: ActiveValue::set(repository.branch.clone()),
is_deleted: ActiveValue::set(false),
branch_summary: ActiveValue::Set(
repository
.branch_summary
.as_ref()
.map(|summary| serde_json::to_string(summary).unwrap()),
),
current_merge_conflicts: ActiveValue::Set(Some(
serde_json::to_string(&repository.current_merge_conflicts).unwrap(),
)),
}
},
))
.on_conflict(
Expand All @@ -347,6 +357,8 @@ impl Database {
.update_columns([
worktree_repository::Column::ScanId,
worktree_repository::Column::Branch,
worktree_repository::Column::BranchSummary,
worktree_repository::Column::CurrentMergeConflicts,
])
.to_owned(),
)
Expand Down Expand Up @@ -779,6 +791,13 @@ impl Database {
.transpose()?
.unwrap_or_default();

let branch_summary = db_repository_entry
.branch_summary
.as_ref()
.map(|branch_summary| serde_json::from_str(&branch_summary))
.transpose()?
.unwrap_or_default();

worktree.repository_entries.insert(
db_repository_entry.work_directory_id as u64,
proto::RepositoryEntry {
Expand All @@ -787,6 +806,7 @@ impl Database {
updated_statuses,
removed_statuses: Vec::new(),
current_merge_conflicts,
branch_summary,
},
);
}
Expand Down
8 changes: 8 additions & 0 deletions crates/collab/src/db/queries/rooms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,12 +743,20 @@ impl Database {
.transpose()?
.unwrap_or_default();

let branch_summary = db_repository
.branch_summary
.as_ref()
.map(|branch_summary| serde_json::from_str(&branch_summary))
.transpose()?
.unwrap_or_default();

worktree.updated_repositories.push(proto::RepositoryEntry {
work_directory_id: db_repository.work_directory_id as u64,
branch: db_repository.branch,
updated_statuses,
removed_statuses,
current_merge_conflicts,
branch_summary,
});
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/collab/src/db/tables/worktree_repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ pub struct Model {
pub is_deleted: bool,
// JSON array typed string
pub current_merge_conflicts: Option<String>,
// A JSON object representing the current Branch values
pub branch_summary: Option<String>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
Expand Down
2 changes: 2 additions & 0 deletions crates/collab/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,8 @@ impl Server {
.add_request_handler(forward_mutating_project_request::<proto::Stage>)
.add_request_handler(forward_mutating_project_request::<proto::Unstage>)
.add_request_handler(forward_mutating_project_request::<proto::Commit>)
.add_request_handler(forward_read_only_project_request::<proto::GitShow>)
.add_request_handler(forward_read_only_project_request::<proto::GitReset>)
.add_request_handler(forward_mutating_project_request::<proto::OpenCommitMessageBuffer>)
.add_message_handler(broadcast_project_message_from_host::<proto::AdvertiseContexts>)
.add_message_handler(update_context)
Expand Down
9 changes: 6 additions & 3 deletions crates/collab/src/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2895,7 +2895,10 @@ async fn test_git_branch_name(
assert_eq!(worktrees.len(), 1);
let worktree = worktrees[0].clone();
let root_entry = worktree.read(cx).snapshot().root_git_entry().unwrap();
assert_eq!(root_entry.branch(), branch_name.map(Into::into));
assert_eq!(
root_entry.branch().map(|branch| branch.name.to_string()),
branch_name
);
}

// Smoke test branch reading
Expand Down Expand Up @@ -6783,7 +6786,7 @@ async fn test_remote_git_branches(
})
});

assert_eq!(host_branch.as_ref(), branches[2]);
assert_eq!(host_branch.name, branches[2]);

// Also try creating a new branch
cx_b.update(|cx| {
Expand All @@ -6804,5 +6807,5 @@ async fn test_remote_git_branches(
})
});

assert_eq!(host_branch.as_ref(), "totally-new-branch");
assert_eq!(host_branch.name, "totally-new-branch");
}
4 changes: 2 additions & 2 deletions crates/collab/src/tests/remote_editing_collaboration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ async fn test_ssh_collaboration_git_branches(
})
});

assert_eq!(server_branch.as_ref(), branches[2]);
assert_eq!(server_branch.name, branches[2]);

// Also try creating a new branch
cx_b.update(|cx| {
Expand All @@ -337,7 +337,7 @@ async fn test_ssh_collaboration_git_branches(
})
});

assert_eq!(server_branch.as_ref(), "totally-new-branch");
assert_eq!(server_branch.name, "totally-new-branch");
}

#[gpui::test]
Expand Down
1 change: 1 addition & 0 deletions crates/git/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ actions!(
StageAll,
UnstageAll,
RevertAll,
Uncommit,
Commit,
ClearCommitMessage
]
Expand Down
Loading
Loading