Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions atomic-cli/src/commands/git/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,7 @@ impl Import {
// then the unambiguous Git HEAD-tree detection, the exact one the
// preflight plan above used. The value is persisted immediately
// after init so every later command reads the recorded policy.
let fresh_vault_tracked = if repo_exists {
let fresh_exclusions = if repo_exists {
None
} else {
Some(
Expand All @@ -1354,7 +1354,7 @@ impl Import {
"cannot resolve the shim vault policy: {error}"
))
},
)? == atomic_repository::ExclusionPolicy::IncludeVault,
)?,
)
};

Expand All @@ -1379,12 +1379,11 @@ impl Import {
repo
};

// Record the detected vault policy for a freshly created repository
// (RFC §6.2): explicit and durable, so the conversion policy is
// frozen for every later command instead of re-detected against a
// moving HEAD.
if let Some(tracked) = fresh_vault_tracked {
super::parallel::record_imported_vault_policy(&repo, tracked)?;
// Persist the detected vault policy for a freshly created repository
// (RFC §6.2). The independent .atomicignore policy follows Git HEAD
// so the projection includes the file exactly when Git tracks it.
if let Some(exclusions) = fresh_exclusions {
super::parallel::record_imported_vault_policy(&repo, exclusions.includes_vault())?;
}

// Enter the shared workspace boundary. Import is also the bootstrap
Expand Down Expand Up @@ -1549,6 +1548,7 @@ impl Import {
self.kind.as_deref(),
self.no_vault,
working_copy,
fresh_exclusions.is_some_and(|policy| policy.includes_atomic_ignore()),
)?;
}

Expand Down Expand Up @@ -1712,6 +1712,7 @@ impl Import {
self.kind.as_deref(),
self.no_vault,
working_copy,
fresh_exclusions.is_some_and(|policy| policy.includes_atomic_ignore()),
)?;
}

