Issue with fetching the latest PR commits

There seems to be an intermittent issue while fetching the latest commits of a PR. I tried a couple of methods, but both fail intermittently. 

Method 1:

git clone --depth 1 https://github.com/qawoody/welcome-pipelines.git welcome-pipelines
cd welcome-pipelines
git checkout -b master-tmp
git fetch --force --depth 1 origin "pull/4/merge:master"
git checkout master
git log --pretty=oneline

Method 2:

git clone --depth 50 https://github.com/qawoody/welcome-pipelines.git welcome-pipelines
cd welcome-pipelines
git fetch origin +refs/pull/4/merge:
git checkout -qf FETCH_HEAD
git log --pretty=oneline

In both the cases, you will observe that the merged branch doesn’t have the latest commits. Observing this issue from the past week.

Can someone help me on this? Or did anyone face this problem?

PS: The above-mentioned repository is an example public repo. I am facing this with many other repositories. 

Thanks

Thanks for asking!

It looks like you’re trying to get the latest commits on a PR by fetching the merge ref for the PR. Unfortunately, while the existence of the PR refs is well-known, we don’t make any guarantees about their operation. When a PR is updated, the merge ref is updated lazily and some changes may have happened in the last week that have made it update more lazily than in the past.

What is your ultimate goal here? Would using the GitHub API be a more reliable way of getting the information you’re looking for?

2 Likes

@lee-dohm Thanks for the reply.

The goal is to pull the latest changes of a PR and build (CI similar to Travis CI). We have webhooks attached to the repo, which triggers builds on push/PR commits.

Could you please tell me if there is a recommended way to get a PR’s latest changes? (into a temporary branch)

@vamche wrote:

Could you please tell me if there is a recommended way to get a PR’s latest changes? (into a temporary branch)

For that, you can see my answer on this other topic. You’ll notice that it uses the head ref instead of the merge ref.

@lee-dohm Thank you. Using head ref solved the issue.