Skip to content

Conversation

@AliSoftware
Copy link
Contributor

@AliSoftware AliSoftware commented Dec 10, 2025

What

Allows to easily use the output in scripts if needed (e.g. pipe that status output through jq, etc)

How

  • Introduce dedicated struct RepositoryStatus object to represent the status reported by git-conceal status
  • Introduce dedicated struct FileStatusList and struct FileStatus objects to represent the status of files list reported by git-conceal status file1 file2 …
  • Make those structs implement both the Serialize trait from the serde crate—to handle JSON serialization (using #[derive(Serialize)] for implicit implementation of it)—and the fmt::Display trait—to handle plain text rendering.
  • Which allows the implementation of cmd_status to build those objects representations regardless of the output format requested, and only at the end decide to println! those results either as JSON (serde_json::to_string_pretty(&status)) or as plain text (print!("{}", status)). (Making the code nicer than if I did giant if / else branches for all the cases)

Testing Instructions

$ export PATH="<path-to-git-conceal-repo>/target/release:$PATH"
$ git-conceal status --json | jq
$ git conceal status --json | jq -r '.encrypted_files[]'
$ git conceal status --json secret.properties | jq
$ git conceal status --json secret.properties foo bar baz | jq '.files | map({key:.file, value:.encrypted}) | from_entries'

src/status.rs Outdated
#[derive(Serialize)]
pub struct RepositoryStatus {
pub repository: String,
pub status: String,
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this can be an enum? Something like:

#[derive(Serialize)]
#[serde(rename_all = "lowercase")] // see https://serde.rs/container-attrs.html#rename_all
pub enum LockStatus {
    Locked,
    Unlocked,
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, I like it 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Implemented in 1427abf

Copy link
Contributor

@iangmaia iangmaia left a comment

Choose a reason for hiding this comment

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

Code looks good 👍 and I ran the test instructions in PCAndroid and it's working as expected :shipit:

@AliSoftware AliSoftware merged commit d116e1b into trunk Dec 11, 2025
4 checks passed
@AliSoftware AliSoftware deleted the status-json branch December 11, 2025 18:21
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.

3 participants