I'm on a CI box running tests. To speed it up, I'm just doing a shallow clone:
git clone --depth 1 git@github.com:JoshCheek/some_repo.git
Assuming all the tests pass, I want to trigger the next step in the pipeline. What to trigger is based on which files changed between the last deployment (ref d123456
) and the current ref I just tested (ref c123456
). If I had done a normal clone, I could find out like this this:
git diff --name-only d123456 c123456
But my clone is shallow, so it doesn't know about those commits. I see that I can use git fetch --depth=n
to get more of the history, but I only know the SHA, not the depth of the SHA. Here's a set of ways that could presumably answer this question:
# hypothetical remote diff
git diff --name-only origin/d123456 origin/c123456
# hypothetical ref based fetch
git fetch --shallow-through d123456
git diff --name-only d123456 c123456
# hypothetical way to find the depth I need
depth=`git remote depth-to d123456`
git fetch --depth "$depth"
git diff --name-only d123456 c123456
Otherwise it seems like I might have to write a loop and keep invoking --deepen
until my history contains the commit. That seems painful (meaning annoying to write / maintain) and expensive (meaning slow, remember that the purpose of the shallow clone is to reduce this cost).