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

Git submodules doesn't appear in changed files #313

Open
BasixKOR opened this issue Aug 10, 2022 · 7 comments
Open

Git submodules doesn't appear in changed files #313

BasixKOR opened this issue Aug 10, 2022 · 7 comments

Comments

@BasixKOR
Copy link

BasixKOR commented Aug 10, 2022

post-checkout:
  commands:
    update-submodules:
      run: printf '%s\n' {all_files}

I expected the submodules we're using to appear in the {all_files} but it wasn't the case. I think it should display the submodules as well.

@BasixKOR
Copy link
Author

Perhaps the more reliable way to test this could be:

post-checkout:
  commands:
    update-submodules:
      files: git submodule foreach --recursive --quiet 'echo $displaypath' # Assuming it runs on the root
      run: printf '%s\n' {all_files}

@sanmai-NL
Copy link
Contributor

Why? Those are separate Git repositories.

@sanmai-NL
Copy link
Contributor

sanmai-NL commented Dec 6, 2023

Do you mean the submodule directories themselves, or rather the contents of submodules? The latter should be out of scope as I mentioned in my previous reply.

@mrexox I think the changed submodule in the below example called _template is an unstaged change, yet somehow Lefthook skips it as part of the files list.

pre-build:
  commands:
    git_diff_check:
      files: git diff --name-only --staged
      run: git diff --check
    git_staged:
      # This check helps to avoid a situation where fixes were applied and thus Lefthook raises no fault, but those
      # changes weren't committed, and so wouldn't be pushed to the remote.
      fail_text: Staged changes exist in your Git working copy. Please commit or stash them before pushing.
      files: git diff --name-only --staged
      run: git diff --exit-code --name-status --staged
    git_untracked:
      # This check helps to avoid a situation where Lefthook linters succeed because of to an untracked configuration
      # file, and then fail when the repository is cloned without this configuration file.
      fail_text: Untracked changes exist in your Git working copy. Please remove or index them before pushing.
      files: git ls-files --exclude-standard --others
      run: exit 9
    git_unstaged:
      # This check helps to avoid a situation where fixes were applied and thus Lefthook raises no fault, but those
      # changes weren't committed, and so wouldn't be pushed to the remote.
      fail_text: Unstaged changes exist in your Git working copy. Please commit or stash them before pushing.
      files: git diff --name-only
      run: git diff --exit-code --name-status -- {files}
$ lefthook run pre-build --commands git_staged,git_untracked,git_unstaged -vvvvv
│ [lefthook] cmd: [git rev-parse --show-toplevel]
│ [lefthook] dir: 
│ [lefthook] err: <nil>
│ [lefthook] out: /Users/bla/repo
                                                                                                    
│ [lefthook] cmd: [git rev-parse --git-path hooks]
│ [lefthook] dir: 
│ [lefthook] err: <nil>
│ [lefthook] out: .git/hooks
                          
│ [lefthook] cmd: [git rev-parse --git-path info]
│ [lefthook] dir: 
│ [lefthook] err: <nil>
│ [lefthook] out: .git/info
                         
│ [lefthook] cmd: [git rev-parse --git-dir]
│ [lefthook] dir: 
│ [lefthook] err: <nil>
│ [lefthook] out: .git
                    
╭─────────────────────────────────────╮
│ 🥊 lefthook v1.5.5  hook: pre-build │
╰─────────────────────────────────────╯
│ [lefthook] cmd: [sh -c git diff --name-only --staged]
│ [lefthook] cmd: [sh -c git ls-files --exclude-standard --others]
│ [lefthook] cmd: [sh -c git diff --name-only]
│ [lefthook] dir: /Users/bla/repo
│ [lefthook] err: <nil>
│ [lefthook] out: 
│  git_untracked (skip) no files for inspection
│ [lefthook] dir: /Users/bla/repo
│ [lefthook] err: <nil>
│ [lefthook] out: pdm.lock
pyproject.toml          
                        
│ [lefthook] files before filters:
[pdm.lock pyproject.toml]       
│ [lefthook] files after filters:
[pdm.lock pyproject.toml]      
│ [lefthook] dir: /Users/bla/repo
│ [lefthook] err: <nil>
│ [lefthook] out: _template
                         
│  git_unstaged (skip) no files for inspection
┃  git_staged ❯ 

M       pdm.lock
M       pyproject.toml

                                      
  ────────────────────────────────────
summary: (done in 0.01 seconds)       
🥊  git_staged: Staged changes exist in your Git working copy. Please commit or stash them before pushing.
bla@device:/Users/bla/repo
  git status
On branch main
Your branch is up to date with 'origin/main'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   pdm.lock
        modified:   pyproject.toml

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
  (commit or discard the untracked or modified content in submodules)
        modified:   _template (modified content)

@BasixKOR
Copy link
Author

BasixKOR commented Dec 6, 2023

Do you mean the submodule directories themselves

I meant the former, as I wanted to track whether the submodules are updated in the commit and verify the submodule was pointing to a valid branch (based on internal release policy).

@avudnez
Copy link

avudnez commented Feb 22, 2024

I also wanted to detect submodule changes and expected it to be listed in lefthook's {staged_files} for example.

@mrexox
Copy link
Member

mrexox commented Apr 9, 2024

Do you also expect lefthook to call the hooks of a submodule? Like parsing the lefthook config of a submodule and executing its hooks?

@avudnez
Copy link

avudnez commented Apr 9, 2024

Not in my case, I only need to be notified that the submodule is dirty.

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

4 participants