# FetchContent\_MakeAvailable fails if Git repository is deleted

**URL:** https://discourse.cmake.org/t/fetchcontent-makeavailable-fails-if-git-repository-is-deleted/4538
**Category:** Usage
**Tags:** os:linux
**Created:** [November 23, 2021, 10:55pm UTC](https://discourse.cmake.org/t/fetchcontent-makeavailable-fails-if-git-repository-is-deleted/4538 "2021-11-23T22:55:49Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![developer](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/d/bcef8e/32.png) [@developer](https://discourse.cmake.org/u/developer)
#### Post date: [November 23, 2021, 10:55pm UTC](https://discourse.cmake.org/t/fetchcontent-makeavailable-fails-if-git-repository-is-deleted/4538/1 "2021-11-23T22:55:49Z")

</div>

I am using `FetchContent` like below

```auto
FetchContent_Declare(
    foo
    GIT_REPOSITORY n ssh://foo-url
    GIT_TAG 1.0.1
    GIT_SHALLOW TRUE
    SOURCE_DIR $ENV{HOME}/foo
)

FetchContent_MakeAvailable(foo)

```

If I explicitly delete foo (`rm -rf ~/foo`). And re-configure or delete cache and reconfigure, I get the following error…

```auto
[cmake] [11%] Performing update step for 'foo-populate'
[cmake] CMake Error at /home/vagrant/cmake_external_dependencies/foo-subbuild/foo-populate-prefix/tmp/foo-populate-gitupdate.cmake:25 (message):
[cmake] Failed to get the hash for HEAD:
[cmake] 
[cmake] fatal: not a git repository (or any parent up to mount point /home)
[cmake] 
[cmake] Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

```

I’ve found my only option at this point is to delete the entire build directory (or specifically the `foo-subbuild` directory). Do I have any options here? Or is this the expected behavior? I would’ve perhaps thought that FetchContent would’ve been able to realize the repo no longer exists and re-clone it like it does on first configuration.

---

<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: [November 24, 2021, 2:40am UTC](https://discourse.cmake.org/t/fetchcontent-makeavailable-fails-if-git-repository-is-deleted/4538/2 "2021-11-24T02:40:32Z")

</div>

It sounds like there’s some missing sanity check here before trying to actually use the source directory. I wonder if the `SOURCE_DIR` combined with `GIT_*` is the cause (as I’ve not seen this with just `GIT_*` arguments).

Cc: @craig.scott

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [November 24, 2021, 8:38pm UTC](https://discourse.cmake.org/t/fetchcontent-makeavailable-fails-if-git-repository-is-deleted/4538/3 "2021-11-24T20:38:53Z")

</div>

FetchContent and ExternalProject both use timestamps to work out whether some individual steps have been completed. In general, it isn’t safe to delete things as described in the original post. If you do want to delete parts, then you are also responsible for deleting any associated timestamps. Those are internal implementation details though, we don’t document how those timestamps are used. We do expose some degree of control over _where_ those timestamps go (see the mention of `STAMP_DIR` in the ExternalProject docs), but not how they are used (and I don’t see that changing because we want the flexibility to change how they are used internally).

---

<div class="post-metadata">

### Author: ![developer](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/d/bcef8e/32.png) [@developer](https://discourse.cmake.org/u/developer)
#### Post date: [December 1, 2021, 10:52pm UTC](https://discourse.cmake.org/t/fetchcontent-makeavailable-fails-if-git-repository-is-deleted/4538/4 "2021-12-01T22:52:40Z")

</div>

I’ve decided to trial CPM.cmake for the time being. Thank you for the response.
