Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0981842

Browse files
committed
lfsapi: permit accessing context later on
We'll want to access the context that was originally passed to us later on in a future commit, so let's preserve it so we can extract it from our API client.
1 parent 4a784c9 commit 0981842

4 files changed

Lines changed: 15 additions & 9 deletions

File tree

lfsapi/lfsapi.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ type Client struct {
1414

1515
credContext *creds.CredentialHelperContext
1616

17-
client *lfshttp.Client
17+
client *lfshttp.Client
18+
context lfshttp.Context
1819
}
1920

2021
func NewClient(ctx lfshttp.Context) (*Client, error) {
@@ -33,8 +34,13 @@ func NewClient(ctx lfshttp.Context) (*Client, error) {
3334
c := &Client{
3435
Endpoints: NewEndpointFinder(ctx),
3536
client: httpClient,
37+
context: ctx,
3638
credContext: creds.NewCredentialHelperContext(gitEnv, osEnv),
3739
}
3840

3941
return c, nil
4042
}
43+
44+
func (c *Client) Context() lfshttp.Context {
45+
return c.context
46+
}

lfshttp/ssh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (c *sshAuthClient) Resolve(e Endpoint, method string) (sshAuthResponse, err
7979
return res, nil
8080
}
8181

82-
exe, args := ssh.GetLFSExeAndArgs(c.os, c.git, &e.SSHMetadata, endpointOperation(e, method), method)
82+
exe, args := ssh.GetLFSExeAndArgs(c.os, c.git, &e.SSHMetadata, "git-lfs-authenticate", endpointOperation(e, method))
8383
cmd := subprocess.ExecCommand(exe, args...)
8484

8585
// Save stdout and stderr in separate buffers

ssh/ssh.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ func FormatArgs(cmd string, args []string, needShell bool) (string, []string) {
2626
return subprocess.FormatForShellQuotedArgs(cmd, args)
2727
}
2828

29-
func GetLFSExeAndArgs(osEnv config.Environment, gitEnv config.Environment, meta *SSHMetadata, operation, method string) (string, []string) {
29+
func GetLFSExeAndArgs(osEnv config.Environment, gitEnv config.Environment, meta *SSHMetadata, command, operation string) (string, []string) {
3030
exe, args, needShell := GetExeAndArgs(osEnv, gitEnv, meta)
31-
args = append(args, fmt.Sprintf("git-lfs-authenticate %s %s", meta.Path, operation))
31+
args = append(args, fmt.Sprintf("%s %s %s", command, meta.Path, operation))
3232
exe, args = FormatArgs(exe, args, needShell)
3333
tracerx.Printf("run_command: %s %s", exe, strings.Join(args, " "))
3434
return exe, args

ssh/ssh_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ func TestSSHGetLFSExeAndArgs(t *testing.T) {
1919
meta.UserAndHost = "[email protected]"
2020
meta.Path = "user/repo"
2121

22-
exe, args := ssh.GetLFSExeAndArgs(cli.OSEnv(), cli.GitEnv(), &meta, "download", "GET")
22+
exe, args := ssh.GetLFSExeAndArgs(cli.OSEnv(), cli.GitEnv(), &meta, "git-lfs-authenticate", "download")
2323
assert.Equal(t, "ssh", exe)
2424
assert.Equal(t, []string{
2525
"--",
2626
2727
"git-lfs-authenticate user/repo download",
2828
}, args)
2929

30-
exe, args = ssh.GetLFSExeAndArgs(cli.OSEnv(), cli.GitEnv(), &meta, "upload", "GET")
30+
exe, args = ssh.GetLFSExeAndArgs(cli.OSEnv(), cli.GitEnv(), &meta, "git-lfs-authenticate", "upload")
3131
assert.Equal(t, "ssh", exe)
3232
assert.Equal(t, []string{
3333
"--",
@@ -320,7 +320,7 @@ func TestSSHGetLFSExeAndArgsWithCustomSSH(t *testing.T) {
320320
assert.Equal(t, "[email protected]", e.SSHMetadata.UserAndHost)
321321
assert.Equal(t, "repo", e.SSHMetadata.Path)
322322

323-
exe, args := ssh.GetLFSExeAndArgs(cli.OSEnv(), cli.GitEnv(), &e.SSHMetadata, "download", "GET")
323+
exe, args := ssh.GetLFSExeAndArgs(cli.OSEnv(), cli.GitEnv(), &e.SSHMetadata, "git-lfs-authenticate", "download")
324324
assert.Equal(t, "not-ssh", exe)
325325
assert.Equal(t, []string{"-p", "12345", "[email protected]", "git-lfs-authenticate repo download"}, args)
326326
}
@@ -338,7 +338,7 @@ func TestSSHGetLFSExeAndArgsInvalidOptionsAsHost(t *testing.T) {
338338
assert.Equal(t, "-oProxyCommand=gnome-calculator", e.SSHMetadata.UserAndHost)
339339
assert.Equal(t, "repo", e.SSHMetadata.Path)
340340

341-
exe, args := ssh.GetLFSExeAndArgs(cli.OSEnv(), cli.GitEnv(), &e.SSHMetadata, "download", "GET")
341+
exe, args := ssh.GetLFSExeAndArgs(cli.OSEnv(), cli.GitEnv(), &e.SSHMetadata, "git-lfs-authenticate", "download")
342342
assert.Equal(t, "ssh", exe)
343343
assert.Equal(t, []string{"--", "-oProxyCommand=gnome-calculator", "git-lfs-authenticate repo download"}, args)
344344
}
@@ -358,7 +358,7 @@ func TestSSHGetLFSExeAndArgsInvalidOptionsAsHostWithCustomSSH(t *testing.T) {
358358
assert.Equal(t, "--oProxyCommand=gnome-calculator", e.SSHMetadata.UserAndHost)
359359
assert.Equal(t, "repo", e.SSHMetadata.Path)
360360

361-
exe, args := ssh.GetLFSExeAndArgs(cli.OSEnv(), cli.GitEnv(), &e.SSHMetadata, "download", "GET")
361+
exe, args := ssh.GetLFSExeAndArgs(cli.OSEnv(), cli.GitEnv(), &e.SSHMetadata, "git-lfs-authenticate", "download")
362362
assert.Equal(t, "not-ssh", exe)
363363
assert.Equal(t, []string{"oProxyCommand=gnome-calculator", "git-lfs-authenticate repo download"}, args)
364364
}

0 commit comments

Comments
 (0)