# ExternalProject: avoid triggering Git "clean" filter with UPDATE\_COMMAND

**URL:** https://discourse.cmake.org/t/externalproject-avoid-triggering-git-clean-filter-with-update-command/8662
**Category:** Code
**Created:** [August 2, 2023, 3:20pm UTC](https://discourse.cmake.org/t/externalproject-avoid-triggering-git-clean-filter-with-update-command/8662 "2023-08-02T15:20:50Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![scivision](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@scivision](https://discourse.cmake.org/u/scivision)
#### Post date: [August 2, 2023, 3:20pm UTC](https://discourse.cmake.org/t/externalproject-avoid-triggering-git-clean-filter-with-update-command/8662/1 "2023-08-02T15:20:50Z")

</div>

Summary: I want to make the ExternalProject “update” step a simple Git command, so that my user-wide Git filter “clean” is not triggered. The default ExternalProject “update” step triggers Git filter “clean”, which in my case errors the update step.

Does this method seem appropriate? I don’t need the usual ExternalProject generalizations for out-of-build SOURCE\_DIR.

* * *

I have a user-wide ~/.gitconfig that strips Jupyter notebooks using a Git filter like:

```ini
[filter "strip-notebook-output"]
clean = "jupyter nbconvert --ClearOutputPreprocessor.enabled=True --ClearMetadataPreprocessor.enabled=True --to=notebook --stdin --stdout --log-level=ERROR"
smudge = "cat"
required

```

Even if I remove the “required” line, ExternalProject check fails because the filter still edits the .ipynb files at the ExternalProject “update” step. This is of course for a remote project that contains .ipynb files (even though I’m not using them in the CMake project). The Git error is like

```auto
error: Your local changes to the following files would be overwritten by merge:
...
Please commit your changes or stash them before you merge.
Aborting
The stash entry is kept in case you need it again.

```

A workaround I found is:

```cmake
ExternalProject_Add(myproj
...
UPDATE_COMMAND git -C <SOURCE_DIR> checkout --detach "myTag"
)

```

In my project I will always be using a remote Git repo under CMAKE\_BINARY\_DIR with default ExternalProject setings.

I don’t think I need the safeguards that seem aimed at cases where \<SOURCE\_DIR\> is a directory outside of PROJECT\_BINARY\_DIR.

Does this approach seem reasonable?

* * *

Another thing I tried that did NOT work was adding an ExternalProject step:

```cmake
  ExternalProject_Add_Step(myproj gitOverride
    DEPENDERS update
    COMMAND git -C <SOURCE_DIR> config --local filter.strip-notebook-output.clean cat
    COMMENT "CMake ExternalProject: override git config to strip notebook output"
    LOG true
    INDEPENDENT true
)

```

that Step technique would seem like it should work, except it seems ExternalProject subsequently overwrites the file build/myproj-prefix/src/myproj/.git/config.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [August 2, 2023, 5:03pm UTC](https://discourse.cmake.org/t/externalproject-avoid-triggering-git-clean-filter-with-update-command/8662/2 "2023-08-02T17:03:43Z")

</div>

I don’t think there’s a general way to “turn off” filters without `-c` commands to `clone` (as this will also perform a checkout). `git-lfs` has an environment variable to no-op itself. Maybe your filter could be a script that does so around the “real” command?

---

<div class="post-metadata">

### Author: ![scivision](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@scivision](https://discourse.cmake.org/u/scivision)
#### Post date: [August 2, 2023, 7:49pm UTC](https://discourse.cmake.org/t/externalproject-avoid-triggering-git-clean-filter-with-update-command/8662/3 "2023-08-02T19:49:15Z")

</div>

Solution: I made a pre-commit hook instead of a filter, since I only use it on commit. This avoids any changes to CMake script.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [August 3, 2023, 1:49am UTC](https://discourse.cmake.org/t/externalproject-avoid-triggering-git-clean-filter-with-update-command/8662/4 "2023-08-03T01:49:12Z")

</div>

That sounds much better anyways as now everyone gets the “cleaned” output. Thanks for reporting back.
