Skip to content

Commit acfad6f

Browse files
Merge pull request #4: git-bundle-server CLI 3: Cleanups and builds
* Consolidate Git executable creation so we can use the `LC_CTYPE=C` environment variable universally. * Modify how `go.mod` files work as well as set up automated builds to verify things compile. I _really struggled_ to figure out how all this module stuff works, so I probably messed it up in some way. However, it builds locally _and_ builds in the GitHub Actions build, so that's a start.
2 parents b10b284 + 897b77a commit acfad6f

File tree

13 files changed

+100
-27
lines changed

13 files changed

+100
-27
lines changed

.github/workflows/main.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- name: Setup Go
11+
uses: actions/setup-go@v3
12+
with:
13+
go-version: '1.19.0'
14+
15+
- uses: actions/checkout@v2
16+
with:
17+
path: src/git-bundle-server
18+
19+
- name: Build
20+
run: |
21+
cd $GITHUB_WORKSPACE/src/git-bundle-server
22+
GOPATH="$GITHUB_WORKSPACE/../../" go build ./cmd/git-bundle-server
23+
24+
- name: Check style
25+
run: |
26+
cd $GITHUB_WORKSPACE/src/git-bundle-server
27+
GOPATH="$GITHUB_WORKSPACE/../../" go vet ./cmd/git-bundle-server
28+
29+
# TODO: add automated tests.

cmd/git-bundle-server/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/github/git-bundle-server/cmd/git-bundle-server
2+
3+
go 1.19

cmd/git-bundle-server/init.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package main
33
import (
44
"errors"
55
"fmt"
6-
"git-bundle-server/internal/bundles"
7-
"git-bundle-server/internal/core"
8-
"git-bundle-server/internal/git"
6+
7+
"github.com/github/git-bundle-server/internal/bundles"
8+
"github.com/github/git-bundle-server/internal/core"
9+
"github.com/github/git-bundle-server/internal/git"
910
)
1011

1112
type Init struct{}
@@ -29,12 +30,22 @@ func (Init) run(args []string) error {
2930
}
3031

3132
fmt.Printf("Cloning repository from %s\n", url)
32-
gitErr := git.GitCommand("clone", "--mirror", url, repo.RepoDir)
33+
gitErr := git.GitCommand("clone", "--bare", url, repo.RepoDir)
3334

3435
if gitErr != nil {
3536
return fmt.Errorf("failed to clone repository: %w", gitErr)
3637
}
3738

39+
gitErr = git.GitCommand("-C", repo.RepoDir, "config", "remote.origin.fetch", "+refs/heads/*:refs/heads/*")
40+
if gitErr != nil {
41+
return fmt.Errorf("failed to configure refspec: %w", gitErr)
42+
}
43+
44+
gitErr = git.GitCommand("-C", repo.RepoDir, "fetch", "origin")
45+
if gitErr != nil {
46+
return fmt.Errorf("failed to fetch latest refs: %w", gitErr)
47+
}
48+
3849
bundle := bundles.CreateInitialBundle(repo)
3950
fmt.Printf("Constructing base bundle file at %s\n", bundle.Filename)
4051

cmd/git-bundle-server/update-all.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package main
22

33
import (
44
"fmt"
5-
"git-bundle-server/internal/core"
65
"os"
76
"os/exec"
7+
8+
"github.com/github/git-bundle-server/internal/core"
89
)
910

1011
type UpdateAll struct{}

cmd/git-bundle-server/update.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ package main
33
import (
44
"errors"
55
"fmt"
6-
"git-bundle-server/internal/bundles"
7-
"git-bundle-server/internal/core"
6+
7+
"github.com/github/git-bundle-server/internal/bundles"
8+
"github.com/github/git-bundle-server/internal/core"
89
)
910

1011
type Update struct{}

doc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package docs

go.mod

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1-
module git-bundle-server
1+
module github.com/github/git-bundle-server
22

3-
go 1.18
3+
go 1.19
4+
5+
require (
6+
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
7+
golang.org/x/tools v0.1.12 // indirect
8+
)

go.work

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
go 1.18
2+
3+
use (
4+
./cmd/git-bundle-server/
5+
./internal/bundles/
6+
./internal/core/
7+
./internal/git/
8+
)

internal/bundles/bundles.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import (
44
"bufio"
55
"encoding/json"
66
"fmt"
7-
"git-bundle-server/internal/core"
8-
"git-bundle-server/internal/git"
97
"os"
108
"sort"
119
"strconv"
1210
"strings"
1311
"time"
12+
13+
"github.com/github/git-bundle-server/internal/core"
14+
"github.com/github/git-bundle-server/internal/git"
1415
)
1516

1617
type BundleHeader struct {

internal/bundles/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module github.com/github/git-bundle-server/internal/bundles
22

3-
go 1.18
3+
go 1.19

0 commit comments

Comments
 (0)