Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detection of clean repo is not reliable. #37

Closed
mrmachine opened this issue Mar 10, 2017 · 10 comments
Closed

Detection of clean repo is not reliable. #37

mrmachine opened this issue Mar 10, 2017 · 10 comments

Comments

@mrmachine
Copy link

I'm using codefresh to build Docker images (including the .git directory), with an entrypoint script that configures the git repo for transcrypt with a password from the environment, to decrypt secret files at runtime.

transcrypt thinks the git repo is dirty:

# transcrypt -c "${TRANSCRYPT_CIPHER:-aes-256-cbc}" -p "$TRANSCRYPT_PASSWORD" -y
transcrypt: the repo is dirty; commit or stash your changes before running transcrypt

When I run the git diff-index command that transcrypt uses internally (minus the --quiet arg), it seems to return some odd results:

# git diff-index HEAD -- | tail                                                                                                   
:100644 100644 3d6e0e93c2bfef67162836b2f0b5ad24c526929e 0000000000000000000000000000000000000000 M      staticroot/apple-touch-icon-precomposed.png        
:100644 100644 9089ef7ffea1efe2de79b49b5e6a5856360de4d6 0000000000000000000000000000000000000000 M      staticroot/apple-touch-icon.png                    
:100644 100644 7b74f8caf013ba164ca9049f7bd4eea0555ff720 0000000000000000000000000000000000000000 M      staticroot/favicon.ico                             
:100644 100644 5d00a90141a920a278e2a8239e560b7ea395a1db 0000000000000000000000000000000000000000 M      staticroot/humans.txt                              
:100644 100644 214e4119653f9c6a4c48cd0ebb06a6754f00f62b 0000000000000000000000000000000000000000 M      staticroot/robots.txt                              

But the repo is clean, cloned and built by codefresh:

# git status                                                                                                                      
HEAD detached at 153c57c                                                                                                                                   
nothing to commit, working directory clean                                                                                                                 

Strangely, after running git status, transcrypt suddenly agrees that the repo is clean and agrees to configure the repo:

# git diff-index HEAD -- | tail                                                                                                   

# transcrypt -c "${TRANSCRYPT_CIPHER:-aes-256-cbc}" -p "$TRANSCRYPT_PASSWORD" -y
The repository has been successfully configured by transcrypt.                                                                                             

Is there something wrong with the way codefresh is cloning the repo before it builds the Docker image?

Is there a more reliable way transcrypt can detect a dirty repo (as reported by git status)?

@elasticdog
Copy link
Owner

I wonder if there is some stale stat info from whatever codefresh is doing. Instead of running git status, if you touch all of the encrypted files, does the clean check work as expected?

cd $(git rev-parse --show-toplevel)
touch $(git ls-crypt)

@dfee
Copy link

dfee commented Sep 3, 2017

I've experienced the same thing using CircleCI. I solved it by doing a git reset --hard HEAD even though when I'd ssh'ed in, git status returned nothing to commit, working directory clean

@andreineculau
Copy link
Collaborator

andreineculau commented Nov 26, 2020

Hate to do a +1, but I'm now experiencing this when running WSL on Windows on Github Actions.

LATER EDIT
It is just mesmerizing how running git status before decrypting can workaround the situation 🤔

Explanations:

LATER LATER EDIT
As per SO, I used git update-index -q --really-refresh instead of git status, etc.

@jmurty
Copy link
Collaborator

jmurty commented Nov 26, 2020

Hmm, is there any reason we shouldn't apply the naïve but simple "fix" and always run git update-index -q --really-refresh or git status before checking for a clean repository?

It would be weird voodoo, but should at least solve the problem.

@andreineculau
Copy link
Collaborator

It's not really voodoo :) after you read the tiny details, that is.... sigh it's just that diff-index gives you a probabilistic view of the world, not a binary one that's all. So if we want to stick to diff-index, then we need update-index. Otherwise we can use a higher-level git command like git status that gives you a binary answer.

@andreineculau
Copy link
Collaborator

