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

BUG (Docker): Not a git repository in Docker when running pre-commit hook in docker #20265

Open
jayam04 opened this issue May 5, 2024 · 7 comments
Labels
bug Label to indicate an issue is a regression

Comments

@jayam04
Copy link
Collaborator

jayam04 commented May 5, 2024

Describe the bug

When committing the changes using git commit -m "Message" we are getting the following errors:

Running pre-commit check for feconf and constants ... Traceback (most recent call last): File "./.git/hooks/pre-commit-python", line 229, in <module> main() File "./.git/hooks/pre-commit-python", line 206, in main check_changes_in_config() File "./.git/hooks/pre-commit-python", line 176, in check_changes_in_config if not check_changes('feconf'): File "./.git/hooks/pre-commit-python", line 160, in check_changes diff_output = subprocess.check_output([ File "/usr/local/lib/python3.8/subprocess.py", line 415, in check_output return run(*popenargs, stdout=PIPE, timeout=timeout, check=True, File "/usr/local/lib/python3.8/subprocess.py", line 516, in run raise CalledProcessError(retcode, process.args, subprocess.CalledProcessError: Command '['git', 'diff', 'core/feconf.py']' returned non-zero exit status 129. Python script exited with code 1 docker compose stop

URL of the page where the issue is observed.

N/A

Steps To Reproduce

  1. Change some files
  2. commit changes using git commit -m <message>

Expected Behavior

It should successfully run pre-commit hook inside Docker container.

Screenshots/Videos

No response

What device are you using?

Desktop

Operating System

Other

What browsers are you seeing the problem on?

No response

Browser version

No response

Additional context

This issue is faced by @Shriyam-Avasthi, as is discussed in #20167

Tips for developers

Before addressing the bug, please identify which PR caused the issue (you can follow the steps here). If you identify the PR, comment on the issue with a link to it. If not, mention the commit hash of the oldest commit you saw the bug on (and the month and year it was made in).

Then, please leave a comment with details of the approach that you plan to take to fix the issue (see example).

Note: If this is your first Oppia issue, please make sure to follow our guidelines for choosing an issue and setting things up. You will also need to show a demo of the fix working correctly on your local machine. Thanks!

@jayam04 jayam04 added triage needed bug Label to indicate an issue is a regression labels May 5, 2024
@jayam04
Copy link
Collaborator Author

jayam04 commented May 5, 2024

@Shriyam-Avasthi It's strange .git isn't copied in Docker container, could you please rebuild it by following.

  1. make clean
  2. make build

Also, can you tell in which system this occurred. Also just to check, git diff <file> gives expected output in local environment.
Also could you list files and folders in .git in Docker by running:

  1. make run-devserver
  2. docker compose exec -it dev-server /bin/bash
  3. ls -al .git (it should be run in bash of Docker container)

@Shriyam-Avasthi
Copy link

Shriyam-Avasthi commented May 5, 2024

@jayam04

1. `make clean`

2. `make build`

Already done that, still the bug persists.

Also, can you tell in which system this occurred.

I am using WSL2.

Also just to check, git diff <file> gives expected output in local environment.

git diff core/feconf.py runs without any output, however git diff --staged returns the expected output

image

Also could you list files and folders in .git in Docker by running:

1. `make run-devserver`

2. `docker compose exec -it dev-server /bin/bash`

3. `ls -al .git` (it should be run in bash of Docker container)

image

@jayam04
Copy link
Collaborator Author

jayam04 commented May 6, 2024

@Shriyam-Avasthi I have confirmed bug occurs in WSL, thanks for bringing it. Being busy, I need some time to find proper fix to it. But till then I found temporary solution which you can use, so this issue doesn't stop you from contributing. Please do following:

  1. make run-devserver
  2. docker compose exec -it dev-server /bin/bash
  3. git config --global --add safe.directory /app/oppia (inside Docker container)

Please, reply if solution works or even if you need any further help.

@Shriyam-Avasthi
Copy link

@jayam04
Thank you for helping out. Following your instructions, I am able to commit changes locally. Now, I am facing another issue, running git push leads to frontend tests failed error , whereas if I run the tests using make run_tests.frontend all tests work. I have worked on a very basic fix (just fixing a button) and I dont feel something like that should cause the frontend tests to fail. Here are the terminal outputs for reference:

  • Using git push

image

  • Using make run_tests.frontend

image

Additionally, just to be sure, I went ahead and created another branch and modified only the following piece of code, in essence, just adding a && true condition, which should not lead to any functionality changes. But this also leads to the same frontend test failed error.

    isDiagramCreated(): boolean {
    // This function checks if any shape has been created or not.
    return Boolean(
      !this.isUserDrawing() &&
        this.diagramStatus === this.STATUS_EDITING &&
        this.canvas &&
        this.canvas.getObjects().length > 0
    );
  }

to

    isDiagramCreated(): boolean {
    // This function checks if any shape has been created or not.
    return Boolean(
      !this.isUserDrawing() &&
        this.diagramStatus === this.STATUS_EDITING &&
        this.canvas &&
        this.canvas.getObjects().length > 0 &&
        true
    );
  }

image

@Ari1009
Copy link

Ari1009 commented May 23, 2024

I face the same issue. My OS is Arch Linux with Hyprland. I made a single CSS file change just to test, but when I try to commit it, an error pops up.

> git -c user.useConfigOnly=true commit --quiet --allow-empty-message --file -
Running docker compose exec -T dev-server  python3 ./.git/hooks/pre-commit-python 
time="2024-05-23T17:29:18+05:30" level=warning msg="/run/media/deku09/fad336b5-383a-49f4-805c-1a9a3e3db54e1/lost+found/Contributions/oppia/docker-compose.yml: `version` is obsolete"
[STARTED] Preparing lint-staged...
[FAILED] 
[FAILED] *** Please tell me who you are.
[FAILED] 
[FAILED] Run
[FAILED] 
[FAILED]   git config --global user.email "you@example.com"
[FAILED]   git config --global user.name "Your Name"
[FAILED] 
[FAILED] to set your account's default identity.
[FAILED] Omit --global to set the identity only in this repository.
[FAILED] 
[FAILED] fatal: unable to auto-detect email address (got 'unknown@c14d993fa07f.(none)')
[FAILED] Cannot save the current index state
[STARTED] Running tasks for staged files...
[SKIPPED] Running tasks for staged files...
[STARTED] Applying modifications from tasks...
[SKIPPED] 
[SKIPPED]   ✖ lint-staged failed due to a git error.
[STARTED] Cleaning up temporary files...
[SKIPPED] 
[SKIPPED]   ✖ lint-staged failed due to a git error.

  ✖ lint-staged failed due to a git error.
  Any lost modifications can be restored from a git stash:

    > git stash list
    stash@{0}: automatic lint-staged backup
    > git stash apply --index stash@{0}

Running pre-commit check for feconf and constants ...
Running pre-commit check for package-lock.json ...
Running prettier ...
Traceback (most recent call last):
  File "./.git/hooks/pre-commit-python", line 229, in <module>
    main()
  File "./.git/hooks/pre-commit-python", line 221, in main
    run_prettier()
  File "./.git/hooks/pre-commit-python", line 189, in run_prettier
    subprocess.run('npx lint-staged', shell=True, check=True)
  File "/usr/local/lib/python3.8/subprocess.py", line 516, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command 'npx lint-staged' returned non-zero exit status 1.
Python script exited with code 1

@jayam04
Copy link
Collaborator Author

jayam04 commented May 23, 2024

@Ari1009 Above issue is resolved in #19962 but not yet commited. Could you please update git username and email in Docker Container manually.

You can do it by running:

  1. docker compose exec -T dev-server git config user.name $(git config user.name)
  2. docker compose exec -T dev-server git config user.email $(git config user.email)

@jayam04
Copy link
Collaborator Author

jayam04 commented May 23, 2024

@Ari1009 You mentioned failing pre-push due to frontend tests, could you please tell if you are still facing it or not?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Label to indicate an issue is a regression
Projects
Status: Todo
Development

No branches or pull requests

4 participants