aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/mozart-vcs/src/downloader/svn.rs
blob: 5222b06253fb53d387b3cdc6b34cae63cb1579d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use std::path::Path;

use anyhow::Result;

use crate::util::svn::SvnUtil;

use super::VcsDownloader;

/// SVN downloader using checkout/switch.
pub struct SvnDownloader {
    svn_util: SvnUtil,
}

impl SvnDownloader {
    pub fn new(svn_util: SvnUtil) -> Self {
        Self { svn_util }
    }
}

impl VcsDownloader for SvnDownloader {
    fn download(&self, _url: &str, _reference: &str, _target: &Path) -> Result<()> {
        // SVN doesn't need a pre-download step
        Ok(())
    }

    fn install(&self, url: &str, reference: &str, target: &Path) -> Result<()> {
        let target_str = target.to_string_lossy().to_string();
        let svn_url = format!("{url}@{reference}");
        self.svn_util
            .execute(&["checkout", &svn_url, &target_str], None)?;
        Ok(())
    }

    fn update(&self, url: &str, _old_ref: &str, new_ref: &str, target: &Path) -> Result<()> {
        let svn_url = format!("{url}@{new_ref}");
        self.svn_util
            .execute(&["switch", "--ignore-ancestry", &svn_url], Some(target))?;
        Ok(())
    }

    fn remove(&self, target: &Path) -> Result<()> {
        if target.exists() {
            std::fs::remove_dir_all(target)?;
        }
        Ok(())
    }

    fn local_changes(&self, target: &Path) -> Result<Option<String>> {
        let output = self.svn_util.execute(&["status"], Some(target))?;
        if output.stdout.trim().is_empty() {
            Ok(None)
        } else {
            Ok(Some(output.stdout))
        }
    }

    fn commit_logs(&self, from: &str, to: &str, target: &Path) -> Result<String> {
        let range = format!("{from}:{to}");
        let output = self
            .svn_util
            .execute(&["log", "-r", &range], Some(target))?;
        Ok(output.stdout)
    }
}