Expand Down Expand Up @@ -2031,9 +2032,10 @@ fn init_atomicignore_and_vault(
kind: Option<&str>,
no_vault: bool,
working_copy: WorkingCopyId,
git_tracks_atomic_ignore: bool,
) -> CliResult<()> {
// Step 1: .atomicignore
{
// Git import already recorded a tracked .atomicignore.
if !git_tracks_atomic_ignore {
let ignore_path = workdir.join(".atomicignore");
if !ignore_path.exists() {
// Use explicit --kind if provided, otherwise auto-detect from project files
Expand Down
36 changes: 36 additions & 0 deletions atomic-cli/tests/it/git_shim_branch_reconcile_regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,42 @@ fn assert_clean_and_verified(root: &Path, home: &Path) {
assert!(git(root, &["status", "--porcelain"]).is_empty());
}

#[test]
fn tracked_atomicignore_matches_git_head_after_import() {
for mode in ["--stream", "--no-stream"] {
let root = tempfile::tempdir().unwrap();
let home = tempfile::tempdir().unwrap();
let root = root.path();
let home = home.path();
let ignore = b"build/\n";
git(root, &["init", "-q", "-b", "main"]);
fs::write(root.join(".atomicignore"), ignore).unwrap();
fs::write(root.join("tracked.txt"), b"baseline\n").unwrap();
git(root, &["add", ".atomicignore", "tracked.txt"]);
git(
root,
&["commit", "-qm", "baseline with tracked Atomic ignore"],
);
let head = git(root, &["rev-parse", "HEAD"]);

atomic_ok(root, home, &["git", "import", mode, "--no-vault"]);
atomic_ok(root, home, &["git", "shim", "verify"]);

assert_eq!(git(root, &["rev-parse", "HEAD"]), head, "{mode}");
assert_eq!(
git(root, &["ls-files", "--error-unmatch", ".atomicignore"]),
".atomicignore",
"{mode}"
);
assert_eq!(
fs::read(root.join(".atomicignore")).unwrap(),
ignore,
"{mode}"
);
assert!(git(root, &["status", "--porcelain"]).is_empty(), "{mode}");
}
}

#[test]
fn literal_percent_path_reconciles_without_stale_checkpoint() {
let (root, home) = shim_repo();
Expand Down
60 changes: 41 additions & 19 deletions atomic-repository/src/repository/project_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,29 @@ pub enum ExclusionReason {
pub enum ExclusionPolicy {
ShimPrivate,
IncludeVault,
IncludeAtomicIgnore,
IncludeVaultAndAtomicIgnore,
}

impl ExclusionPolicy {
pub fn includes_vault(self) -> bool {
matches!(self, Self::IncludeVault | Self::IncludeVaultAndAtomicIgnore)
}

pub fn includes_atomic_ignore(self) -> bool {
matches!(
self,
Self::IncludeAtomicIgnore | Self::IncludeVaultAndAtomicIgnore
)
}

pub fn exclusion(self, path: &RepoPath) -> Option<ExclusionReason> {
if atomic_private_path(path.as_bytes()) {
if atomic_private_path(path.as_bytes())
&& (path.as_bytes() != b".atomicignore" || !self.includes_atomic_ignore())
{
Some(ExclusionReason::AtomicPrivate)
} else if path.components().next().unwrap_or_default() == b".vault"
&& self == Self::ShimPrivate
&& !self.includes_vault()
{
Some(ExclusionReason::VaultPrivate)
} else {
Expand Down Expand Up @@ -296,7 +311,7 @@ impl ExclusionPolicy {
// repository) — the HEAD tree decides.
match Repository::canonical_dot_dir(workdir) {
Ok(dot_dir) => dot_dir,
Err(_) => return Ok(Self::from_git_head(git)),
Err(_) => return Ok(Self::from_git_head(git, None)),
}
};
let config_path = dot_dir.join("config.toml");
Expand All @@ -309,30 +324,35 @@ impl ExclusionPolicy {
))
})?;
if let Some(vault) = config.git.shim.vault {
return Ok(match vault {
atomic_config::ShimVaultPolicy::Tracked => Self::IncludeVault,
atomic_config::ShimVaultPolicy::Private => Self::ShimPrivate,
});
return Ok(Self::from_git_head(
git,
Some(matches!(vault, atomic_config::ShimVaultPolicy::Tracked)),
));
}
}
}
Ok(Self::from_git_head(git))
Ok(Self::from_git_head(git, None))
}

/// Auto-detect from the Git HEAD tree: does the tracked root tree hold
/// a `.vault` entry? An unborn or detached-without-commit HEAD reads
/// as untracked.
fn from_git_head(git: &git2::Repository) -> Self {
let tracks_vault = git
/// Resolve tracked root paths from Git HEAD, honoring the vault override.
fn from_git_head(git: &git2::Repository, vault_override: Option<bool>) -> Self {
let tree = git
.head()
.ok()
.and_then(|head| head.peel_to_commit().ok())
.and_then(|commit| commit.tree().ok())
.is_some_and(|tree| tree.get_name(".vault").is_some());
if tracks_vault {
Self::IncludeVault
} else {
Self::ShimPrivate
.and_then(|commit| commit.tree().ok());
let tracked = |name| {
tree.as_ref()
.is_some_and(|tree| tree.get_name(name).is_some())
};
match (
vault_override.unwrap_or_else(|| tracked(".vault")),
tracked(".atomicignore"),
) {
(false, false) => Self::ShimPrivate,
(true, false) => Self::IncludeVault,
(false, true) => Self::IncludeAtomicIgnore,
(true, true) => Self::IncludeVaultAndAtomicIgnore,
}
}
}
Expand Down Expand Up @@ -584,6 +604,8 @@ impl ConversionPolicy {
encoder.u8(match self.exclusions {
ExclusionPolicy::ShimPrivate => 0,
ExclusionPolicy::IncludeVault => 1,
ExclusionPolicy::IncludeAtomicIgnore => 2,
ExclusionPolicy::IncludeVaultAndAtomicIgnore => 3,
});
encoder.u8(match self.losses {
LossPolicy::Refuse => 0,
Expand Down
Loading