-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible to checkout the whole history since the branch creation? #266
Comments
If you set the input You can then use Does that help? If not can you provide more information about the scenario? |
I was able to do it yesterday sometime after my question. Just describing my scenario a little bit better. I wanted to clone the whole branch history because I want to use this, to generate visual diffs from the beginning of the branch creation and the latest commit of the branch. So reviewers can have this info easily when they have to review printed circuit boards. |
It would be nice to fetch just the commits being proposed in a given pull request. Fetching the entire repo history can be quite slow/expensive. Git lets you clone just the commits between a branch git clone --shallow-exclude master --single-branch --branch branch git@github.com:<org>/<repo>.git Might make sense to reopen this issue to track exposing that functionality in this action. A related, combination of steps I've used to have the PR base and head available (but none of the interceding history) is:
That's enough to do e.g. It would be nicei if actions/checkout streamlined this multi-ref use-case (perhaps in a Some of these common patterns could even merit their own top-level flags (just the PR history, just the PR endpoints, just the PR head without the merge, etc.). |
@ryan-williams Can I use something like your command to initialize submodules behind a private repo? I was not able to achieve this so far. |
This will fetch the PR branch commits and one more commit (the commit on the base branch that the PR branched from (eg: - name: 'PR commits + 1'
run: echo "PR_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> "${GITHUB_ENV}"
- name: 'Checkout PR branch and all PR commits'
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: ${{ env.PR_FETCH_DEPTH }} NOTE: If the PR had merge commits from the base branch into the PR branch, those are included and the fetch depth will also continue to fetch remaining N depth commits from both parents of the merge commit (the base branch at that point and the PR branch). The ref was set to the PR head ref, which will point to the last commit listed for that PR. The default is a test merge-commit that Github generates of the PR branch merging into the base branch, which is probably not what you'd want/expect if trying to fetch only the commit history for the PR branch. Likewise, ignore the prior step to set an ENV for
This is quite neat, but I noticed when a merge commit from base branch to PR branch exists in the history it'll stop from that point. So if that was the last commit in the PR history (eg, a maintainer did this via Github PR web UI button), then you have a single commit. Might not be as useful. It is neat for finding how many commits the branch has if it was branched off the excluded branch (or that branch was merged into it):
You can use the github context to get how many commits belong to the PR, fetch that depth + 1, like shown above. Then a When a merge commit from base branch into PR branch occurs, the
Just to clarify, the base ref is not the first commit of the PR (nor the commit on the base branch that the PR branched from), it is the ref to the base branch. So the commit you fetch may be newer than the one you branched off from. There is also the ref You could instead take the default ref of the generated test merge commit of PR branch into base branch, since the outcome would be the same in your example with the base ref. With No need to specify the refs then, the merge commit itself is Example for comparing branches (eg: PR to master, files that have added/modified changes): - name: 'Checkout PR branch (with test merge-commit)'
uses: actions/checkout@v3
with:
fetch-depth: 2
- name: 'Get a list of changed files to process'
run: git diff-tree --name-only --diff-filter 'AM' -r HEAD^1 HEAD As we're comparing two commits with direct before/after diff, this works well. NOTE: If you attempted to do so with the other commit that was fetched (the HEAD sha/ref commit from the PR branch), you'd not be able to derive a merge-base, and without that you'd potentially get different diff output than the example above. One scenario of that problem occurs if the base branch has since deleted a file that the PR branch has in it's history (but the PR branch left alone), a diff between those two commits would suggest that the file has been added by the PR commit. This won't happen with the merge commit diff (which was done with a merge base by Github).
This would run into the issue I mentioned comparing the two commits, instead of the base commit with the default test merge-commit. I don't think the range notation You'd also potentially miss files due to lack of The |
Hello, is it possible to checkout the whole history since the branch creation?
If, yes. How can I do it?
The text was updated successfully, but these errors were encountered: