Skip to content

fix overwriting gitignore in initializaiton - #877

Merged
xav-db merged 5 commits into
HelixDB:devfrom
CodeMan62:init-gitignore
Mar 3, 2026
Merged

xav-db merged 5 commits into
HelixDB:devfrom
CodeMan62:init-gitignore

Conversation

@CodeMan62

@CodeMan62 CodeMan62 commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

Description

when we initialization helix with helix init in a folder that contains a .gitignore with some content that got wriped and overwritten. this PR fixes that

Related Issues

Closes #876

Checklist when merging to main

  • No compiler warnings (if applicable)
  • Code is formatted with rustfmt
  • No useless or dead code (if applicable)
  • Code is easy to understand
  • Doc comments are used for all functions, enums, structs, and fields (where appropriate)
  • All tests pass
  • Performance has not regressed (assuming change was not to fix a bug)
  • Version number has been updated in helix-cli/Cargo.toml and helixdb/Cargo.toml

Additional Notes

Greptile Summary

Changed .gitignore handling from overwrite to append mode to preserve existing content when running helix init.

Issue found: The duplicate check uses substring matching (existing.contains(line)) which can cause false positives - e.g., if .gitignore contains my-target/, the check for target/ will incorrectly skip adding it.

Important Files Changed

Filename Overview
helix-cli/src/commands/init.rs Fixed gitignore overwriting, but substring matching logic has edge case bugs

Last reviewed commit: 3e51c60

xav-db and others added 3 commits February 17, 2026 16:47
…DB#868)

<!-- greptile_comment -->

<h3>Greptile Summary</h3>

This PR implements `helix sync` to pull schema and query files from
Helix Cloud clusters, integrating the CLI with the dashboard backend. It
adds comprehensive workspace/project/cluster management flows for both
standard and enterprise deployments.

**Major additions:**
- New `helix sync` command with three flows: workspace-based,
project-based, and instance-specific syncing
- Interactive workspace/project/cluster selection using `cliclack`
prompts
- Enterprise cluster support across `add`, `init`, `sync`, and `delete`
commands
- Path sanitization for remote files to prevent directory traversal
attacks
- Workspace config persistence to `~/.helix/config`
- New `intersect` graph traversal operator in the query engine
- Fixed `Ord` implementation in `Value` type to use consistent variant
ordering

**Critical issues found:**
1. `helix-cli/src/commands/sync.rs:495` - `config.enterprise.clear()`
unconditionally removes ALL enterprise instances, not just those from
the selected project (similar to the already-flagged issue with cloud
instances)
2. `helix-cli/src/commands/delete.rs:93,99` - `todo!()` macros will
panic when users delete enterprise instances
3. `helix-db/src/protocol/value.rs:237-249` - Ord/PartialEq
inconsistency in Date↔String comparison due to reversed ordering

**Recommendations:**
- Replace `config.enterprise.clear()` with selective removal logic (like
`config.cloud.retain()`)
- Implement enterprise instance deletion instead of using `todo!()`
- Fix the Date/String comparison ordering to maintain Ord/PartialEq
consistency

<details><summary><h3>Important Files Changed</h3></summary>




| Filename | Overview |
|----------|----------|
| helix-cli/src/commands/sync.rs | New 1410-line file implementing
`helix sync` command with workspace/project/cluster selection flows,
file syncing from cloud, and path sanitization. Notable issue:
`reconcile_project_config_from_cloud` clears all enterprise entries
(line 495) which could delete unrelated instances. |
| helix-cli/src/commands/workspace_flow.rs | New 456-line file
implementing workspace → project → cluster creation flow for `helix add`
and `helix init`. Clean implementation with proper workspace caching,
billing checks, and enterprise cluster support. |
| helix-cli/src/prompts.rs | New 551-line file providing interactive CLI
prompts using `cliclack`. Implements workspace/cluster selection, input
validation, and deployment configuration flows. Well-structured with
proper validation logic. |
| helix-cli/src/config.rs | Added `WorkspaceConfig` for persisting
workspace selections to `~/.helix/config`, and
`EnterpriseInstanceConfig` for enterprise cluster support. Clean
additions with proper error handling. |
| helix-cli/src/commands/delete.rs | Added enterprise instance handling
with `todo!()` placeholders on lines 93 and 99. Will panic when users
try to delete enterprise instances created via `helix add cloud` or
`helix init cloud`. |
| helix-db/src/protocol/value.rs | Fixed `Ord` implementation to use
consistent variant ordering instead of returning `Equal` for
incomparable types (which violated Ord contract). Added `Date`↔`String`
comparison logic. |

</details>


</details>


<details><summary><h3>Flowchart</h3></summary>

