MCPcopy Create free account
hub / github.com/MegEngine/MegFlow / new

Method new

flow-quickstart/src/git.rs:55–83  ·  view source on GitHub ↗

Creates a new `GitConfig` by parsing `git` as a URL or a local path.

(
        git: Cow<'a, str>,
        branch: Option<String>,
        identity: Option<PathBuf>,
    )

Source from the content-addressed store, hash-verified

53impl<'a> GitConfig<'a> {
54 /// Creates a new `GitConfig` by parsing `git` as a URL or a local path.
55 pub fn new(
56 git: Cow<'a, str>,
57 branch: Option<String>,
58 identity: Option<PathBuf>,
59 ) -> Result<Self> {
60 let (remote, kind) = match determine_repo_kind(git.as_ref()) {
61 RepoKind::Invalid => anyhow::bail!("Invalid git remote '{}'", &git),
62 RepoKind::LocalFolder => {
63 let full_path = canonicalize_path(git.deref().as_ref())?;
64 if !full_path.exists() {
65 anyhow::bail!("The given git remote {:?} does not exist.", &git,);
66 }
67 (
68 full_path.display().to_string().into(),
69 RepoKind::LocalFolder,
70 )
71 }
72 k => (git, k),
73 };
74
75 Ok(GitConfig {
76 remote,
77 kind,
78 identity,
79 branch: branch
80 .map(GitReference::Branch)
81 .unwrap_or(GitReference::DefaultBranch),
82 })
83 }
84
85 /// Creates a new `GitConfig`, first with `new` and then as a GitHub `owner/repo` remote, like
86 /// [hub].

Callers

nothing calls this directly

Calls 4

determine_repo_kindFunction · 0.85
canonicalize_pathFunction · 0.85
as_refMethod · 0.80
derefMethod · 0.45

Tested by

no test coverage detected