mirror of
https://github.com/tj/git-extras.git
synced 2026-09-10 07:26:17 -04:00
* feat(mr): support Forgejo/Codeberg pull request URLs Codeberg and other Forgejo instances expose pull requests under refs/pull/<id>/head instead of GitLab's refs/merge-requests/<id>/head, so passing a Codeberg pull request URL to git mr fetched the wrong ref. Recognize the /pulls/<id> URL shape and switch to the matching ref for that case, leaving the GitLab URL and bare numeric id behavior unchanged. Closes #1213 * test(git-mr): cover Forgejo/Codeberg URLs, regenerate man docs Add a bats test that exercises the pulls URL branch via a local insteadOf remote rewrite (no real HTTP endpoint needed), and bring git-mr.1/git-mr.html in line with the git-mr.md changes. --------- Co-authored-by: vjymisal0 <vijay.looprai@gmail.com>
69 lines
1.8 KiB
Bash
69 lines
1.8 KiB
Bash
# shellcheck shell=bash
|
|
|
|
source "$BATS_TEST_DIRNAME/test_util.sh"
|
|
|
|
setup_file() {
|
|
test_util.setup_file
|
|
|
|
PATH="$BATS_TEST_DIRNAME/bin:$PATH"
|
|
}
|
|
|
|
setup() {
|
|
test_util.cd_test
|
|
|
|
test_util.git_init
|
|
touch ./tracked
|
|
git add ./tracked
|
|
git commit -m 'Initial commit'
|
|
|
|
# Local bare "remote" standing in for a real GitLab/Forgejo instance,
|
|
# with a merge-requests ref and a pull ref pointing at the same commit.
|
|
remote_dir="$BATS_TEST_TMPDIR/remote.git"
|
|
git init --bare --initial-branch main "$remote_dir"
|
|
git push "$remote_dir" HEAD:refs/merge-requests/51/head
|
|
git push "$remote_dir" HEAD:refs/pull/51/head
|
|
|
|
git remote add origin "$remote_dir"
|
|
}
|
|
|
|
@test "checks out a merge request by numeric id" {
|
|
run git mr 51
|
|
assert_success
|
|
assert_output --partial "refs/merge-requests/51/head"
|
|
|
|
run git rev-parse --abbrev-ref HEAD
|
|
assert_output 'mr/51'
|
|
|
|
run git config --get branch.mr/51.merge
|
|
assert_output 'refs/merge-requests/51/head'
|
|
}
|
|
|
|
@test "checks out a merge request by numeric id and explicit remote" {
|
|
run git mr 51 "$remote_dir"
|
|
assert_success
|
|
assert_output --partial "refs/merge-requests/51/head"
|
|
|
|
run git rev-parse --abbrev-ref HEAD
|
|
assert_output 'mr/51'
|
|
}
|
|
|
|
@test "checks out a Forgejo/Codeberg pull request by URL" {
|
|
# git-mr only recognizes http(s) URLs, so rewrite the fake Codeberg URL
|
|
# to our local bare "remote" via insteadOf rather than needing a real
|
|
# HTTP(S) endpoint.
|
|
git config --local url."$remote_dir".insteadOf "https://codeberg.org/owner/repository.git"
|
|
|
|
run git mr "https://codeberg.org/owner/repository/pulls/51"
|
|
assert_success
|
|
assert_output --partial "refs/pull/51/head"
|
|
|
|
run git rev-parse --abbrev-ref HEAD
|
|
assert_output 'mr/51'
|
|
|
|
run git config --get branch.mr/51.merge
|
|
assert_output 'refs/pull/51/head'
|
|
|
|
run git config --get branch.mr/51.remote
|
|
assert_output 'https://codeberg.org/owner/repository.git'
|
|
}
|