Skip to content

Commit 237e529

Browse files
authored
Merge pull request #206 from pjbgf/v5-improvements
v5: Run go-git tests as part of integration tests
2 parents 07f2a0b + 04edb39 commit 237e529

3 files changed

Lines changed: 132 additions & 1 deletion

File tree

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
on:
2+
pull_request:
3+
workflow_dispatch:
4+
5+
name: Go Git Integration
6+
permissions:
7+
contents: read
8+
9+
jobs:
10+
test:
11+
name: ${{ matrix.os }} / Go stable
12+
runs-on: ${{ matrix.os }}
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
os:
17+
- ubuntu-latest
18+
- macos-latest
19+
- windows-latest
20+
defaults:
21+
run:
22+
shell: bash
23+
steps:
24+
- name: Checkout go-billy
25+
uses: actions/checkout@v4
26+
with:
27+
path: go-billy
28+
29+
- name: Select go-git branch
30+
id: target
31+
run: |
32+
set -e
33+
module_path="$(awk '$1 == "module" { print $2 }' go-billy/go.mod)"
34+
35+
case "${module_path}" in
36+
github.com/go-git/go-billy/v6)
37+
go_git_ref="main"
38+
;;
39+
github.com/go-git/go-billy/v5)
40+
go_git_ref="releases/v5.x"
41+
;;
42+
*)
43+
echo "::error::unsupported go-billy module path: ${module_path}"
44+
exit 1
45+
;;
46+
esac
47+
48+
echo "go_billy_module=${module_path}" >> "${GITHUB_OUTPUT}"
49+
echo "go_git_ref=${go_git_ref}" >> "${GITHUB_OUTPUT}"
50+
echo "Testing ${module_path} against go-git ${go_git_ref}"
51+
52+
- name: Checkout go-git
53+
uses: actions/checkout@v4
54+
with:
55+
repository: go-git/go-git
56+
ref: ${{ steps.target.outputs.go_git_ref }}
57+
path: go-git
58+
fetch-depth: 0
59+
60+
- name: Install Go
61+
uses: actions/setup-go@v5
62+
with:
63+
go-version: stable
64+
cache-dependency-path: |
65+
go-billy/go.sum
66+
go-git/**/go.sum
67+
68+
- name: Use local go-billy
69+
run: |
70+
set -e
71+
go_billy_dir="$(cd go-billy && pwd)"
72+
go_git_dir="$(cd go-git && pwd)"
73+
go_billy_module="${{ steps.target.outputs.go_billy_module }}"
74+
75+
if command -v cygpath >/dev/null 2>&1; then
76+
go_billy="$(cygpath -m "${go_billy_dir}")"
77+
go_git="$(cygpath -m "${go_git_dir}")"
78+
else
79+
go_billy="${go_billy_dir}"
80+
go_git="${go_git_dir}"
81+
fi
82+
83+
cd go-git
84+
go_git_module="$(awk '$1 == "module" { print $2 }' go.mod)"
85+
go mod edit -replace "${go_billy_module}=${go_billy}"
86+
go mod tidy
87+
88+
if [ -f cli/go-git/go.mod ]; then
89+
cd cli/go-git
90+
go mod edit -replace "${go_git_module}=${go_git}"
91+
go mod edit -replace "${go_billy_module}=${go_billy}"
92+
go mod tidy
93+
fi
94+
95+
- name: Configure known hosts
96+
continue-on-error: true
97+
if: matrix.os != 'ubuntu-latest'
98+
run: |
99+
mkdir -p ~/.ssh
100+
ssh-keyscan -H github.com > ~/.ssh/known_hosts
101+
102+
- name: Set Git config
103+
run: |
104+
git config --global user.email "gha@example.com"
105+
git config --global user.name "GitHub Actions"
106+
107+
- name: Test go-git
108+
working-directory: go-git
109+
run: go test ./...
110+
111+
- name: Test go-git CLI
112+
if: ${{ hashFiles('go-git/cli/go-git/go.mod') != '' }}
113+
working-directory: go-git/cli/go-git
114+
run: go test ./...

osfs/os_chroot.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ import (
2626
type ChrootOS struct{}
2727

2828
func newChrootOS(baseDir string) billy.Filesystem {
29-
if resolved, err := filepath.EvalSymlinks(baseDir); err == nil {
29+
if baseDir != "" {
30+
resolved, err := filepath.EvalSymlinks(baseDir)
31+
if err != nil {
32+
return chroot.New(&ChrootOS{}, baseDir)
33+
}
3034
baseDir = resolved
3135
}
3236

osfs/os_chroot_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,19 @@ func (s *ChrootOSSuite) TestOpenDoesNotCreateDir(c *C) {
5151
c.Assert(os.IsNotExist(err), Equals, true)
5252
}
5353

54+
func (s *ChrootOSSuite) TestEmptyBaseChrootPreservesAbsolutePath(c *C) {
55+
dir := c.MkDir()
56+
c.Assert(os.Mkdir(filepath.Join(dir, ".git"), 0755), IsNil)
57+
58+
fs, err := newChrootOS("").Chroot(dir)
59+
c.Assert(err, IsNil)
60+
c.Assert(fs.Root(), Equals, dir)
61+
62+
fi, err := fs.Stat(".git")
63+
c.Assert(err, IsNil)
64+
c.Assert(fi.IsDir(), Equals, true)
65+
}
66+
5467
func (s *ChrootOSSuite) TestSymlinkedRoot(c *C) {
5568
root := c.MkDir()
5669
realRoot := filepath.Join(root, "real")

0 commit comments

Comments
 (0)