# How to trace through FetchContent code?

**URL:** https://discourse.cmake.org/t/how-to-trace-through-fetchcontent-code/11621
**Category:** Usage
**Created:** [September 9, 2024, 8:40am UTC](https://discourse.cmake.org/t/how-to-trace-through-fetchcontent-code/11621 "2024-09-09T08:40:38Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![tonh](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/t/3bc359/32.png) [@tonh](https://discourse.cmake.org/u/tonh)
#### Post date: [September 9, 2024, 8:40am UTC](https://discourse.cmake.org/t/how-to-trace-through-fetchcontent-code/11621/1 "2024-09-09T08:40:38Z")

</div>

I am debugging an issue where FetchContent instead of checking out a requested branch leaves a repository in a detached HEAD state (where HEAD is pointing to the requested branch though).

To debug this, I am looking at the CMake code FetchContent is executing while performing the update step, and from what I can tell it should do the right thing. I would love to be able to trace through this code, but running my CMake command with `--trace` does not trace through the CMake code of FetchContent unfortunately.

Is it possible to trace the CMake code that is executed by FetchContent?

---

<div class="post-metadata">

### Author: ![tonh](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/t/3bc359/32.png) [@tonh](https://discourse.cmake.org/u/tonh)
#### Post date: [September 9, 2024, 8:49am UTC](https://discourse.cmake.org/t/how-to-trace-through-fetchcontent-code/11621/2 "2024-09-09T08:49:39Z")

</div>

For now I found a crude work-around by adding debug prints to:

“…/Modules/ExternalProject/gitupdate.cmake.in”

relative to the CMake installation share directory.

---

<div class="post-metadata">

### Author: ![tonh](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/t/3bc359/32.png) [@tonh](https://discourse.cmake.org/u/tonh)
#### Post date: [September 9, 2024, 9:49am UTC](https://discourse.cmake.org/t/how-to-trace-through-fetchcontent-code/11621/3 "2024-09-09T09:49:40Z")

</div>

To answer the problem I encountered; FetchContent defaults to checkout `<remote>/GIT_TAG` it seems like, causing the local repository to end up in a detached HEAD state (even in case the local branch points to the same commit). I am still researching whether there is any way to avoid that.
