Skip to content
This repository was archived by the owner on Sep 1, 2025. It is now read-only.
This repository was archived by the owner on Sep 1, 2025. It is now read-only.

gitLib is_dirty_worktree #654

Description

@blaggacao

function is_git_repository {
local path="${1}"
git -C "${path}" rev-parse 2> /dev/null
}

  • Complement with an is_dirty_worktree

I figured in some situations one might want to ensure that things are run on a clean dir.

One such use case is:

function ensure_clean_workdir {
  if test -n "$(git status --short)"; then
    critical Please witness deployment from a clean workdir. \
      Commit your local changes first.
  fi
}

(a witness of a deployed state, but this can be moved up the chain and only allow deploys on clean git workdirs in the first place)

/cc @nrdxp

Activity

  1. self-assigned this
    on Sep 30, 2021
  2. kamadorueda commented on Sep 30, 2021

    @kamadorueda
    Contributor

    @blaggacao what about gitignored files ? should they be considered part of the dirty state? git status does not take them into account, but if they exists, they will cause NAR serializations drift on nix-stable

    should we consider a clean worktree one that is: git reset --hard COMMIT && git clean -dffx ?
    the above is exactly equal as cloning the repository from scratch and checking out a given commit

  3. blaggacao commented on Sep 30, 2021

    @blaggacao
    ContributorAuthor

    I'd say that if a gitops engineer deploys any state off of a gitignore file, that engineer is very deliberately shooting himself in the foot (or doesn't know better).

    I currently don't think we need to prevent that type of self harm if minimum gitops ethics is a given.

    The issue here is rather deploying an uncommitted change by mistake (and thereby loosing auditability).

  4. kamadorueda commented on Sep 30, 2021

    @kamadorueda
    Contributor

    Understood,

    my concern was more purity and security. I heard of someone once deploying a file with plain text secrets to a public docker container image. The file was gitignored so that person was not aware of its existence. Other story is, python automatically writes __pycache__ folders when executed, which are also gitignored, and they cause ./path/to/folder hashes to change on Nix stable. Since those folders are "invisible", people normally have bad times debugging why the hash changes

  5. nrdxp commented on Sep 30, 2021

    @nrdxp
    Contributor

    If you use the unstable path, Nix itself already warns you of a dirty worktree, so doing this in makes may become redundant. Then again you can choose to turn that warning off in Nix.

  6. blaggacao commented on Oct 1, 2021

    @blaggacao
    ContributorAuthor

    I heard of someone once deploying a file with plain text secrets to a public docker container image. The file was gitignored so that person was not aware of its existence.

    Oh yeah, I can see that happen. Let's ignore it for is_dirty_worktree, I'd say. Here is why:

    • Here we want to hint a user at: "please commit your changes before proceeding"
    • The other use case, that you bring up is: "do whatever will be done on a pristine checkout"
    • These use cases are slightly different, though often one could wrap the former into the latter. But I can see cases where you genuinely want to say: "please remember to commit your changes first".
    • Let's rename to has_uncommitted_changes, that's less of a misnomer, then.

    If you use the unstable path, Nix itself already warns you of a dirty worktree, so doing this in makes may become redundant. Then again you can choose to turn that warning off in Nix.

    My main used case here is to make a hard stop sign for a run-book and don't let the user get past that point during the control flow of an interactive script.

  7. removed their assignment
    on Oct 4, 2021
  8. added
    help wantedWill be solved only if someone contributes it
    and removed on Oct 4, 2021
  9. moved this to 🆕 New in Makes Roadmapon Sep 24, 2022
  10. moved this from 🆕 New to 📋 To do in Makes Roadmapon Sep 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueNice for a first contributionhelp wantedWill be solved only if someone contributes it

    Type

    No type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions