дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 17:47:08 +02:00
feat(svn): shelf, working copy information, menu name and stripe position (#7478)
Subversion requests from #7433: - Shelve, Shelve Silently, Unshelve and the Shelf tab work in Subversion working copies. Shelve saves `svn diff --git --show-copies-as-adds` of the selection and rolls the files back, refusing when the files changed since the patch was taken; Unshelve applies it with `svn patch` and reports rejected or skipped files as conflicts. Unversioned or conflicted files, binary files an older svn cannot put in a patch, non-UTF-8 text and selections across working copies are refused before anything is reverted. Stash stays Git-only. - A Subversion Working Copies Information tab lists every working copy with its URL, repository root, revision, depth and format, with Show Log, Update Project, Cleanup and Relocate for each. - The version control menu is named SVN for a Subversion project and VCS for a project with several systems. - The version control tool window button is last in the bottom stripe group. Co-authored-by: wildcatDownstairs <[email protected]>
Цей коміт міститься в:
1 джерело
8aacedf5ad
коміт
a8db175c25
38 files changed
+1018
-45
No files matched your search
@@ -75,13 +75,18 @@ pub async fn svn_unlock(host: &Host, window: &str, paths: Vec<PathBuf>, force: b
|
||||
.await
|
||||
}
|
||||
|
||||
/// Where a working copy points: VCS › Subversion › Relocate shows the current URL.
|
||||
/// Where a working copy points (VCS › Subversion › Relocate shows the current URL), and what
|
||||
/// the Working Copies tab shows of it.
|
||||
#[derive(Serialize, Deserialize, Type)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SvnRepositoryInfo {
|
||||
pub url: String,
|
||||
pub root_url: String,
|
||||
pub uuid: String,
|
||||
pub revision: Option<u32>,
|
||||
pub depth: String,
|
||||
/// The oldest svn release that reads the working copy (`1.8`); `None` before svn 1.15.
|
||||
pub format: Option<String>,
|
||||
}
|
||||
|
||||
#[command(trust = trusted)]
|
||||
@@ -93,7 +98,10 @@ pub async fn svn_repository_info(host: &Host, window: &str, repo: Option<PathBuf
|
||||
Ok(SvnRepositoryInfo {
|
||||
url: r.url,
|
||||
root_url: r.root_url,
|
||||
uuid: r.uuid,
|
||||
revision: r.revision.and_then(|r| u32::try_from(r).ok()),
|
||||
depth: r.depth,
|
||||
format: r.format,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -3295,11 +3295,14 @@ pub async fn vcs_shelve(host: &Host, window: &str, name: String, paths: Vec<Path
|
||||
host.require_trust(window)?;
|
||||
let project = host.project(window)?;
|
||||
blocking(move || {
|
||||
let shelf = shelf_dir(&project.root);
|
||||
if let Some(backend) = paths.iter().find_map(|path| project.backend_of(path)) {
|
||||
return shelve_working_copy(&project, backend.as_ref(), &shelf, &name, &paths);
|
||||
}
|
||||
let groups = project.repos().group(&paths);
|
||||
if groups.is_empty() || groups.iter().map(|(_, selected)| selected.len()).sum::<usize>() != paths.len() {
|
||||
return Err(ide_core::IdeError::invalid("select files in a git repository to shelve"));
|
||||
}
|
||||
let shelf = shelf_dir(&project.root);
|
||||
if let [(repo, selected)] = groups.as_slice() {
|
||||
keep_private(&project.root);
|
||||
return project
|
||||
@@ -3325,6 +3328,40 @@ pub async fn vcs_shelve(host: &Host, window: &str, name: String, paths: Vec<Path
|
||||
.await
|
||||
}
|
||||
|
||||
/// Shelve Changes in a Subversion working copy: the patch goes on the shelf, then the files
|
||||
/// are rolled back. Files of other working copies or Git repositories are shelved on their own.
|
||||
fn shelve_working_copy(
|
||||
project: &Project,
|
||||
backend: &dyn Backend,
|
||||
shelf: &Path,
|
||||
name: &str,
|
||||
paths: &[PathBuf],
|
||||
) -> IdeResult<ShelvedChangeList> {
|
||||
let wc = crate::ops::svn::as_svn(backend)
|
||||
.ok_or_else(|| ide_core::IdeError::invalid("Shelve Changes is available for Git and Subversion only"))?;
|
||||
if paths.iter().any(|path| project.backend_of(path).is_none_or(|other| other.root() != wc.root())) {
|
||||
return Err(ide_core::IdeError::invalid(
|
||||
"select files of one Subversion working copy to shelve; shelve the others separately",
|
||||
));
|
||||
}
|
||||
let patch = wc.shelf_patch(paths)?;
|
||||
keep_private(&project.root);
|
||||
let entry = ide_vcs::shelf::save(shelf, name, wc.root(), backend.head_label(), &patch)?;
|
||||
project.backend_recorded(backend, Some("Shelve"), |_| wc.shelf_revert(paths, &patch))?;
|
||||
project.vcs_changed();
|
||||
Ok(entry)
|
||||
}
|
||||
|
||||
/// The Subversion working copy a shelved selection was made in, if it was.
|
||||
fn shelved_working_copy(
|
||||
project: &Project,
|
||||
selection: &ide_vcs::shelf::ShelfSelection,
|
||||
) -> Option<std::sync::Arc<dyn Backend>> {
|
||||
project
|
||||
.backend_at(Some(selection.repo.as_deref()?))
|
||||
.filter(|backend| crate::ops::svn::as_svn(backend.as_ref()).is_some())
|
||||
}
|
||||
|
||||
#[command(trust = always)]
|
||||
pub async fn vcs_shelves(host: &Host, window: &str) -> IdeResult<Vec<ShelvedChangeList>> {
|
||||
let project = host.project(window)?;
|
||||
@@ -3356,13 +3393,25 @@ pub async fn vcs_unshelve(
|
||||
blocking(move || {
|
||||
let shelf = shelf_dir(&project.root);
|
||||
let selections = ide_vcs::shelf::selections(&shelf, &id, path.as_deref())?;
|
||||
for selection in &selections {
|
||||
project.with_repo_at(selection.repo.as_deref(), |_| Ok(()))?;
|
||||
let working_copies: Vec<_> =
|
||||
selections.iter().map(|selection| shelved_working_copy(&project, selection)).collect();
|
||||
for (selection, wc) in selections.iter().zip(&working_copies) {
|
||||
if wc.is_none() {
|
||||
project.with_repo_at(selection.repo.as_deref(), |_| Ok(()))?;
|
||||
}
|
||||
}
|
||||
let mut result = ApplyOutcome { applied: Vec::new(), conflicts: Vec::new() };
|
||||
for selection in &selections {
|
||||
let outcome =
|
||||
project.with_repo_recorded(selection.repo.as_deref(), Some("Unshelve"), |r| selection.apply(r))?;
|
||||
for (selection, wc) in selections.iter().zip(&working_copies) {
|
||||
let outcome = match wc {
|
||||
Some(backend) => project.backend_recorded(backend.as_ref(), Some("Unshelve"), |b| {
|
||||
let wc = crate::ops::svn::as_svn(b)
|
||||
.ok_or_else(|| ide_core::IdeError::invalid("not a Subversion working copy"))?;
|
||||
wc.unshelve(selection.patch())
|
||||
})?,
|
||||
None => {
|
||||
project.with_repo_recorded(selection.repo.as_deref(), Some("Unshelve"), |r| selection.apply(r))?
|
||||
}
|
||||
};
|
||||
if remove && outcome.conflicts.is_empty() {
|
||||
ide_vcs::shelf::delete_paths(&shelf, &id, &outcome.applied)?;
|
||||
}
|
||||
@@ -3417,6 +3466,16 @@ pub async fn vcs_shelf_diff(host: &Host, window: &str, id: String) -> IdeResult<
|
||||
let shelf = shelf_dir(&project.root);
|
||||
let mut files = Vec::new();
|
||||
for selection in ide_vcs::shelf::selections(&shelf, &id, None)? {
|
||||
if let Some(backend) = shelved_working_copy(&project, &selection) {
|
||||
// The base each file had: the shelved hunks were made against it. A folder's
|
||||
// change is its properties, which the patch shows.
|
||||
let root = backend.root().to_path_buf();
|
||||
files.extend(selection.diff_files_on(|path| match root.join(path) {
|
||||
path if path.is_dir() => Ok(None),
|
||||
path => backend.file_bytes_at(&path, Some("BASE")),
|
||||
}));
|
||||
continue;
|
||||
}
|
||||
files.extend(project.with_repo_at(selection.repo.as_deref(), |r| selection.diff_files(r))?);
|
||||
}
|
||||
Ok(files)
|
||||
|
||||
@@ -217,6 +217,10 @@ async fn a_working_copy_through_the_shared_commands() {
|
||||
svn::svn_unlock(&host, "main", vec![a.clone()], false).await.unwrap();
|
||||
let info = svn::svn_repository_info(&host, "main", None).await.unwrap();
|
||||
assert!(info.url.ends_with("/repo/trunk"), "{}", info.url);
|
||||
// What the Working Copies tab shows (issue #7433).
|
||||
assert!(info.root_url.ends_with("/repo") && !info.uuid.is_empty(), "{} {}", info.root_url, info.uuid);
|
||||
assert_eq!(info.depth, "infinity");
|
||||
assert!(info.format.is_none() || info.format.as_deref().is_some_and(|f| f.starts_with("1.")), "{:?}", info.format);
|
||||
svn::svn_cleanup(&host, "main", None).await.unwrap();
|
||||
assert!(svn::svn_version(&host, "main", String::new()).await.unwrap().version.is_some());
|
||||
let fresh = fx.base.join("fresh");
|
||||
@@ -939,3 +943,108 @@ async fn a_project_tree_move_and_its_undo_reach_the_working_copy() {
|
||||
assert!(root.join("a.txt").is_file());
|
||||
assert_eq!(fx.svn(&root, &["status"]), "", "back as committed");
|
||||
}
|
||||
|
||||
/// A working copy with `.openidea` (where the shelf is kept) ignored, and committed files.
|
||||
fn shelf_fixture(fx: &Fixture, files: &[(&str, &[u8])]) -> PathBuf {
|
||||
let root = fx.checkout("wc");
|
||||
fx.svn(&root, &["propset", "-q", "svn:ignore", ".openidea", "."]);
|
||||
for (name, bytes) in files {
|
||||
std::fs::write(root.join(name), bytes).unwrap();
|
||||
fx.svn(&root, &["add", "-q", name]);
|
||||
}
|
||||
fx.svn(&root, &["commit", "-q", "-m", "base"]);
|
||||
root
|
||||
}
|
||||
|
||||
/// Issue #7433: Shelve Changes in a Subversion working copy saves text, binary and property
|
||||
/// changes, added and deleted files, and rolls them back; Unshelve puts them back.
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn shelve_and_unshelve_in_a_working_copy() {
|
||||
let Some(fx) = fixture() else { return };
|
||||
let files: &[(&str, &[u8])] =
|
||||
&[("a.txt", b"one\n"), ("gone.txt", b"bye\n"), ("pic.bin", b"\0\x01\x02"), ("prop.txt", b"p\n")];
|
||||
let root = shelf_fixture(&fx, files);
|
||||
let (host, _project) = open(&fx.base, &root).await;
|
||||
let path = |name: &str| root.join(name);
|
||||
std::fs::write(path("a.txt"), "one\ntwo\n").unwrap();
|
||||
std::fs::write(path("new.txt"), "new\n").unwrap();
|
||||
fx.svn(&root, &["add", "-q", "new.txt"]);
|
||||
fx.svn(&root, &["rm", "-q", "gone.txt"]);
|
||||
std::fs::write(path("pic.bin"), b"\0\x03\x04\x05").unwrap();
|
||||
fx.svn(&root, &["propset", "-q", "review", "yes", "prop.txt"]);
|
||||
let changed = fx.svn(&root, &["status"]);
|
||||
|
||||
// An unversioned file is not in the patch: shelving it is refused and nothing is reverted.
|
||||
std::fs::write(path("loose.txt"), "loose\n").unwrap();
|
||||
let refused = vcs::vcs_shelve(&host, "main", "loose".into(), vec![path("a.txt"), path("loose.txt")]).await;
|
||||
assert!(refused.unwrap_err().message.contains("loose.txt"));
|
||||
assert_eq!(std::fs::read_to_string(path("a.txt")).unwrap(), "one\ntwo\n");
|
||||
std::fs::remove_file(path("loose.txt")).unwrap();
|
||||
|
||||
let selected: Vec<PathBuf> = ["a.txt", "new.txt", "gone.txt", "pic.bin", "prop.txt"].map(path).to_vec();
|
||||
let entry = vcs::vcs_shelve(&host, "main", "work".into(), selected).await.unwrap();
|
||||
assert_eq!(fx.svn(&root, &["status"]), "", "rolled back");
|
||||
assert!(!path("new.txt").exists(), "an added file is gone from disk");
|
||||
assert_eq!(std::fs::read_to_string(path("a.txt")).unwrap(), "one\n");
|
||||
assert_eq!(std::fs::read_to_string(path("gone.txt")).unwrap(), "bye\n");
|
||||
assert_eq!(std::fs::read(path("pic.bin")).unwrap(), b"\0\x01\x02");
|
||||
|
||||
let shelves = vcs::vcs_shelves(&host, "main").await.unwrap();
|
||||
assert_eq!(shelves.len(), 1);
|
||||
assert_eq!(shelves[0].repo.as_deref(), Some(root.as_path()));
|
||||
let mut names: Vec<_> = shelves[0].files.iter().map(|f| (f.path.as_str(), f.kind)).collect();
|
||||
names.sort_by_key(|(path, _)| *path);
|
||||
assert_eq!(
|
||||
names,
|
||||
[
|
||||
("a.txt", ChangeKind::Modified),
|
||||
("gone.txt", ChangeKind::Deleted),
|
||||
("new.txt", ChangeKind::Added),
|
||||
("pic.bin", ChangeKind::Modified),
|
||||
("prop.txt", ChangeKind::Modified),
|
||||
]
|
||||
);
|
||||
|
||||
// The shelved diff: the base, and the base with the shelved hunks applied.
|
||||
let diff = vcs::vcs_shelf_diff(&host, "main", entry.id.clone()).await.unwrap();
|
||||
let sides = |name: &str| {
|
||||
let file = diff.iter().find(|f| f.path == name).unwrap();
|
||||
(file.before.clone(), file.after.clone())
|
||||
};
|
||||
assert_eq!(sides("a.txt"), (Some("one\n".into()), Some("one\ntwo\n".into())));
|
||||
assert_eq!(sides("new.txt"), (Some(String::new()), Some("new\n".into())));
|
||||
assert_eq!(sides("gone.txt"), (Some("bye\n".into()), Some(String::new())));
|
||||
assert_eq!(sides("pic.bin"), (None, None));
|
||||
|
||||
let outcome = vcs::vcs_unshelve(&host, "main", entry.id, true, None).await.unwrap();
|
||||
assert!(outcome.conflicts.is_empty(), "{outcome:?}");
|
||||
let mut applied = outcome.applied.clone();
|
||||
applied.sort();
|
||||
assert_eq!(applied, ["a.txt", "gone.txt", "new.txt", "pic.bin", "prop.txt"]);
|
||||
assert_eq!(fx.svn(&root, &["status"]), changed, "every change is back, the added file scheduled again");
|
||||
assert_eq!(std::fs::read_to_string(path("a.txt")).unwrap(), "one\ntwo\n");
|
||||
assert_eq!(std::fs::read(path("pic.bin")).unwrap(), b"\0\x03\x04\x05");
|
||||
assert_eq!(fx.svn(&root, &["propget", "review", "prop.txt"]).trim(), "yes");
|
||||
assert!(vcs::vcs_shelves(&host, "main").await.unwrap().is_empty(), "removed from the shelf");
|
||||
}
|
||||
|
||||
/// Unshelving onto a conflicting local edit reports the file and keeps it on the shelf.
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn unshelve_onto_a_conflicting_edit() {
|
||||
let Some(fx) = fixture() else { return };
|
||||
let root = shelf_fixture(&fx, &[("a.txt", b"one\n"), ("b.txt", b"b\n")]);
|
||||
let (host, _project) = open(&fx.base, &root).await;
|
||||
let (a, b) = (root.join("a.txt"), root.join("b.txt"));
|
||||
std::fs::write(&a, "one\ntwo\n").unwrap();
|
||||
std::fs::write(&b, "b\nmore\n").unwrap();
|
||||
let entry = vcs::vcs_shelve(&host, "main", "work".into(), vec![a.clone(), b.clone()]).await.unwrap();
|
||||
std::fs::write(&a, "mine\n").unwrap();
|
||||
|
||||
let outcome = vcs::vcs_unshelve(&host, "main", entry.id.clone(), true, None).await.unwrap();
|
||||
assert_eq!((outcome.applied, outcome.conflicts), (vec!["b.txt".to_owned()], vec!["a.txt".to_owned()]));
|
||||
assert_eq!(std::fs::read_to_string(&a).unwrap(), "mine\n", "the local edit is kept");
|
||||
assert_eq!(std::fs::read_to_string(&b).unwrap(), "b\nmore\n");
|
||||
let shelves = vcs::vcs_shelves(&host, "main").await.unwrap();
|
||||
assert_eq!(shelves.len(), 1, "a conflict keeps the shelved changes");
|
||||
assert_eq!(shelves[0].files.len(), 2);
|
||||
}
|
||||
@@ -77,7 +77,7 @@ fn parents(entries: &[StatusEntry]) -> HashSet<PathBuf> {
|
||||
}
|
||||
|
||||
/// `paths` without those below another of them.
|
||||
fn outermost(mut paths: Vec<PathBuf>) -> Vec<PathBuf> {
|
||||
pub(crate) fn outermost(mut paths: Vec<PathBuf>) -> Vec<PathBuf> {
|
||||
paths.sort();
|
||||
paths.dedup();
|
||||
let mut out: Vec<PathBuf> = Vec::new();
|
||||
@@ -458,7 +458,7 @@ impl WorkingCopy {
|
||||
/// A path as a diff argument: relative to the root, so the patch names
|
||||
/// files as `git diff` does. `svn diff` reads a peg revision only when
|
||||
/// comparing with a repository revision; against the base it takes the path as written.
|
||||
fn diff_target(&self, path: &Path, pegged: bool) -> OsString {
|
||||
pub(crate) fn diff_target(&self, path: &Path, pegged: bool) -> OsString {
|
||||
let rel = self.rel(path);
|
||||
// `./` keeps a name starting with `-` from being an option and one starting with `@`
|
||||
// from being a peg revision (E125001).
|
||||
@@ -754,7 +754,7 @@ impl WorkingCopy {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn revert(&self, paths: &[PathBuf]) -> IdeResult<()> {
|
||||
pub(crate) fn revert(&self, paths: &[PathBuf]) -> IdeResult<()> {
|
||||
let entries = self.entries_selected(paths)?;
|
||||
// Folders moved here: what svn never tracked in them goes back with the folder.
|
||||
let moved_here: Vec<PathBuf> = entries
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
mod backend;
|
||||
mod cli;
|
||||
mod ops;
|
||||
mod shelf;
|
||||
mod workspace;
|
||||
mod xml;
|
||||
|
||||
|
||||
@@ -0,0 +1,237 @@
|
||||
//! Shelve Changes for a working copy: the shelf keeps a patch in Git form (as for a Git
|
||||
//! repository); `svn diff --git` writes it, `svn patch` applies it back.
|
||||
|
||||
use crate::backend::outermost;
|
||||
use crate::cli::args;
|
||||
use crate::workspace::WorkingCopy;
|
||||
use ide_core::{IdeError, IdeResult};
|
||||
use ide_vcs::{ApplyOutcome, ChangeKind};
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
|
||||
impl WorkingCopy {
|
||||
/// The patch Shelve Changes saves for `paths`: text, binary files (Git binary patches) and
|
||||
/// property changes, named relative to the root. Copies and moves are in it as additions
|
||||
/// (and the deletion of a move's source): their history is not kept. Refused when a change
|
||||
/// of `paths` would be missing from it (an unversioned file, a conflict, a binary file this
|
||||
/// svn does not write into a patch, an empty folder), so that reverting them loses nothing.
|
||||
pub fn shelf_patch(&self, paths: &[PathBuf]) -> IdeResult<String> {
|
||||
let inside = self.inside(paths);
|
||||
if inside.len() != paths.len() {
|
||||
return Err(IdeError::invalid("select files of one Subversion working copy to shelve"));
|
||||
}
|
||||
let status = self.status_of(&inside)?;
|
||||
for file in &status {
|
||||
match file.unstaged {
|
||||
Some(ChangeKind::Untracked) => {
|
||||
return Err(IdeError::invalid(format!(
|
||||
"{} is not under version control: add it to Subversion before shelving it",
|
||||
file.rel_path
|
||||
)));
|
||||
}
|
||||
Some(ChangeKind::Conflicted) => {
|
||||
return Err(IdeError::invalid(format!(
|
||||
"resolve the conflict in {} before shelving it",
|
||||
file.rel_path
|
||||
)));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
// The source of a move goes with its destination: its deletion is part of the change.
|
||||
let mut targets = inside;
|
||||
targets.extend(status.iter().filter_map(|f| f.renamed_from.as_deref().map(|from| self.abs(from))));
|
||||
let mut argv = args(["diff", "--git", "--show-copies-as-adds", "--internal-diff"]);
|
||||
argv.extend(outermost(targets).iter().map(|p| self.diff_target(p, false)));
|
||||
let raw = String::from_utf8(self.run(&argv)?)
|
||||
.map_err(|_| IdeError::invalid("only UTF-8 text files can be shelved in a Subversion working copy"))?;
|
||||
let repository = self.current_repository().path;
|
||||
let (patch, files) = rooted(&raw, repository.trim_matches('/'))?;
|
||||
for file in &status {
|
||||
let rel = if file.rel_path.is_empty() { "." } else { file.rel_path.as_str() };
|
||||
let below = format!("{rel}/");
|
||||
if !files.iter().any(|f| f == rel || f.starts_with(&below)) {
|
||||
return Err(IdeError::invalid(format!("the change of {rel} cannot be shelved")));
|
||||
}
|
||||
}
|
||||
if files.is_empty() {
|
||||
return Err(IdeError::invalid("no changes to shelve"));
|
||||
}
|
||||
Ok(patch)
|
||||
}
|
||||
|
||||
/// Reverts `paths` once their changes are on the shelf as `patch` (as Rollback does: added
|
||||
/// files are removed). Refused, and nothing reverted, when they no longer match `patch`.
|
||||
pub fn shelf_revert(&self, paths: &[PathBuf], patch: &str) -> IdeResult<()> {
|
||||
self.exclusively(|| {
|
||||
if self.shelf_patch(paths)? != patch {
|
||||
return Err(IdeError::invalid("Files changed while shelving. The captured changes are on the Shelf."));
|
||||
}
|
||||
self.revert(paths)
|
||||
})
|
||||
}
|
||||
|
||||
/// Unshelve: `svn patch` of a patch [`shelf_patch`](Self::shelf_patch) made. Files svn
|
||||
/// could not patch (a rejected hunk, left in `<file>.svnpatch.rej`; a skipped file) are
|
||||
/// conflicts.
|
||||
pub fn unshelve(&self, patch: &str) -> IdeResult<ApplyOutcome> {
|
||||
let mut file = tempfile::NamedTempFile::new()?;
|
||||
file.write_all(patch.as_bytes())?;
|
||||
file.flush()?;
|
||||
let argv = [args(["patch"]), vec![file.path().as_os_str().to_owned()]].concat();
|
||||
let out = self.exclusively(|| self.run(&argv))?;
|
||||
Ok(patched(&String::from_utf8_lossy(&out)))
|
||||
}
|
||||
}
|
||||
|
||||
/// `svn diff --git` output with the files named relative to the working copy's root (svn names
|
||||
/// them by their path in the repository, `repository` being the root's), and its `Index:`
|
||||
/// banners left out. The root's own change (a property) is `.`. Also the files, in order.
|
||||
fn rooted(raw: &str, repository: &str) -> IdeResult<(String, Vec<String>)> {
|
||||
let local = |path: &str| -> IdeResult<String> {
|
||||
if repository.is_empty() {
|
||||
return Ok(path.to_owned());
|
||||
}
|
||||
if path == repository {
|
||||
return Ok(".".to_owned());
|
||||
}
|
||||
path.strip_prefix(repository)
|
||||
.and_then(|rest| rest.strip_prefix('/'))
|
||||
.map(str::to_owned)
|
||||
.ok_or_else(|| IdeError::invalid(format!("svn diff named {path}, outside the working copy")))
|
||||
};
|
||||
let mut out = String::with_capacity(raw.len());
|
||||
let mut files = Vec::new();
|
||||
// The file of the last `Index:` banner, and whether its header (before any hunk) is being read.
|
||||
let mut index = String::new();
|
||||
let mut header = false;
|
||||
let mut banner = false;
|
||||
for line in raw.split_inclusive('\n') {
|
||||
let bare = line.trim_end_matches(['\n', '\r']);
|
||||
let end = &line[bare.len()..];
|
||||
if let Some(name) = bare.strip_prefix("Index: ") {
|
||||
index = name.to_owned();
|
||||
banner = true;
|
||||
continue;
|
||||
}
|
||||
if std::mem::take(&mut banner) && !bare.is_empty() && bare.bytes().all(|b| b == b'=') {
|
||||
continue;
|
||||
}
|
||||
if bare.starts_with("Cannot display: ") {
|
||||
return Err(IdeError::invalid(format!(
|
||||
"{index} is a binary file, which this svn does not write into a patch: it cannot be shelved"
|
||||
)));
|
||||
}
|
||||
if let Some(rest) = bare.strip_prefix("diff --git a/") {
|
||||
// `a/<path> b/<path>`: the same path twice, as copies are additions here.
|
||||
let n = rest.len().saturating_sub(3) / 2;
|
||||
let path = rest.get(..n).filter(|p| rest.get(n..) == Some(&format!(" b/{p}")));
|
||||
let path = local(path.ok_or_else(|| IdeError::invalid(format!("unexpected svn diff header: {bare}")))?)?;
|
||||
out.push_str(&format!("diff --git a/{path} b/{path}{end}"));
|
||||
files.push(path);
|
||||
header = true;
|
||||
continue;
|
||||
}
|
||||
if header && let Some((marker, rest)) = bare.split_at_checked(4).filter(|(m, _)| *m == "--- " || *m == "+++ ") {
|
||||
let (path, label) = rest.split_once('\t').map_or((rest, ""), |(p, l)| (p, l));
|
||||
let side = &path[..path.len().min(2)];
|
||||
if let Some(path) = path.strip_prefix("a/").or_else(|| path.strip_prefix("b/")) {
|
||||
let tab = if label.is_empty() { "" } else { "\t" };
|
||||
out.push_str(&format!("{marker}{side}{}{tab}{label}{end}", local(path)?));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if let Some(path) = bare.strip_prefix("Property changes on: ") {
|
||||
header = false;
|
||||
let path = local(path).unwrap_or_else(|_| path.to_owned());
|
||||
out.push_str(&format!("Property changes on: {path}{end}"));
|
||||
continue;
|
||||
}
|
||||
if bare.starts_with("@@ ") || bare.starts_with("GIT binary patch") {
|
||||
header = false;
|
||||
}
|
||||
out.push_str(line);
|
||||
}
|
||||
Ok((out, files))
|
||||
}
|
||||
|
||||
/// What `svn patch` printed, as applied and conflicted files. A line is `XY` status columns
|
||||
/// and the path from the 11th character on (`U`pdated, `A`dded, `D`eleted, `G` merged with an
|
||||
/// offset, `C` with a rejected hunk); `Skipped '<path>' -- …` is a file it left alone.
|
||||
fn patched(out: &str) -> ApplyOutcome {
|
||||
let mut outcome = ApplyOutcome { applied: Vec::new(), conflicts: Vec::new() };
|
||||
let path = |p: &str| p.replace('\\', "/");
|
||||
for line in out.lines() {
|
||||
if let Some(rest) = line.strip_prefix("Skipped") {
|
||||
if let Some((_, rest)) = rest.split_once('\'')
|
||||
&& let Some((skipped, _)) = rest.split_once('\'')
|
||||
{
|
||||
outcome.conflicts.push(path(skipped));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
let Some((columns, name)) = line.split_at_checked(10) else { continue };
|
||||
if name.is_empty() || !columns.bytes().all(|b| b" UADGCR".contains(&b)) || columns.trim().is_empty() {
|
||||
continue;
|
||||
}
|
||||
let name = path(name);
|
||||
if columns.contains('C') {
|
||||
outcome.conflicts.push(name);
|
||||
} else {
|
||||
outcome.applied.push(name);
|
||||
}
|
||||
}
|
||||
outcome.applied.retain(|p| !outcome.conflicts.contains(p));
|
||||
outcome.applied.dedup();
|
||||
outcome.conflicts.dedup();
|
||||
outcome
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{patched, rooted};
|
||||
|
||||
#[test]
|
||||
fn names_files_from_the_working_copy_root() {
|
||||
let raw = "Index: a.txt\n\
|
||||
===================================================================\n\
|
||||
diff --git a/trunk/a.txt b/trunk/a.txt\n\
|
||||
--- a/trunk/a.txt\t(revision 2)\n\
|
||||
+++ b/trunk/a.txt\t(working copy)\n\
|
||||
@@ -1 +1,2 @@\n\
|
||||
\x20hello\n\
|
||||
+--- a/trunk/x\n\
|
||||
Index: .\n\
|
||||
===================================================================\n\
|
||||
diff --git a/trunk b/trunk\n\
|
||||
--- a/trunk\t(revision 2)\n\
|
||||
+++ b/trunk\t(working copy)\n\
|
||||
\n\
|
||||
Property changes on: trunk\n\
|
||||
___________________________________________________________________\n\
|
||||
Added: p\n\
|
||||
## -0,0 +1 ##\n\
|
||||
+v\n";
|
||||
let (patch, files) = rooted(raw, "trunk").unwrap();
|
||||
assert_eq!(files, ["a.txt", "."]);
|
||||
assert_eq!(
|
||||
patch,
|
||||
"diff --git a/a.txt b/a.txt\n--- a/a.txt\t(revision 2)\n+++ b/a.txt\t(working copy)\n@@ -1 +1,2 @@\n \
|
||||
hello\n+--- a/trunk/x\ndiff --git a/. b/.\n--- a/.\t(revision 2)\n+++ b/.\t(working copy)\n\n\
|
||||
Property changes on: .\n___________________________________________________________________\n\
|
||||
Added: p\n## -0,0 +1 ##\n+v\n"
|
||||
);
|
||||
assert!(rooted("Index: b.bin\n=====\nCannot display: file marked as a binary type.\n", "").is_err());
|
||||
assert!(rooted("diff --git a/other/a b/other/a\n", "trunk").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reads_what_svn_patch_did() {
|
||||
let out = "U a.txt\nC b.txt\n> rejected hunk @@ -1,1 +1,2 @@\n\
|
||||
Skipped 'n.txt' -- obstructed by unversioned node\n U .\nA sub\\new.txt\n\
|
||||
Summary of conflicts:\n Text conflicts: 1\n";
|
||||
let outcome = patched(out);
|
||||
assert_eq!(outcome.applied, ["a.txt", ".", "sub/new.txt"]);
|
||||
assert_eq!(outcome.conflicts, ["b.txt", "n.txt"]);
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ const WRITERS: &[&str] = &[
|
||||
"changelist",
|
||||
"propset",
|
||||
"propdel",
|
||||
"patch",
|
||||
"lock",
|
||||
"unlock",
|
||||
"relocate",
|
||||
@@ -47,6 +48,10 @@ pub struct Repository {
|
||||
pub path: String,
|
||||
/// The revision of the working-copy root.
|
||||
pub revision: Option<u64>,
|
||||
/// The working-copy root's depth (`infinity`, `immediates`, `files`, `empty`).
|
||||
pub depth: String,
|
||||
/// The oldest svn release that reads the working copy (`1.8`), when svn tells it.
|
||||
pub format: Option<String>,
|
||||
}
|
||||
|
||||
/// Where a repository path sits in the standard `trunk` / `branches` / `tags` layout.
|
||||
@@ -605,6 +610,8 @@ fn repository(info: &xml::Info) -> Repository {
|
||||
uuid: info.repository_uuid.clone(),
|
||||
path: if path.is_empty() { "/".into() } else { unescape_url(path) },
|
||||
revision: info.revision,
|
||||
depth: info.depth.clone(),
|
||||
format: info.format.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -248,6 +248,10 @@ pub struct Info {
|
||||
pub conflict_files: Vec<String>,
|
||||
pub conflicts: Vec<Conflict>,
|
||||
pub lock: Option<Lock>,
|
||||
/// `infinity`, `immediates`, `files`, `empty`: how much of the folder the working copy holds.
|
||||
pub depth: String,
|
||||
/// The oldest svn release that reads this working copy (`1.8`); svn 1.15 and later tell it.
|
||||
pub format: Option<String>,
|
||||
/// The last revision that changed this path, and when.
|
||||
pub last_changed_revision: Option<u64>,
|
||||
pub last_changed_ms: f64,
|
||||
@@ -311,6 +315,8 @@ pub(crate) fn info(xml: &[u8]) -> IdeResult<Vec<Info>> {
|
||||
conflict_files,
|
||||
conflicts,
|
||||
lock: entry.child("lock").map(lock),
|
||||
depth: wc.map(|w| w.text_of("depth")).unwrap_or_default().to_owned(),
|
||||
format: wc.map(|w| w.text_of("wc-compatible-version").to_owned()).filter(|v| !v.is_empty()),
|
||||
last_changed_revision: entry.child("commit").and_then(|c| c.attr("revision")?.parse().ok()),
|
||||
last_changed_ms: entry.child("commit").and_then(|c| time_ms(c.text_of("date"))).unwrap_or(0.0),
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
//! Shelve Changes in a working copy: the patch the shelf keeps and the rollback after it.
|
||||
mod common;
|
||||
|
||||
use common::{repo, write};
|
||||
|
||||
/// A file changed between saving its patch on the shelf and rolling it back is left alone.
|
||||
#[test]
|
||||
fn a_file_changed_after_its_patch_was_taken_is_not_reverted() {
|
||||
let Some(repo) = repo() else { return };
|
||||
let wc = repo.checkout("wc");
|
||||
let a = write(&wc, "a.txt", "one\n");
|
||||
repo.svn(wc.root(), &["add", "-q", "a.txt"]);
|
||||
repo.svn(wc.root(), &["commit", "-q", "-m", "a"]);
|
||||
std::fs::write(&a, "one\ntwo\n").unwrap();
|
||||
let patch = wc.shelf_patch(std::slice::from_ref(&a)).unwrap();
|
||||
assert!(patch.starts_with("diff --git a/a.txt b/a.txt\n"), "{patch}");
|
||||
std::fs::write(&a, "one\ntwo\nthree\n").unwrap();
|
||||
assert!(wc.shelf_revert(std::slice::from_ref(&a), &patch).is_err());
|
||||
assert_eq!(std::fs::read_to_string(&a).unwrap(), "one\ntwo\nthree\n");
|
||||
// Unchanged since: rolled back.
|
||||
let patch = wc.shelf_patch(std::slice::from_ref(&a)).unwrap();
|
||||
wc.shelf_revert(std::slice::from_ref(&a), &patch).unwrap();
|
||||
assert_eq!(std::fs::read_to_string(&a).unwrap(), "one\n");
|
||||
}
|
||||
|
||||
/// A move is shelved as the deletion of its source and the addition of its destination, so
|
||||
/// rolling back both halves loses nothing.
|
||||
#[test]
|
||||
fn a_moved_file_is_shelved_with_its_source() {
|
||||
let Some(repo) = repo() else { return };
|
||||
let wc = repo.checkout("wc");
|
||||
write(&wc, "a.txt", "one\n");
|
||||
repo.svn(wc.root(), &["add", "-q", "a.txt"]);
|
||||
repo.svn(wc.root(), &["commit", "-q", "-m", "a"]);
|
||||
repo.svn(wc.root(), &["move", "-q", "a.txt", "b.txt"]);
|
||||
let b = wc.root().join("b.txt");
|
||||
let patch = wc.shelf_patch(std::slice::from_ref(&b)).unwrap();
|
||||
assert!(patch.contains("diff --git a/a.txt b/a.txt\ndeleted file mode"), "{patch}");
|
||||
assert!(patch.contains("diff --git a/b.txt b/b.txt\nnew file mode"), "{patch}");
|
||||
wc.shelf_revert(std::slice::from_ref(&b), &patch).unwrap();
|
||||
assert_eq!(repo.svn(wc.root(), &["status"]), "");
|
||||
let outcome = wc.unshelve(&patch).unwrap();
|
||||
assert!(outcome.conflicts.is_empty(), "{outcome:?}");
|
||||
assert_eq!(std::fs::read_to_string(&b).unwrap(), "one\n");
|
||||
assert!(!wc.root().join("a.txt").exists());
|
||||
}
|
||||
@@ -221,6 +221,96 @@ pub fn save_combined(shelf: &Path, base: &Path, name: &str, captures: &[ShelfCap
|
||||
write_entry(shelf, info, &patch, None)
|
||||
}
|
||||
|
||||
/// Saves `patch` (Git form, paths relative to `repo`) of a working copy that is not Git's as a
|
||||
/// shelved change list; reverting the files is the caller's.
|
||||
pub fn save(
|
||||
shelf: &Path,
|
||||
name: &str,
|
||||
repo: &Path,
|
||||
branch: Option<String>,
|
||||
patch: &str,
|
||||
) -> IdeResult<ShelvedChangeList> {
|
||||
let name = name.trim();
|
||||
if name.is_empty() {
|
||||
return Err(IdeError::invalid("name must not be empty"));
|
||||
}
|
||||
let files = changed_files(patch);
|
||||
if files.is_empty() {
|
||||
return Err(IdeError::invalid("no changes to shelve"));
|
||||
}
|
||||
crate::changelists::ensure_ignored(shelf, &["*"])?;
|
||||
let info = Info {
|
||||
name: name.to_owned(),
|
||||
time_ms: now_ms(),
|
||||
branch,
|
||||
repo: Some(repo.into()),
|
||||
files,
|
||||
repositories: Vec::new(),
|
||||
group: None,
|
||||
};
|
||||
write_entry(shelf, info, patch, None)
|
||||
}
|
||||
|
||||
/// `before` with the text hunks (`@@`) of the unified diff `section` applied, each where it
|
||||
/// says; `None` when a hunk's old lines are not there. Property changes (`##`) are not text.
|
||||
fn apply_hunks(before: &str, section: &str) -> Option<String> {
|
||||
let old: Vec<&str> = before.split_inclusive('\n').collect();
|
||||
let same = |a: &str, b: &str| a.strip_suffix('\n').unwrap_or(a) == b.strip_suffix('\n').unwrap_or(b);
|
||||
let mut out = String::with_capacity(before.len());
|
||||
let mut at = 0;
|
||||
let mut lines = section.split_inclusive('\n').peekable();
|
||||
while let Some(line) = lines.next() {
|
||||
let Some(range) = line.strip_prefix("@@ -") else { continue };
|
||||
let mut parts = range.split(' ');
|
||||
let span = |part: Option<&str>| -> Option<(usize, usize)> {
|
||||
let part = part?.trim_start_matches(['-', '+']);
|
||||
Some(match part.split_once(',') {
|
||||
Some((start, count)) => (start.parse().ok()?, count.parse().ok()?),
|
||||
None => (part.parse().ok()?, 1),
|
||||
})
|
||||
};
|
||||
let (start, mut removed) = span(parts.next())?;
|
||||
let (_, mut added) = span(parts.next())?;
|
||||
// `-0,0` (nothing before) is the place before the first line.
|
||||
let first = if removed == 0 { start } else { start.checked_sub(1)? };
|
||||
if first < at || first > old.len() {
|
||||
return None;
|
||||
}
|
||||
out.extend(old[at..first].iter().copied());
|
||||
at = first;
|
||||
let mut previous = "";
|
||||
while removed > 0 || added > 0 || lines.peek().is_some_and(|l| l.starts_with('\\')) {
|
||||
let line = lines.next()?;
|
||||
let (kind, text) = line.split_at_checked(1)?;
|
||||
match kind {
|
||||
" " | "-" if removed > 0 && old.get(at).is_some_and(|o| same(o, text)) => {
|
||||
if kind == " " {
|
||||
out.push_str(old[at]);
|
||||
added = added.checked_sub(1)?;
|
||||
}
|
||||
at += 1;
|
||||
removed -= 1;
|
||||
}
|
||||
"+" if added > 0 => {
|
||||
out.push_str(text);
|
||||
added -= 1;
|
||||
}
|
||||
// `\ No newline at end of file`: the added line before it ends without one (an
|
||||
// old line, kept or removed, is copied or dropped as it is).
|
||||
"\\" => {
|
||||
if previous == "+" && out.ends_with('\n') {
|
||||
out.pop();
|
||||
}
|
||||
}
|
||||
_ => return None,
|
||||
}
|
||||
previous = kind;
|
||||
}
|
||||
}
|
||||
out.extend(old[at..].iter().copied());
|
||||
Some(out)
|
||||
}
|
||||
|
||||
/// A patch selection with its original repository and the common path prefix to strip when applying it.
|
||||
pub struct ShelfSelection {
|
||||
pub repo: Option<ide_core::IpcPath>,
|
||||
@@ -242,6 +332,37 @@ impl ShelfSelection {
|
||||
diff_from_patch(r, &self.patch, &self.prefix)
|
||||
}
|
||||
|
||||
/// The patch text of the selection, its paths relative to [`Self::repo`] after the prefix.
|
||||
pub fn patch(&self) -> &str {
|
||||
&self.patch
|
||||
}
|
||||
|
||||
/// [`Self::diff_files`] for a working copy that is not Git's: the before side is `base` of a
|
||||
/// path (its text in the version the change was made on; `None` when it cannot be read), the
|
||||
/// after side that text with the section's hunks applied. Neither side when a hunk does not
|
||||
/// match it, or for a binary file.
|
||||
pub fn diff_files_on(&self, base: impl Fn(&str) -> IdeResult<Option<Vec<u8>>>) -> Vec<ShelfDiffFile> {
|
||||
let mut out = Vec::new();
|
||||
for (section, file) in crate::patch::sections(&self.patch) {
|
||||
let mut item =
|
||||
ShelfDiffFile { path: file.path.clone(), patch: section.to_string(), before: None, after: None };
|
||||
if !file.binary {
|
||||
let before = match file.kind {
|
||||
ChangeKind::Added => Some(String::new()),
|
||||
_ => base(&file.path).ok().flatten().and_then(|bytes| String::from_utf8(bytes).ok()),
|
||||
};
|
||||
if let Some(before) = before
|
||||
&& let Some(after) = apply_hunks(&before, section)
|
||||
{
|
||||
item.before = Some(before);
|
||||
item.after = Some(after);
|
||||
}
|
||||
}
|
||||
out.push(item);
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
pub fn export(&self, fallback_root: &Path, base: &Path) -> IdeResult<String> {
|
||||
let root = self.repo.as_deref().unwrap_or(fallback_root);
|
||||
crate::patch::rebase_patch(&self.patch, root, &self.prefix, base)
|
||||
@@ -884,7 +1005,19 @@ pub fn import_patch(shelf: &Path, name: &str, patch: &str, repo: Option<&Path>)
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::slug;
|
||||
use super::{apply_hunks, slug};
|
||||
|
||||
#[test]
|
||||
fn applies_hunks_where_they_say() {
|
||||
let section = "diff --git a/a b/a\n--- a/a\n+++ b/a\n@@ -1,2 +1,2 @@\n one\n-two\n+2\n@@ -4 +4,2 @@\n-four\n\\ No newline at end of file\n+4\n+five\n\\ No newline at end of file\n";
|
||||
assert_eq!(apply_hunks("one\ntwo\nthree\nfour", section).as_deref(), Some("one\n2\nthree\n4\nfive"));
|
||||
assert_eq!(apply_hunks("one\nTWO\nthree\nfour", section), None);
|
||||
let added = "--- a/n\t(nonexistent)\n+++ b/n\t(working copy)\n@@ -0,0 +1 @@\n+new\n";
|
||||
assert_eq!(apply_hunks("", added).as_deref(), Some("new\n"));
|
||||
// Property changes are not the text's.
|
||||
let property = "--- a/p\n+++ b/p\n\nProperty changes on: p\n___\nAdded: x\n## -0,0 +1 ##\n+v\n";
|
||||
assert_eq!(apply_hunks("text\n", property).as_deref(), Some("text\n"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn slugs() {
|
||||
|
||||
@@ -16854,11 +16854,18 @@ export type SvnProperty = {
|
||||
value: string,
|
||||
};
|
||||
|
||||
/** Where a working copy points: VCS › Subversion › Relocate shows the current URL. */
|
||||
/**
|
||||
* Where a working copy points (VCS › Subversion › Relocate shows the current URL), and what
|
||||
* the Working Copies tab shows of it.
|
||||
*/
|
||||
export type SvnRepositoryInfo = {
|
||||
url: string,
|
||||
rootUrl: string,
|
||||
uuid: string,
|
||||
revision: number | null,
|
||||
depth: string,
|
||||
/** The oldest svn release that reads the working copy (`1.8`); `None` before svn 1.15. */
|
||||
format: string | null,
|
||||
};
|
||||
|
||||
/** Settings › Version Control › Subversion (`vcs.svn`). */
|
||||
|
||||
@@ -6,6 +6,7 @@ import * as ipc from "@/platform/ipc";
|
||||
import { resetDistractionFree, setDistractionFree } from "@/workbench/distractionFree";
|
||||
import { useFullscreen } from "@/workbench/zenMode";
|
||||
import { registerStatusItem, registerToolWindow } from "@/workbench/contributions";
|
||||
import { setOtherVcsRoots } from "@/platform/gitEnabled";
|
||||
import { useProject } from "@/platform/project";
|
||||
import { _reloadLayouts, saveLayout } from "@/workbench/toolwindows/layouts";
|
||||
import { clearContext, setContext } from "@/platform/context";
|
||||
@@ -327,6 +328,19 @@ describe("menu config", () => {
|
||||
});
|
||||
|
||||
describe("window-scoped menu labels", () => {
|
||||
// Issue #7433: a Subversion project's menu bar said Git. IDEA names the menu after the
|
||||
// project's one system, and VCS for several.
|
||||
it("names the version control menu after the project's systems", () => {
|
||||
const label = () => buildMenuConfig("macos").labels["menu.git"];
|
||||
expect(label()).toBe("Git");
|
||||
setOtherVcsRoots(true, "svn");
|
||||
expect(label()).toBe("SVN");
|
||||
setOtherVcsRoots(true, "vcs");
|
||||
expect(label()).toBe("VCS");
|
||||
setOtherVcsRoots(false);
|
||||
expect(label()).toBe("Git");
|
||||
});
|
||||
|
||||
it("flips Enter / Exit Distraction Free Mode with the window's mode", () => {
|
||||
expect(buildMenuConfig("macos").labels["menu.editor.toggleZen"]).toBe("Enter Distraction Free Mode");
|
||||
expect(buildMenuConfig("macos").accelerators["editor.toggleZen"]).toBeUndefined();
|
||||
|
||||
@@ -36,8 +36,8 @@ export function activate(): () => void {
|
||||
title: "GraphQL",
|
||||
icon: "toolwindow-graphql",
|
||||
anchor: "bottom",
|
||||
// IDEA's stripe: right above Git (order 5).
|
||||
order: 4,
|
||||
// IDEA's stripe: right above Git (order 50).
|
||||
order: 49,
|
||||
stripe: "onUse",
|
||||
component: GraphQLView,
|
||||
headerContent: GraphQLTabs,
|
||||
|
||||
@@ -46,6 +46,7 @@ import { branchesByRepo } from "./multiRoot";
|
||||
import { stripSlash } from "./model";
|
||||
import { clearConsole, useVcsConsole } from "./ops";
|
||||
import { loadBranches, refreshNow, useAnyGit, useVcs } from "./store";
|
||||
import { SvnWorkingCopies } from "./SvnWorkingCopies";
|
||||
import { UnavailableReposBanner } from "./UnavailableReposBanner";
|
||||
|
||||
/** The Git window's tabs (they depend on the commit interface) and the one shown. */
|
||||
@@ -57,7 +58,8 @@ function useGitTabs() {
|
||||
const tab = useGitLog((s) => s.tab);
|
||||
const logTabs = useGitLog((s) => s.logTabs);
|
||||
const counts = useStashTabCounts(available && modal);
|
||||
const tabs = gitTabs({ modal, combine, tab, logTabs, ...counts, noGit: !anyGit });
|
||||
const workingCopies = useVcs((s) => s.roots.some((root) => s.kinds[root] === "subversion"));
|
||||
const tabs = gitTabs({ modal, combine, tab, logTabs, ...counts, noGit: !anyGit, workingCopies });
|
||||
return { tabs, shown: shownTab(tab, tabs, combine) };
|
||||
}
|
||||
|
||||
@@ -120,6 +122,8 @@ export function GitToolWindow() {
|
||||
<ConsoleView />
|
||||
) : shown === "worktrees" ? (
|
||||
<WorktreesPanel className={styles.worktrees} listClassName={styles.worktreeList} />
|
||||
) : shown === "svnInfo" ? (
|
||||
<SvnWorkingCopies />
|
||||
) : null}
|
||||
{keptLog && (
|
||||
<div ref={logHost} className={clsx(styles.logHost, !logShown && styles.logHidden)} inert={!logShown}>
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
.root {
|
||||
height: 100%;
|
||||
overflow: auto;
|
||||
padding: 8px 12px;
|
||||
font-size: var(--fs-ui);
|
||||
}
|
||||
.empty {
|
||||
padding: 12px;
|
||||
color: var(--fg-secondary);
|
||||
}
|
||||
.copy + .copy {
|
||||
margin-top: 12px;
|
||||
padding-top: 12px;
|
||||
border-top: 1px solid var(--border);
|
||||
}
|
||||
.path {
|
||||
margin: 0 0 6px;
|
||||
font-size: var(--fs-ui);
|
||||
font-weight: 600;
|
||||
user-select: text;
|
||||
}
|
||||
.fields {
|
||||
display: grid;
|
||||
grid-template-columns: max-content 1fr;
|
||||
gap: 2px 16px;
|
||||
margin: 0 0 6px;
|
||||
}
|
||||
.field {
|
||||
display: contents;
|
||||
}
|
||||
.field dt {
|
||||
color: var(--fg-secondary);
|
||||
}
|
||||
.field dd {
|
||||
margin: 0;
|
||||
user-select: text;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.error {
|
||||
margin-bottom: 6px;
|
||||
color: var(--fg-secondary);
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
.actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px 16px;
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
/**
|
||||
* Subversion Working Copies Information (IDEA's tab of the version control tool window): every
|
||||
* working copy of the project with where it points, and what acts on that one working copy.
|
||||
*/
|
||||
import { useEffect, useState } from "react";
|
||||
import type { SvnRepositoryInfo } from "@/bindings";
|
||||
import { executeAction } from "@/platform/actions";
|
||||
import { call, commands } from "@/platform/ipc";
|
||||
import { tx } from "@/platform/i18n";
|
||||
import { T } from "@/ui";
|
||||
import { displayPath } from "./compareData";
|
||||
import { selectGitTab, setLogFilters } from "./logStore";
|
||||
import { errorMessage } from "./ops";
|
||||
import { useVcs } from "./store";
|
||||
import { svnCleanup, svnRelocate } from "./svn";
|
||||
import common from "./common.module.css";
|
||||
import styles from "./SvnWorkingCopies.module.css";
|
||||
|
||||
type Read = { info: SvnRepositoryInfo } | { error: string };
|
||||
|
||||
/** The project's Subversion working copies, in root order. */
|
||||
function useWorkingCopies(): string[] {
|
||||
const roots = useVcs((s) => s.roots);
|
||||
const kinds = useVcs((s) => s.kinds);
|
||||
return roots.filter((root) => kinds[root] === "subversion");
|
||||
}
|
||||
|
||||
export function SvnWorkingCopies() {
|
||||
const copies = useWorkingCopies();
|
||||
// Read again after each status refresh: an update, switch or relocate changes them.
|
||||
const version = useVcs((s) => s.version);
|
||||
const [read, setRead] = useState<Record<string, Read>>({});
|
||||
const key = copies.join("\n");
|
||||
useEffect(() => {
|
||||
let current = true;
|
||||
for (const root of key ? key.split("\n") : []) {
|
||||
call(commands.svnRepositoryInfo(root)).then(
|
||||
(info) => current && setRead((r) => ({ ...r, [root]: { info } })),
|
||||
(e: unknown) => current && setRead((r) => ({ ...r, [root]: { error: errorMessage(e) } })),
|
||||
);
|
||||
}
|
||||
return () => {
|
||||
current = false;
|
||||
};
|
||||
}, [key, version]);
|
||||
if (!copies.length) {
|
||||
return (
|
||||
<div className={styles.empty}>
|
||||
<T>No Subversion working copies</T>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<div className={styles.root}>
|
||||
{copies.map((root) => (
|
||||
<WorkingCopy key={root} root={root} read={read[root]} />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function WorkingCopy({ root, read }: { root: string; read: Read | undefined }) {
|
||||
const info = read && "info" in read ? read.info : null;
|
||||
const rows: Array<[string, string]> = info
|
||||
? [
|
||||
[tx("URL"), info.url],
|
||||
[tx("Repository Root"), info.rootUrl],
|
||||
[tx("Revision"), info.revision === null ? "" : `r${info.revision}`],
|
||||
[tx("Depth"), info.depth],
|
||||
...(info.format ? [[tx("Format"), info.format] as [string, string]] : []),
|
||||
]
|
||||
: [];
|
||||
const link = (label: string, run: () => void) => (
|
||||
<button type="button" className={common.linkButton} onClick={run}>
|
||||
{label}
|
||||
</button>
|
||||
);
|
||||
return (
|
||||
<section className={styles.copy} aria-label={displayPath(root)}>
|
||||
<h3 className={styles.path}>{displayPath(root)}</h3>
|
||||
{read && "error" in read ? (
|
||||
<div className={styles.error} role="alert">
|
||||
{read.error}
|
||||
</div>
|
||||
) : (
|
||||
<dl className={styles.fields}>
|
||||
{rows.map(([name, value]) => (
|
||||
<div key={name} className={styles.field}>
|
||||
<dt>{name}</dt>
|
||||
<dd>{value}</dd>
|
||||
</div>
|
||||
))}
|
||||
</dl>
|
||||
)}
|
||||
<div className={styles.actions}>
|
||||
{link(tx("Show Log"), () => {
|
||||
setLogFilters({ repositories: [root] });
|
||||
selectGitTab("log");
|
||||
})}
|
||||
{link(tx("Update Project…"), () => void executeAction("vcs.update", { repo: root }))}
|
||||
{link(tx("Cleanup"), () => void svnCleanup(root))}
|
||||
{link(tx("Relocate…"), () => void svnRelocate(root))}
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -24,6 +24,11 @@ describe("Settings › Git › Enable Git integration off (Review #2 P1 14)", ()
|
||||
expect(getAction(id), id).toBeDefined();
|
||||
}
|
||||
expect(hiddenMenuEntries(undefined, useOtherVcsRoots.getState().present)).toEqual(["vcs.cloneProject"]);
|
||||
// The menu is named after the project's system (issue #7433): SVN, VCS with Git beside it.
|
||||
expect(useOtherVcsRoots.getState().menu).toBe("svn");
|
||||
useVcs.setState({ roots: ["/p", "/p/app"], kinds: { "/p": "subversion", "/p/app": "git" } });
|
||||
expect(useOtherVcsRoots.getState().menu).toBe("vcs");
|
||||
useVcs.setState({ roots: ["/p"], kinds: { "/p": "subversion" } });
|
||||
|
||||
// No working copy (and Git's repositories not looked for): nothing of it is left.
|
||||
useVcs.setState({ roots: [], kinds: {}, repo: null });
|
||||
|
||||
@@ -208,11 +208,12 @@ describe("a project with Git and Subversion roots", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("shelves Git files only, and checks a working copy's files whole", () => {
|
||||
it("shelves Git and Subversion files, and checks a working copy's files whole", () => {
|
||||
const shelve = getAction("vcs.shelve")!;
|
||||
expect(isActionVisible(shelve, undefined, [gitFile])).toBe(true);
|
||||
expect(isActionVisible(shelve, undefined, [svnFile])).toBe(false);
|
||||
// A project without a Git repository has no Shelf or Stash tab.
|
||||
// Issue #7433: the shelf keeps a working copy's changes too.
|
||||
expect(isActionVisible(shelve, undefined, [svnFile])).toBe(true);
|
||||
// A project without a Git repository has no Stash tab; the Shelf shows once it has shelves.
|
||||
expect(stashTabs({ combine: false, shelfCount: 0, stashCount: 0, tab: "changes", noGit: true })).toEqual([]);
|
||||
// A block of a Subversion file cannot be left out of the commit (svn commits whole files).
|
||||
useCommit.setState({ checks: new Map(), excludedHunks: new Map(), excludedHunkLines: new Map() });
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Issue #7433: the Shelf of a Subversion working copy. Shelve, Unshelve and Show Shelf are
|
||||
* offered for it, its Shelf tab shows without Git, and Stash stays Git's.
|
||||
*/
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { getAction, isActionEnabled, isActionVisible } from "@/platform/actions";
|
||||
import { setContext } from "@/platform/context";
|
||||
import { registerVcsActions } from "../actions";
|
||||
import { gitTabs, stashTabs } from "../gitTabs";
|
||||
import { registerHistoryActions } from "../historyActions";
|
||||
import { registerLogPaneActions } from "../logPaneActions";
|
||||
|
||||
const SVN = { vcsAvailable: true, vcsKind: "subversion", vcsAnyGit: false };
|
||||
const PERFORCE = { vcsAvailable: true, vcsKind: "perforce", vcsAnyGit: false };
|
||||
|
||||
function withActions(run: () => void) {
|
||||
const off = [registerVcsActions(), registerHistoryActions(), registerLogPaneActions()];
|
||||
try {
|
||||
run();
|
||||
} finally {
|
||||
off.forEach((dispose) => dispose());
|
||||
setContext("vcsKind", "git");
|
||||
setContext("vcsAnyGit", true);
|
||||
}
|
||||
}
|
||||
|
||||
describe("the Shelf of a Subversion working copy", () => {
|
||||
it("offers Shelve, Unshelve and Show Shelf, and not Stash", () => {
|
||||
withActions(() => {
|
||||
for (const id of ["vcs.shelve", "vcs.shelveSilently", "vcs.unshelve", "vcs.showShelf"]) {
|
||||
const action = getAction(id)!;
|
||||
expect(isActionVisible(action, SVN), id).toBe(true);
|
||||
expect(isActionEnabled(action, SVN), id).toBe(true);
|
||||
// The host shelves Git repositories and Subversion working copies only.
|
||||
expect(isActionEnabled(action, PERFORCE), id).toBe(false);
|
||||
}
|
||||
for (const id of ["vcs.stash", "vcs.unstash", "vcs.showStashes", "vcs.stashSelected"]) {
|
||||
expect(isActionEnabled(getAction(id)!, SVN), id).toBe(false);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it("shows the Shelf tab without a Git repository, and no Stash tab", () => {
|
||||
const input = { combine: false, shelfCount: 2, stashCount: 0, tab: "changes", noGit: true };
|
||||
expect(stashTabs(input)).toEqual([{ id: "shelf", label: "Shelf", count: 2 }]);
|
||||
// Shown while selected (Show Shelf), even when empty.
|
||||
expect(stashTabs({ ...input, shelfCount: 0, tab: "shelf" }).map((t) => t.id)).toEqual(["shelf"]);
|
||||
// "Combine stashes and shelves" needs Git's stashes.
|
||||
expect(stashTabs({ ...input, combine: true }).map((t) => t.id)).toEqual(["shelf"]);
|
||||
const tabs = gitTabs({ ...input, modal: true, logTabs: [] }).map((t) => t.id);
|
||||
expect(tabs).toEqual(["changes", "shelf", "log", "console"]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,76 @@
|
||||
import { fireEvent, render, screen, within } from "@testing-library/react";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
vi.mock("@/platform/ipc", async (importOriginal) => {
|
||||
const real = await importOriginal<typeof import("@/platform/ipc")>();
|
||||
return {
|
||||
...real,
|
||||
commands: {
|
||||
...real.commands,
|
||||
svnRepositoryInfo: (root: string) =>
|
||||
Promise.resolve(
|
||||
root === "/p/antd"
|
||||
? { status: "error", error: { kind: "unavailable", message: "E155036: upgrade the working copy" } }
|
||||
: {
|
||||
status: "ok",
|
||||
data: {
|
||||
url: "https://svn.example/svn/serp/boot/trunk",
|
||||
rootUrl: "https://svn.example/svn/serp",
|
||||
uuid: "u",
|
||||
revision: 22487,
|
||||
depth: "infinity",
|
||||
format: "1.8",
|
||||
},
|
||||
},
|
||||
),
|
||||
},
|
||||
};
|
||||
});
|
||||
const execute = vi.hoisted(() => vi.fn());
|
||||
vi.mock("@/platform/actions", async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import("@/platform/actions")>()),
|
||||
executeAction: execute,
|
||||
}));
|
||||
|
||||
import { gitTabs } from "../gitTabs";
|
||||
import { emptyFilters, useGitLog } from "../logStore";
|
||||
import { useVcs } from "../store";
|
||||
import { SvnWorkingCopies } from "../SvnWorkingCopies";
|
||||
|
||||
afterEach(() => {
|
||||
useVcs.setState({ roots: [], kinds: {}, repo: null });
|
||||
useGitLog.setState({ filters: emptyFilters() });
|
||||
execute.mockReset();
|
||||
});
|
||||
|
||||
// Issue #7433: no way to see a working copy's URL, or to act on one working copy of several
|
||||
// from the version control tool window.
|
||||
describe("Subversion Working Copies Information", () => {
|
||||
it("is a tab of the version control tool window when the project has a working copy", () => {
|
||||
const base = { modal: false, combine: false, logTabs: [], shelfCount: 0, stashCount: 0, tab: "log", noGit: true };
|
||||
expect(gitTabs(base).map((t) => t.id)).toEqual(["log", "console"]);
|
||||
expect(gitTabs({ ...base, workingCopies: true }).map((t) => t.id)).toEqual(["log", "console", "svnInfo"]);
|
||||
});
|
||||
|
||||
it("shows every working copy with its URL, and acts on the one chosen", async () => {
|
||||
useVcs.setState({
|
||||
roots: ["/p/app", "/p/boot", "/p/antd"],
|
||||
kinds: { "/p/app": "git", "/p/boot": "subversion", "/p/antd": "subversion" },
|
||||
repo: "/p/app",
|
||||
});
|
||||
render(<SvnWorkingCopies />);
|
||||
const boot = await screen.findByRole("region", { name: "/p/boot" });
|
||||
expect(await screen.findByText("https://svn.example/svn/serp/boot/trunk")).toBeInTheDocument();
|
||||
expect(boot.textContent).toContain("r22487");
|
||||
expect(boot.textContent).toContain("infinity");
|
||||
expect(boot.textContent).toContain("1.8");
|
||||
expect(await screen.findByRole("alert")).toHaveTextContent("E155036");
|
||||
expect(screen.queryByRole("region", { name: "/p/app" })).toBeNull();
|
||||
|
||||
fireEvent.click(within(boot).getByRole("button", { name: "Update Project…" }));
|
||||
expect(execute).toHaveBeenCalledWith("vcs.update", { repo: "/p/boot" });
|
||||
fireEvent.click(within(boot).getByRole("button", { name: "Show Log" }));
|
||||
expect(useGitLog.getState().filters.repositories).toEqual(["/p/boot"]);
|
||||
expect(useGitLog.getState().tab).toBe("log");
|
||||
});
|
||||
});
|
||||
@@ -29,6 +29,19 @@ describe("which version control system a root is", () => {
|
||||
expect(useContributions.getState().toolWindows.has("git")).toBe(false);
|
||||
});
|
||||
|
||||
// Issue #7433: the button sat above Terminal; IDEA keeps it last, below Terminal (10) and
|
||||
// Problems (30), and below the windows that appear there on use (TODO, Remote Ports: 40).
|
||||
it("puts its stripe button last in the bottom group", () => {
|
||||
const dispose = registerVcsToolWindow();
|
||||
try {
|
||||
const window = useContributions.getState().toolWindows.get("git")!;
|
||||
expect(window.anchor).toBe("bottom");
|
||||
expect(window.order).toBeGreaterThan(40);
|
||||
} finally {
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
|
||||
it("has a 20×20 stripe icon of its own", () => {
|
||||
expect(iconMarkup("subversion", 20)).toContain('viewBox="0 0 20 20"');
|
||||
expect(iconMarkup("subversion", 16)).toContain('viewBox="0 0 16 16"');
|
||||
|
||||
@@ -23,7 +23,7 @@ export interface StashTabsInput {
|
||||
stashCount: number;
|
||||
/** The selected tab: an empty Shelf tab stays while it is shown. */
|
||||
tab: string;
|
||||
/** No Git repository in the project (a Subversion working copy): the Shelf stands in for Stash. */
|
||||
/** No Git repository in the project (a Subversion working copy): the Shelf without Stash. */
|
||||
noGit?: boolean;
|
||||
}
|
||||
|
||||
@@ -34,12 +34,12 @@ export function stashTabOf(tab: CommitTab, combine: boolean): CommitTab {
|
||||
|
||||
/** Shelf and Stash tabs (Shelf only when there are shelves), or the combined one. */
|
||||
export function stashTabs({ combine, shelfCount, stashCount, tab, noGit }: StashTabsInput): ContentTab[] {
|
||||
// Shelves and stashes are Git's patches: a project without a Git repository has neither.
|
||||
if (noGit) return [];
|
||||
if (combine) return [{ id: "stashes", label: "Stashes and Shelves", count: stashCount + shelfCount || undefined }];
|
||||
// Stash is Git's: a project without a Git repository (Subversion working copies) has the Shelf only.
|
||||
if (combine && !noGit)
|
||||
return [{ id: "stashes", label: "Stashes and Shelves", count: stashCount + shelfCount || undefined }];
|
||||
return [
|
||||
...(shelfCount || tab === "shelf" ? [{ id: "shelf", label: "Shelf", count: shelfCount || undefined }] : []),
|
||||
{ id: "stashes", label: "Stash", count: stashCount || undefined },
|
||||
...(noGit ? [] : [{ id: "stashes", label: "Stash", count: stashCount || undefined }]),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -53,6 +53,8 @@ export interface GitTabsInput extends StashTabsInput {
|
||||
/** Modal commit interface: the Git window also shows the local changes, shelves and stashes. */
|
||||
modal: boolean;
|
||||
logTabs: readonly LogTab[];
|
||||
/** The project has a Subversion working copy: its information has a tab, as in IDEA. */
|
||||
workingCopies?: boolean;
|
||||
}
|
||||
|
||||
export function gitTabs(input: GitTabsInput): ContentTab[] {
|
||||
@@ -64,6 +66,7 @@ export function gitTabs(input: GitTabsInput): ContentTab[] {
|
||||
.map((t) => ({ id: t.id, label: logTabLabel(t), closable: true })),
|
||||
{ id: "console", label: "Console" },
|
||||
...(input.noGit ? [] : [{ id: "worktrees", label: "Worktrees" }]),
|
||||
...(input.workingCopies ? [{ id: "svnInfo", label: "Subversion Working Copies Information" }] : []),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -150,7 +150,15 @@ export function annotateLabel(path: string | null | undefined): string {
|
||||
|
||||
/** Keeps [`setOtherVcsRoots`] in step with the project's roots (Enable Git integration leaves them). */
|
||||
export function trackOtherVcsRoots(): () => void {
|
||||
const sync = (s: VcsState) => setOtherVcsRoots(s.roots.some((root) => kindOf(s, root) !== "git"));
|
||||
const sync = (s: VcsState) => {
|
||||
const kinds = new Set(s.roots.map((root) => kindOf(s, root)));
|
||||
const [only] = kinds;
|
||||
const menu = kinds.size > 1 ? "vcs" : only === "subversion" ? "svn" : only === "perforce" ? "vcs" : "git";
|
||||
setOtherVcsRoots(
|
||||
[...kinds].some((kind) => kind !== "git"),
|
||||
menu,
|
||||
);
|
||||
};
|
||||
sync(useVcs.getState());
|
||||
const off = useVcs.subscribe(sync);
|
||||
return () => {
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
* action ids; what only Git has is disabled and left out of menus for it.
|
||||
*
|
||||
* Actions of the selected repository go by the `vcsKind` context key; actions over every
|
||||
* repository of the project (Stash, Worktrees) by `vcsAnyGit`.
|
||||
* repository of the project (Stash, Worktrees) by `vcsAnyGit`. The Shelf is Git's and
|
||||
* Subversion's.
|
||||
*/
|
||||
import type { VcsKind } from "@/bindings";
|
||||
import type { Action } from "@/platform/actions";
|
||||
@@ -13,6 +14,9 @@ import type { Action } from "@/platform/actions";
|
||||
// window without a project) is Git's, as it was before other systems existed.
|
||||
const GIT = "vcsKind != subversion && vcsKind != perforce";
|
||||
const ANY_GIT = "vcsAnyGit != false";
|
||||
/** The shelf keeps patches of Git repositories and Subversion working copies. */
|
||||
const SHELF = "vcsKind != perforce";
|
||||
const ANY_SHELF = "(vcsAnyGit != false || vcsKind == subversion)";
|
||||
export const SUBVERSION = "vcsKind == subversion";
|
||||
|
||||
/** Git concepts: remotes, the index, rewriting history, tags, submodules, LFS. */
|
||||
@@ -33,11 +37,8 @@ const GIT_ONLY = new Set([
|
||||
"vcs.stageAll",
|
||||
"vcs.stageAllTracked",
|
||||
"vcs.stageWithoutContent",
|
||||
// The shelf saves Git patches (the host shelves files of Git repositories only).
|
||||
"vcs.shelve",
|
||||
// Stashes the files it is given: Git's files only.
|
||||
"vcs.stashSelected",
|
||||
"vcs.shelveSilently",
|
||||
"vcs.stageGutterChange",
|
||||
"vcs.unstageGutterChange",
|
||||
"vcs.toggleStagedRepositories",
|
||||
@@ -107,6 +108,10 @@ const GIT_ONLY = new Set([
|
||||
"vcs.showHistoryForSelection",
|
||||
]);
|
||||
|
||||
/** Shelve the selected root's files; Unshelve and Show Shelf over the project's shelf. */
|
||||
const SHELF_ACTIONS = new Set(["vcs.shelve", "vcs.shelveSilently"]);
|
||||
const ANY_SHELF_ACTIONS = new Set(["vcs.unshelve", "vcs.showShelf"]);
|
||||
|
||||
/** Git features that span the project's repositories. */
|
||||
const ANY_GIT_ONLY = new Set([
|
||||
"vcs.stash",
|
||||
@@ -118,8 +123,6 @@ const ANY_GIT_ONLY = new Set([
|
||||
"vcs.clearStashes",
|
||||
"vcs.unstash",
|
||||
"vcs.unstashAs",
|
||||
"vcs.unshelve",
|
||||
"vcs.showShelf",
|
||||
"vcs.newWorktree",
|
||||
"vcs.worktrees",
|
||||
"vcs.worktree.openReview",
|
||||
@@ -132,7 +135,15 @@ function and(when: string | undefined, condition: string): string {
|
||||
/** `actions` with what only Git has gated on the root's version control system. */
|
||||
export function gateByVcsKind(actions: Action[]): Action[] {
|
||||
return actions.map((a) => {
|
||||
const condition = GIT_ONLY.has(a.id) ? GIT : ANY_GIT_ONLY.has(a.id) ? ANY_GIT : null;
|
||||
const condition = GIT_ONLY.has(a.id)
|
||||
? GIT
|
||||
: ANY_GIT_ONLY.has(a.id)
|
||||
? ANY_GIT
|
||||
: SHELF_ACTIONS.has(a.id)
|
||||
? SHELF
|
||||
: ANY_SHELF_ACTIONS.has(a.id)
|
||||
? ANY_SHELF
|
||||
: null;
|
||||
return condition ? { ...a, when: and(a.when, condition), visibleWhen: and(a.visibleWhen, condition) } : a;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -37,7 +37,8 @@ function register(kind: ReturnType<typeof vcsKindOf>) {
|
||||
title: vcsToolWindowTitle(kind),
|
||||
icon: vcsToolWindowIcon(kind),
|
||||
anchor: "bottom",
|
||||
order: 5,
|
||||
// Last of the bottom group, below Terminal and Problems, as in IDEA's stripe.
|
||||
order: 50,
|
||||
component,
|
||||
headerContent,
|
||||
});
|
||||
|
||||
@@ -55,10 +55,20 @@ export function whileGitEnabled(register: () => () => void): () => void {
|
||||
* does not turn off: the shared version control UI (Commit, log, annotate) stays for it, and
|
||||
* what only Git has is hidden by the root's system (`vcsKind`).
|
||||
*/
|
||||
export const useOtherVcsRoots = create<{ present: boolean }>(() => ({ present: false }));
|
||||
/**
|
||||
* `menu`: the version control menu's name, as IDEA names it: the project's one system (`git`,
|
||||
* `svn`), else `vcs`.
|
||||
*/
|
||||
export type VcsMenuName = "git" | "svn" | "vcs";
|
||||
|
||||
export function setOtherVcsRoots(present: boolean): void {
|
||||
if (useOtherVcsRoots.getState().present !== present) useOtherVcsRoots.setState({ present });
|
||||
export const useOtherVcsRoots = create<{ present: boolean; menu: VcsMenuName }>(() => ({
|
||||
present: false,
|
||||
menu: "git",
|
||||
}));
|
||||
|
||||
export function setOtherVcsRoots(present: boolean, menu: VcsMenuName = "git"): void {
|
||||
const s = useOtherVcsRoots.getState();
|
||||
if (s.present !== present || s.menu !== menu) useOtherVcsRoots.setState({ present, menu });
|
||||
}
|
||||
|
||||
/** Git integration is on, or the project has a working copy of another system. */
|
||||
|
||||
@@ -266,7 +266,7 @@
|
||||
"menu.completion": "Code Completion",
|
||||
"menu.folding": "Folding",
|
||||
"menu.code.foldSelection": "Fold Selection / Remove Region",
|
||||
"menu.git": "Git",
|
||||
"menu.git": "{vcs, select, svn {SVN} vcs {VCS} other {Git}}",
|
||||
"menu.help": "Help",
|
||||
"menu.mainMenu": "Main Menu",
|
||||
"window.caption.minimize": "Minimize",
|
||||
|
||||
@@ -189,7 +189,7 @@
|
||||
"menu.completion": "Autocompletado de código",
|
||||
"menu.folding": "Plegado",
|
||||
"menu.code.foldSelection": "Plegar selección / Quitar región",
|
||||
"menu.git": "Git",
|
||||
"menu.git": "{vcs, select, svn {SVN} vcs {VCS} other {Git}}",
|
||||
"menu.help": "Ayuda",
|
||||
"menu.mainMenu": "Menú principal",
|
||||
"window.caption.minimize": "Minimizar",
|
||||
|
||||
@@ -188,7 +188,7 @@
|
||||
"menu.completion": "Complétion de code",
|
||||
"menu.folding": "Pliage",
|
||||
"menu.code.foldSelection": "Plier la sélection / supprimer la région",
|
||||
"menu.git": "Git",
|
||||
"menu.git": "{vcs, select, svn {SVN} vcs {VCS} other {Git}}",
|
||||
"menu.help": "Aide",
|
||||
"menu.mainMenu": "Menu principal",
|
||||
"window.caption.minimize": "Réduire",
|
||||
|
||||
@@ -195,7 +195,7 @@
|
||||
"menu.completion": "코드 완성",
|
||||
"menu.folding": "접기",
|
||||
"menu.code.foldSelection": "선택 영역 접기/영역 제거",
|
||||
"menu.git": "Git",
|
||||
"menu.git": "{vcs, select, svn {SVN} vcs {VCS} other {Git}}",
|
||||
"menu.help": "도움말",
|
||||
"menu.mainMenu": "메인 메뉴",
|
||||
"window.caption.minimize": "최소화",
|
||||
|
||||
@@ -189,7 +189,7 @@
|
||||
"menu.completion": "Autouzupełnianie kodu",
|
||||
"menu.folding": "Zwinięcie kodu",
|
||||
"menu.code.foldSelection": "Zwiń zaznaczenie / usuń region",
|
||||
"menu.git": "Git",
|
||||
"menu.git": "{vcs, select, svn {SVN} vcs {VCS} other {Git}}",
|
||||
"menu.help": "Pomoc",
|
||||
"menu.mainMenu": "Menu główne",
|
||||
"window.caption.minimize": "Minimalizuj",
|
||||
|
||||
@@ -189,7 +189,7 @@
|
||||
"menu.completion": "Autocompletar código",
|
||||
"menu.folding": "Recolhimento de código",
|
||||
"menu.code.foldSelection": "Recolher seleção / Remover região",
|
||||
"menu.git": "Git",
|
||||
"menu.git": "{vcs, select, svn {SVN} vcs {VCS} other {Git}}",
|
||||
"menu.help": "Ajuda",
|
||||
"menu.mainMenu": "Menu principal",
|
||||
"window.caption.minimize": "Minimizar",
|
||||
|
||||
@@ -257,7 +257,7 @@
|
||||
"menu.completion": "Автодополнение кода",
|
||||
"menu.folding": "Сворачивание кода",
|
||||
"menu.code.foldSelection": "Свернуть выделение / удалить область",
|
||||
"menu.git": "Git",
|
||||
"menu.git": "{vcs, select, svn {SVN} vcs {VCS} other {Git}}",
|
||||
"menu.help": "Справка",
|
||||
"menu.mainMenu": "Главное меню",
|
||||
"window.caption.minimize": "Свернуть",
|
||||
|
||||
@@ -11788,6 +11788,10 @@
|
||||
"Runs svn as it runs in a terminal. Password and passphrase prompts of svn+ssh repositories and untrusted server certificates of https repositories are then answered in dialogs. Off, svn never asks: a rejected login opens a login dialog once.": "按在终端中运行的方式执行 svn。svn+ssh 仓库的密码和密钥口令提示、https 仓库不受信任的服务器证书,都会弹出对话框让您回答。关闭后 svn 不再提问:登录被拒绝时只弹出一次登录框。",
|
||||
"Lock…": "锁定…",
|
||||
"Unlock": "解锁",
|
||||
"Subversion Working Copies Information": "Subversion 工作副本信息",
|
||||
"No Subversion working copies": "没有 Subversion 工作副本",
|
||||
"Repository Root": "仓库根",
|
||||
"Depth": "深度",
|
||||
"Relocate…": "重新定位…",
|
||||
"Properties…": "属性…",
|
||||
"Switch": "切换",
|
||||
|
||||
@@ -254,7 +254,7 @@
|
||||
"menu.completion": "Kod Tamamlama",
|
||||
"menu.folding": "Kod Katlama",
|
||||
"menu.code.foldSelection": "Seçimi Katla / Bölgeyi Kaldır",
|
||||
"menu.git": "Git",
|
||||
"menu.git": "{vcs, select, svn {SVN} vcs {VCS} other {Git}}",
|
||||
"menu.help": "Yardım",
|
||||
"menu.mainMenu": "Ana Menü",
|
||||
"window.caption.minimize": "Simge Durumuna Küçült",
|
||||
|
||||
@@ -255,7 +255,7 @@
|
||||
"menu.completion": "程式碼自動完成",
|
||||
"menu.folding": "摺疊",
|
||||
"menu.code.foldSelection": "摺疊所選內容/移除區域",
|
||||
"menu.git": "Git",
|
||||
"menu.git": "{vcs, select, svn {SVN} vcs {VCS} other {Git}}",
|
||||
"menu.help": "幫助",
|
||||
"menu.mainMenu": "主選單",
|
||||
"window.caption.minimize": "最小化",
|
||||
|
||||
@@ -266,7 +266,7 @@
|
||||
"menu.completion": "代码补全",
|
||||
"menu.folding": "折叠",
|
||||
"menu.code.foldSelection": "折叠所选内容/移除区域",
|
||||
"menu.git": "Git",
|
||||
"menu.git": "{vcs, select, svn {SVN} vcs {VCS} other {Git}}",
|
||||
"menu.help": "帮助",
|
||||
"menu.mainMenu": "主菜单",
|
||||
"window.caption.minimize": "最小化",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/** Parameters shared between the native menu bridge and the custom title bar menu. */
|
||||
import { getContext } from "@/platform/context";
|
||||
import { useOtherVcsRoots } from "@/platform/gitEnabled";
|
||||
import { basename } from "@/platform/project";
|
||||
import { isVirtualUri } from "@/platform/virtualDocs";
|
||||
import { maybeEditorService } from "./contributions";
|
||||
@@ -21,5 +22,7 @@ export function menuLabelParams(os: string) {
|
||||
toolWindows: toolWindowsRestorable() ? "hidden" : "shown",
|
||||
compileFile: compileFileName ? "yes" : "no",
|
||||
compileFileName: compileFileName ?? "",
|
||||
// The Git menu is named after the project's system: SVN, or VCS for several (IDEA).
|
||||
vcs: useOtherVcsRoots.getState().menu,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Заблокувати користувача