Skip to content

Commit 18c7435

Browse files
committed
Common http basic auth for git push and lfs
- Also create .lfsconfig if it is not present
1 parent 6d55664 commit 18c7435

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ All notable changes will be documented here.
66

77
- git credential helper for git lfs
88
- Use git cli instead of go-git for fetch/push
9+
- Common http basic auth for both git push and lfs
910
- Refactor wallets
1011

1112
## [v1.4.0] - 2023-02-22

cmd/git-remote-gitopia/gitopia.go

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

33
import (
44
"context"
5+
"encoding/base64"
56
"fmt"
67
"io"
78
"io/ioutil"
@@ -122,6 +123,27 @@ func (h *GitopiaHandler) List(remote *core.Remote, forPush bool) ([]string, erro
122123

123124
out = append(out, fmt.Sprintf("@refs/heads/%s HEAD", h.remoteRepository.DefaultBranch))
124125

126+
if _, err := os.Stat(".lfsconfig"); errors.Is(err, os.ErrNotExist) {
127+
lfsURL := fmt.Sprintf("%v/%v.git", config.GitServerHost, h.remoteRepository.Id)
128+
129+
args := []string{
130+
"config",
131+
"--file=.lfsconfig",
132+
"lfs.url",
133+
lfsURL,
134+
}
135+
136+
cmd, pipe := core.GitCommand("git", args...)
137+
if err := cmd.Start(); err != nil {
138+
return nil, err
139+
}
140+
defer core.CleanUpProcessGroup(cmd)
141+
142+
if _, err := io.Copy(ioutil.Discard, pipe); err != nil {
143+
return nil, err
144+
}
145+
}
146+
125147
return out, nil
126148
}
127149

@@ -232,9 +254,14 @@ func (h *GitopiaHandler) Push(remote *core.Remote, refsToPush []core.RefToPush)
232254
remote.Logger.Println("Please sign the git server request on your ledger device.")
233255
}
234256

257+
credential := fmt.Sprintf("%s:%s", h.wallet.Address(), signature)
235258
args := []string{
236259
"-c",
237-
fmt.Sprintf("http.extraheader=Authorization: Bearer %s", signature),
260+
fmt.Sprintf("http.extraheader=Authorization: Basic %s", base64.StdEncoding.EncodeToString([]byte(credential))),
261+
"-c",
262+
"credential.helper=",
263+
"-c",
264+
"credential.helper=gitopia",
238265
"push",
239266
remoteURL,
240267
fmt.Sprintf("%s:%s", ref.Local, ref.Remote),

0 commit comments

Comments
 (0)