MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / capture

Method capture

atomic-cli/src/commands/git/import.rs:838–938  ·  view source on GitHub ↗
(git: &GitRepository)

Source from the content-addressed store, hash-verified

836#[cfg(feature = "experimental-span-import")]
837impl SpanIncrementalGitObservation {
838 fn capture(git: &GitRepository) -> CliResult<Self> {
839 // libgit2's repository index and a Git process using GIT_INDEX_FILE
840 // need not observe the same index. Until the override is explicitly
841 // supported, do not claim a clean checkout based on the wrong file.
842 if std::env::var_os("GIT_INDEX_FILE").is_some() {
843 return Err(CliError::GitError {
844 message:
845 "span incremental import does not support GIT_INDEX_FILE; no import was started"
846 .into(),
847 });
848 }
849 if git.state() != git2::RepositoryState::Clean {
850 return Err(CliError::GitError {
851 message: "Git has an in-progress operation; span incremental import was refused"
852 .into(),
853 });
854 }
855 if git.path().join("index.lock").exists() {
856 return Err(CliError::GitError {
857 message: "Git index is locked; span incremental import was refused".into(),
858 });
859 }
860 let head = git.head().map_err(|error| CliError::GitError {
861 message: format!("cannot observe Git HEAD: {error}"),
862 })?;
863 if !head.is_branch() {
864 return Err(CliError::GitError {
865 message: "span incremental import requires an attached Git branch".into(),
866 });
867 }
868 let branch = head
869 .shorthand()
870 .ok()
871 .ok_or_else(|| CliError::GitError {
872 message: "Git branch name is not representable".into(),
873 })?
874 .to_string();
875 let tip = head.target().ok_or_else(|| CliError::GitError {
876 message: "Git branch has no commit".into(),
877 })?;
878 let index =
879 std::fs::read(git.path().join("index")).map_err(|error| CliError::GitError {
880 message: format!("cannot inspect Git index: {error}"),
881 })?;
882 let mut parsed_index = git.index().map_err(|error| CliError::GitError {
883 message: format!("cannot inspect Git index entries: {error}"),
884 })?;
885 parsed_index
886 .read(true)
887 .map_err(|error| CliError::GitError {
888 message: format!("cannot refresh Git index observation: {error}"),
889 })?;
890 if parsed_index.iter().any(|entry| {
891 // These flags tell Git status not to compare a tracked file with
892 // the worktree, so clean status cannot establish its bytes.
893 entry.flags & 0x8000 != 0 || entry.flags_extended & 0x4000 != 0
894 }) {
895 return Err(CliError::GitError {

Callers

nothing calls this directly

Calls 13

include_untrackedMethod · 0.80
readFunction · 0.50
stateMethod · 0.45
existsMethod · 0.45
pathMethod · 0.45
headMethod · 0.45
okMethod · 0.45
indexMethod · 0.45
readMethod · 0.45
iterMethod · 0.45
is_emptyMethod · 0.45
statusMethod · 0.45

Tested by

no test coverage detected