Skip to content

Commit 65ad5b5

Browse files
feat(cli.rs/info): detect if tauri is used from git (#3309)
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
1 parent 83f52fd commit 65ad5b5

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

.changes/cli.rs-detect-git.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"cli.rs": patch
3+
---
4+
5+
Detect if tauri is used from git in the `info` command.

tooling/cli.rs/src/info.rs

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct YarnVersionInfo {
2828
struct CargoLockPackage {
2929
name: String,
3030
version: String,
31+
source: Option<String>,
3132
}
3233

3334
#[derive(Deserialize)]
@@ -51,6 +52,9 @@ struct VersionMetadata {
5152
#[derive(Clone, Deserialize)]
5253
struct CargoManifestDependencyPackage {
5354
version: Option<String>,
55+
git: Option<String>,
56+
branch: Option<String>,
57+
rev: Option<String>,
5458
path: Option<PathBuf>,
5559
}
5660

@@ -646,20 +650,36 @@ pub fn command(_options: Options) -> Result<()> {
646650
match (&manifest, &lock, tauri_lock_packages.len()) {
647651
(Some(_manifest), Some(_lock), 1) => {
648652
let tauri_lock_package = tauri_lock_packages.first().unwrap();
649-
(
650-
tauri_lock_package.version.clone(),
651-
vec![tauri_lock_package.version.clone()],
652-
)
653+
let version_string = if let Some(s) = &tauri_lock_package.source {
654+
if s.starts_with("git") {
655+
format!("{} ({})", s, tauri_lock_package.version)
656+
} else {
657+
tauri_lock_package.version.clone()
658+
}
659+
} else {
660+
tauri_lock_package.version.clone()
661+
};
662+
(version_string, vec![tauri_lock_package.version.clone()])
653663
}
654664
(None, Some(_lock), 1) => {
655665
let tauri_lock_package = tauri_lock_packages.first().unwrap();
666+
let version_string = if let Some(s) = &tauri_lock_package.source {
667+
if s.starts_with("git") {
668+
format!("{} ({})", s, tauri_lock_package.version)
669+
} else {
670+
tauri_lock_package.version.clone()
671+
}
672+
} else {
673+
tauri_lock_package.version.clone()
674+
};
656675
(
657-
format!("{} (no manifest)", tauri_lock_package.version),
676+
format!("{} (no manifest)", version_string),
658677
vec![tauri_lock_package.version.clone()],
659678
)
660679
}
661680
_ => {
662681
let mut found_tauri_versions = Vec::new();
682+
let mut is_git = false;
663683
let manifest_version = match manifest.and_then(|m| m.dependencies.get("tauri").cloned()) {
664684
Some(tauri) => match tauri {
665685
CargoManifestDependency::Version(v) => {
@@ -680,6 +700,15 @@ pub fn command(_options: Options) -> Result<()> {
680700
Err(_) => "unknown version".to_string(),
681701
};
682702
format!("path:{:?} [{}]", p, v)
703+
} else if let Some(g) = p.git {
704+
is_git = true;
705+
let mut v = format!("git:{}", g);
706+
if let Some(branch) = p.branch {
707+
v.push_str(&format!("&branch={}", branch));
708+
} else if let Some(rev) = p.rev {
709+
v.push_str(&format!("#{}", rev));
710+
}
711+
v
683712
} else {
684713
"unknown manifest".to_string()
685714
}
@@ -699,7 +728,12 @@ pub fn command(_options: Options) -> Result<()> {
699728
};
700729

701730
(
702-
format!("{} ({})", manifest_version, lock_version),
731+
format!(
732+
"{} {}({})",
733+
manifest_version,
734+
if is_git { "(git manifest)" } else { "" },
735+
lock_version
736+
),
703737
found_tauri_versions,
704738
)
705739
}

0 commit comments

Comments
 (0)