Skip to main content

gitdir_link

Function gitdir_link 

Source
pub fn gitdir_link(text: &str) -> Option<PathBuf>
Expand description

The path a linked work tree’s .git file names, when it names one. Git writes exactly one line, gitdir: <path>, and the path is normally absolute.

use majordomus_cli::worktree::state::gitdir_link;
use std::path::PathBuf;
assert_eq!(gitdir_link("gitdir: /a/.git/worktrees/x\n"), Some(PathBuf::from("/a/.git/worktrees/x")));
assert_eq!(gitdir_link("gitdir: ../elsewhere"), Some(PathBuf::from("../elsewhere")));
assert_eq!(gitdir_link("gitdir:\n"), None);
assert_eq!(gitdir_link("something else\n"), None);
assert_eq!(gitdir_link(""), None);