```mermaid
flowchart TD
    A[helix sync] --> B{Project context<br/>exists?}
    B -->|No| C[Workspace Sync Flow]
    B -->|Yes, with instance| D[Instance-specific Sync]
    B -->|Yes, interactive| E[Project Sync Flow]
    
    C --> F[Load/Select Workspace]
    F --> G[Fetch Workspace Clusters]
    G --> H{Cluster Type?}
    H -->|Standard| I[Sync .hx files from cluster]
    H -->|Enterprise| J[Sync .rs files from cluster]
    
    E --> K[Authenticate & Select Workspace]
    K --> L[Resolve/Create Project]
    L --> M[Fetch Project Clusters]
    M --> N[User Selects Cluster]
    N --> O{Cluster Type?}
    O -->|Standard| P[Sync .hx files into project]
    O -->|Enterprise| Q[Sync .rs files into project]
    P --> R[Reconcile helix.toml]
    Q --> R
    R --> S[Update cloud/enterprise instances]
    
    D --> T{Instance Type?}
    T -->|Helix Cloud| U[Pull from cloud cluster]
    T -->|Enterprise| V[Pull from enterprise cluster]
    T -->|Local| W[Not implemented - warn user]
    U --> X[Fetch cluster metadata]
    X --> Y[Reconcile helix.toml]
    V --> Z[Fetch enterprise files]
    
    style R fill:#ff9999
    style S fill:#ff9999
    style Y fill:#ff9999
```
</details>


<sub>Last reviewed commit: a330ecb</sub>

<!-- greptile_other_comments_section -->

<!-- /greptile_comment -->
HelixDB#870)

<!-- greptile_comment -->

<h3>Greptile Summary</h3>

This PR significantly improves the CLI's sync functionality with
intelligent conflict resolution, enhances authentication with cluster
API key rotation, and adds update command improvements.

**Key Changes:**
- **Intelligent Sync**: Implements SHA256-based file hashing and
timestamp-based conflict resolution for bidirectional sync between local
and cloud. The new system detects divergence and intelligently suggests
push/pull operations based on which side has newer changes (with
5-second clock skew tolerance)
- **Project Identity**: Adds canonical project ID tracking in
`helix.toml` so projects are matched by ID first, then by name as
fallback
- **Auth Improvements**: Implements cluster API key rotation endpoint
(`helix auth create-key`) with proper error handling
- **Update Fix**: Adds `no_confirm` flag to the self-update process for
non-interactive environments
- **Better UX**: Enhanced prompts for project selection with options to
create new or choose existing projects

**Architectural Improvements:**
- New manifest-based sync system compares local and remote state using
content hashes
- Timestamp-based authority determination for concurrent edits
- Path sanitization for security when handling remote file paths
- Validation of `.hx` queries before pushing to prevent deploying broken
code

<details><summary><h3>Important Files Changed</h3></summary>




| Filename | Overview |
|----------|----------|
| helix-cli/src/commands/sync.rs | Major refactor to intelligent sync
with SHA256 hashing, timestamp-based conflict resolution, and
bidirectional reconciliation |
| helix-cli/src/commands/auth.rs | Implements cluster API key rotation,
memory leak from `.leak()` call on user_id string |
| helix-cli/src/commands/workspace_flow.rs | Enhanced project resolution
to use project ID as canonical identity with fallback to name matching |
| helix-cli/src/prompts.rs | Added new prompts for missing project
choice and project selection with better UX |
| helix-cli/src/config.rs | Added optional project ID field to
ProjectConfig for canonical identity tracking |

</details>


</details>


<details><summary><h3>Flowchart</h3></summary>

```mermaid
%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[helix sync command] --> B{Fetch cloud state}
    B --> C[Build local manifest<br/>SHA256 + timestamps]
    B --> D[Build remote manifest<br/>SHA256 + timestamps]
    
    C --> E[Compare manifests]
    D --> E
    
    E --> F{Comparison result}
    
    F -->|Both empty| G[No action needed]
    F -->|In sync| G
    F -->|Local only| H{Validate local queries}
    F -->|Remote only| I{Confirm pull?}
    F -->|Diverged| J{Determine authority}
    
    H -->|Valid| K{Confirm push?}
    H -->|Invalid| L[Show error]
    
    K -->|Yes| M[Push to cloud]
    K -->|No| G
    
    I -->|Yes| N[Pull to local]
    I -->|No| G
    
    J -->|Local newer| O{Push allowed?}
    J -->|Remote newer| P{Confirm pull?}
    J -->|Tie/Unknown| Q{User choice}
    
    O -->|Yes + Confirm| M
    O -->|No/Decline| R{Offer pull instead?}
    
    P -->|Yes| N
    P -->|No| G
    
    Q -->|Push| M
    Q -->|Pull| N
    Q -->|NoOp| G
    
    R -->|Yes| N
    R -->|No| G
    
    M --> S[Reconciliation complete]
    N --> S
    G --> S
```
</details>


<sub>Last reviewed commit: 04280f6</sub>

<!-- greptile_other_comments_section -->

<!-- /greptile_comment -->

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment thread helix-cli/src/commands/init.rs Outdated
@xav-db
xav-db changed the base branch from main to dev March 3, 2026 10:55
"#;
let gitignore_path = project_dir.join(".gitignore");
fs::write(&gitignore_path, gitignore)?;
let existing = fs::read_to_string(&gitignore_path).unwrap_or_default();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think greptile is accurate here! please update

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

CodeMan62 and others added 2 commits March 3, 2026 19:18
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@xav-db
xav-db merged commit 4e46111 into HelixDB:dev Mar 3, 2026
6 checks passed
@tika

tika commented Mar 5, 2026

Copy link
Copy Markdown

Thx!

@CodeMan62
CodeMan62 deleted the init-gitignore branch March 5, 2026 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: helix init clears .gitignore

3 participants