lefthook icon indicating copy to clipboard operation
lefthook copied to clipboard

Git submodules doesn't appear in changed files

Open BasixKOR opened this issue 2 years ago • 7 comments

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 avatar Aug 10 '22 08:08 BasixKOR

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}

BasixKOR avatar Aug 10 '22 08:08 BasixKOR

Why? Those are separate Git repositories.

sanmai-NL avatar Oct 12 '23 12:10 sanmai-NL

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)

sanmai-NL avatar Dec 06 '23 12:12 sanmai-NL

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

BasixKOR avatar Dec 06 '23 13:12 BasixKOR

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

avudnez avatar Feb 22 '24 13:02 avudnez

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

mrexox avatar Apr 09 '24 12:04 mrexox

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

avudnez avatar Apr 09 '24 12:04 avudnez