for example, have a look at how the git bash prompt detects dirty state
https://github.com/git/git/blob/e31aba42fb12bdeb0f850829e008e1e3f43af500/contrib/completion/git-prompt.sh#L527-L528

jmurty added a commit that referenced this issue Feb 3, 2021
Should fix/avoid failures seen in CI systems where the repo seems
dirty when it really isn't.
@jmurty
Copy link
Collaborator

jmurty commented Feb 3, 2021

Hi @andreineculau it's been a while sorry, but I have created a pull request with a potential fix to more reliably detect dirty repositories, without false positives. It would be great if you could look over it or test it: #109

@andreineculau
Copy link
Collaborator

Well, I have already implemented this in ysoftwareab/yplatform@4834b27 (basically just for my usecase of WSL in CI) and it does work. I'd be surprised if your fix gives degraded outcome.

I'm currently not able to test this, but it's a +1 from me.

@jmurty
Copy link
Collaborator

jmurty commented Feb 6, 2021

Hi @mrmachine @dfee and anyone else watching this issue, could someone test and confirm the potential fix for detection of dirty repos in pull request #109?

jmurty added a commit that referenced this issue Apr 26, 2021
Should fix/avoid failures seen in CI systems where the repo seems
dirty when it really isn't.
@jmurty
Copy link
Collaborator

jmurty commented Apr 26, 2021

With the merge of #109 this issue should now be fixed. Please re-open if dirty repo detection is still failing for you when using the latest transcrypt from the master branch.

@jmurty jmurty closed this as completed Apr 26, 2021
jmurty added a commit that referenced this issue Apr 29, 2021
* main:
  Remove Ubuntu 16.04 LTS from test matrix (#123)
  Configure default Git branch name for macOS tests in GitHub
  Handle rename of primary branch from "master" to "main"
  Ensure Git index is up-to-date before dirty repo  check #37 (#109)
jmurty added a commit that referenced this issue Jan 15, 2022
* main:
  Improve command hint to fix secret files not encrypted in index (#120) (#130)
  Remove Ubuntu 16.04 LTS from test matrix (#123)
  Configure default Git branch name for macOS tests in GitHub
  Handle rename of primary branch from "master" to "main"
  Ensure Git index is up-to-date before dirty repo  check #37 (#109)
  Fix incorrect salt when partially staged files are commited (#119)
  Use shorthand for grep options for broader compatibility (#121)
jmurty added a commit that referenced this issue Oct 15, 2022
# By James Murty (18) and others
# Via GitHub (1) and James Murty (1)
* main: (26 commits)
  Centralise load and save of password into functions #141
  Fix date of 2.2.0 release
  Ensure tests use "main" as default branch name #143
  Use OpenSSL for B64 encoding not `base64` which differs between Linux and Mac #140
  Use core attributesFile from worktree (#137)
  Document `xxd` requirement, and make optional with OpenSSL < 3 (#138)
  Prepare for 2.2.0 release
  Fix when using OpenSSL 3 which no longer embeds salt in output (#135)
  Consolidate all git operation scripts into a single transcrypt script
  Fix handling of small files and files with null in first 8 bytes (#116)
  Improve command hint to fix secret files not encrypted in index (#120) (#130)
  Remove Ubuntu 16.04 LTS from test matrix (#123)
  Configure default Git branch name for macOS tests in GitHub
  Handle rename of primary branch from "master" to "main"
  Ensure Git index is up-to-date before dirty repo  check #37 (#109)
  Fix incorrect salt when partially staged files are commited (#119)
  Use shorthand for grep options for broader compatibility (#121)
  Let user set a custom path to openssl #108
  Install entire transcrypt script into repository
  Change version to indicate development "pre-release" status
  ...

# Conflicts:
#	README.md
#	tests/_test_helper.bash
#	tests/test_cleanup.bats
#	tests/test_crypt.bats
#	tests/test_init.bats
#	tests/test_not_inited.bats
#	transcrypt
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

No branches or pull requests

5 participants