lux_lib/git/
mod.rs

1use git_url_parse::GitUrl;
2use mlua::UserData;
3
4use crate::lua_rockspec::{DisplayAsLuaKV, DisplayLuaKV, DisplayLuaValue};
5
6pub mod shorthand;
7pub mod utils;
8
9#[derive(Debug, PartialEq, Clone)]
10pub struct GitSource {
11    pub url: GitUrl,
12    pub checkout_ref: Option<String>,
13}
14
15impl UserData for GitSource {
16    fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
17        methods.add_method("url", |_, this, _: ()| Ok(this.url.to_string()));
18        methods.add_method("checkout_ref", |_, this, _: ()| {
19            Ok(this.checkout_ref.clone())
20        });
21    }
22}
23
24impl DisplayAsLuaKV for GitSource {
25    fn display_lua(&self) -> DisplayLuaKV {
26        let mut source_tbl = Vec::new();
27        source_tbl.push(DisplayLuaKV {
28            key: "url".to_string(),
29            value: DisplayLuaValue::String(format!("{}", self.url)),
30        });
31        if let Some(checkout_ref) = &self.checkout_ref {
32            source_tbl.push(DisplayLuaKV {
33                // branches are not reproducible, so we will only ever generate tags.
34                // lux can also fetch revisions.
35                key: "tag".to_string(),
36                value: DisplayLuaValue::String(checkout_ref.to_string()),
37            });
38        }
39        DisplayLuaKV {
40            key: "source".to_string(),
41            value: DisplayLuaValue::Table(source_tbl),
42        }
43    }
44}