Skip to content

Commit edffef8

Browse files
committed
fix: address review feedback
1 parent 6ee2cd2 commit edffef8

File tree

3 files changed

+37
-22
lines changed

3 files changed

+37
-22
lines changed

cmd/agent/git_ssh_signature_test.go

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,40 @@ func TestGitSSHSignatureSuite(t *testing.T) {
1919
func (s *GitSSHSignatureTestSuite) TestAcceptsUnknownFlags() {
2020
cmd := NewGitSSHSignatureCmd(&flags.GlobalFlags{})
2121

22-
// Git may pass: -Y sign -n git -f /path/to/key -U /tmp/buffer
23-
// With FParseErrWhitelist, -U is treated as an unknown flag consuming
24-
// /tmp/buffer as its value. This is fine because git always puts the
25-
// buffer file as the last argument. We test with the buffer as a
26-
// separate positional arg (no unknown flag consuming it).
22+
// Git passes: -Y sign -n git -f /path/to/key -U /dev/stdin /tmp/buffer
23+
// -U is an unknown flag that consumes /dev/stdin as its value.
24+
// /tmp/buffer remains as a positional argument.
2725
err := cmd.ParseFlags(
28-
[]string{"-Y", "sign", "-n", "git", "-f", "/path/to/key", "-U", "/tmp/buffer"},
26+
[]string{
27+
"-Y",
28+
"sign",
29+
"-n",
30+
"git",
31+
"-f",
32+
"/path/to/key",
33+
"-U",
34+
"/dev/stdin",
35+
"/tmp/buffer",
36+
},
2937
)
3038
assert.NoError(s.T(), err, "flag parsing should succeed with unknown flag -U")
39+
40+
args := cmd.Flags().Args()
41+
s.Require().NotEmpty(args, "should have positional args")
42+
assert.Equal(s.T(), "/tmp/buffer", args[len(args)-1],
43+
"buffer file should be preserved as last positional arg")
3144
}
3245

3346
func (s *GitSSHSignatureTestSuite) TestBufferFileAsPositionalArg() {
3447
cmd := NewGitSSHSignatureCmd(&flags.GlobalFlags{})
3548

36-
// Standard git invocation: -Y sign -n git -f /path/to/key /tmp/buffer
37-
// The buffer file is the last positional argument.
3849
err := cmd.ParseFlags(
3950
[]string{"-Y", "sign", "-n", "git", "-f", "/path/to/key", "/tmp/buffer"},
4051
)
4152
assert.NoError(s.T(), err)
4253

4354
args := cmd.Flags().Args()
44-
assert.NotEmpty(s.T(), args, "should have positional args")
55+
s.Require().NotEmpty(args, "should have positional args")
4556
assert.Equal(s.T(), "/tmp/buffer", args[len(args)-1],
4657
"last positional arg should be the buffer file")
4758
}
@@ -52,15 +63,14 @@ func (s *GitSSHSignatureTestSuite) TestKnownFlagsParsed() {
5263
err := cmd.ParseFlags(
5364
[]string{"-Y", "sign", "-n", "git", "-f", "/path/to/key", "/tmp/buffer"},
5465
)
55-
assert.NoError(s.T(), err, "flag parsing should succeed")
66+
assert.NoError(s.T(), err)
5667

5768
val, err := cmd.Flags().GetString("command")
5869
assert.NoError(s.T(), err)
5970
assert.Equal(s.T(), "sign", val, "command flag should be 'sign'")
6071

61-
// The buffer file should be the last positional argument
6272
args := cmd.Flags().Args()
63-
assert.NotEmpty(s.T(), args, "should have positional args")
73+
s.Require().NotEmpty(args, "should have positional args")
6474
assert.Equal(s.T(), "/tmp/buffer", args[len(args)-1],
6575
"last positional arg should be the buffer file")
6676
}

cmd/up.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -383,21 +383,27 @@ func (cmd *UpCmd) configureWorkspace(
383383
log.Info("SSH configuration completed in workspace")
384384
}
385385

386-
if cmd.GitSSHSigningKey != "" {
387-
if err := setupGitSSHSignature(cmd.GitSSHSigningKey, client); err != nil {
388-
return err
389-
}
390-
}
391-
392-
return setupDotfiles(
386+
if err := setupDotfiles(
393387
cmd.DotfilesSource,
394388
cmd.DotfilesScript,
395389
cmd.DotfilesScriptEnvFile,
396390
cmd.DotfilesScriptEnv,
397391
client,
398392
devPodConfig,
399393
log,
400-
)
394+
); err != nil {
395+
return err
396+
}
397+
398+
// Run after dotfiles so the signing config isn't overwritten by a
399+
// dotfiles installer that replaces .gitconfig.
400+
if cmd.GitSSHSigningKey != "" {
401+
if err := setupGitSSHSignature(cmd.GitSSHSigningKey, client); err != nil {
402+
return err
403+
}
404+
}
405+
406+
return nil
401407
}
402408

403409
// openIDE opens the configured IDE.

pkg/gitsshsigning/helper.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,7 @@ func isDevpodManagedGpgKey(inGpgSection bool, trimmed string) bool {
196196
if !inGpgSection || len(trimmed) == 0 || trimmed[0] == '[' {
197197
return false
198198
}
199-
return strings.HasPrefix(trimmed, "format = ssh") ||
200-
strings.HasPrefix(trimmed, "program = devpod-ssh-signature")
199+
return strings.HasPrefix(trimmed, "format = ssh")
201200
}
202201

203202
// filterGpgSSHSection removes devpod-managed keys from a buffered [gpg "ssh"]

0 commit comments

Comments
 (0)