gitLib is_dirty_worktree #654

Open
opened 2021-09-30 04:53:10 +02:00 by blaggacao · 5 comments
blaggacao commented 2021-09-30 04:53:10 +02:00 (Migrated from github.com)

github.com/fluidattacks/makes@874fb8ca2e/src/args/lib-git/template.sh (L3-L7)

  • 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

https://github.com/fluidattacks/makes/blob/874fb8ca2eb28e60f5b51b8526d9616cfa624fb2/src/args/lib-git/template.sh#L3-L7 - 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
kamadorueda commented 2021-09-30 20:07:07 +02:00 (Migrated from github.com)

@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

@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
blaggacao commented 2021-09-30 20:51:17 +02:00 (Migrated from github.com)

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).

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).
kamadorueda commented 2021-09-30 21:14:31 +02:00 (Migrated from github.com)

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

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
nrdxp commented 2021-09-30 21:23:06 +02:00 (Migrated from github.com)

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.

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.
blaggacao commented 2021-10-01 17:22:09 +02:00 (Migrated from github.com)

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.

> 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.
This discussion has been locked. Commenting is limited to contributors.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
justin/makes#654
No description provided.