Skip to content

Commit f9c1d63

Browse files
Update should accept empty path with version (#2572)
1 parent bc04a55 commit f9c1d63

File tree

3 files changed

+60
-5
lines changed

3 files changed

+60
-5
lines changed

internal/cmdupdate/cmdupdate_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,55 @@ func TestCmd_successNoGit(t *testing.T) {
229229
}
230230
}
231231

232+
func TestCmd_onlyVersionAsInput(t *testing.T) {
233+
g, w, clean := testutil.SetupRepoAndWorkspace(t, testutil.Content{
234+
Data: testutil.Dataset1,
235+
Branch: "master",
236+
})
237+
defer clean()
238+
239+
err := os.RemoveAll(".git")
240+
if !assert.NoError(t, err) {
241+
t.FailNow()
242+
}
243+
dest := filepath.Join(w.WorkspaceDirectory, g.RepoName)
244+
245+
// clone the repo
246+
getCmd := cmdget.NewRunner(fake.CtxWithDefaultPrinter(), "kpt")
247+
getCmd.Command.SetArgs([]string{"file://" + g.RepoDirectory + ".git", w.WorkspaceDirectory})
248+
err = getCmd.Command.Execute()
249+
if !assert.NoError(t, err) {
250+
return
251+
}
252+
if !g.AssertEqual(t, filepath.Join(g.DatasetDirectory, testutil.Dataset1), dest, true) {
253+
return
254+
}
255+
256+
// update the master branch
257+
if !assert.NoError(t, g.ReplaceData(testutil.Dataset2)) {
258+
return
259+
}
260+
261+
// commit the upstream but not the local
262+
_, err = g.Commit("new dataset")
263+
if !assert.NoError(t, err) {
264+
return
265+
}
266+
267+
// update the cloned package
268+
updateCmd := cmdupdate.NewRunner(fake.CtxWithDefaultPrinter(), "kpt")
269+
defer testutil.Chdir(t, dest)()
270+
updateCmd.Command.SetArgs([]string{"@master"})
271+
err = updateCmd.Command.Execute()
272+
if !assert.NoError(t, err) {
273+
t.FailNow()
274+
}
275+
276+
if !g.AssertEqual(t, filepath.Join(g.DatasetDirectory, testutil.Dataset2), dest, true) {
277+
return
278+
}
279+
}
280+
232281
// NoOpRunE is a noop function to replace the run function of a command. Useful for testing argument parsing.
233282
var NoOpRunE = func(cmd *cobra.Command, args []string) error { return nil }
234283

internal/util/argutil/argutil.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,13 @@ func ParseFieldPath(path string) ([]string, error) {
9494
func ResolveSymlink(ctx context.Context, path string) (string, error) {
9595
isSymlink := false
9696
f, err := os.Lstat(path)
97-
if err != nil {
98-
return "", err
99-
}
100-
if f.Mode().Type() == os.ModeSymlink {
101-
isSymlink = true
97+
if err == nil {
98+
// this step only helps with printing WARN message by checking if the input
99+
// path has symlink, so do not error out at this phase and let
100+
// filepath.EvalSymlinks(path) handle the cases
101+
if f.Mode().Type() == os.ModeSymlink {
102+
isSymlink = true
103+
}
102104
}
103105
rp, err := filepath.EvalSymlinks(path)
104106
if err != nil {

internal/util/argutil/argutil_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ func TestResolveSymlink(t *testing.T) {
144144
assert.NoError(t, err)
145145
assert.Equal(t, "foo", actual2)
146146

147+
actual3, err := ResolveSymlink(fake.CtxWithDefaultPrinter(), ".")
148+
assert.NoError(t, err)
149+
assert.Equal(t, ".", actual3)
150+
147151
_, err = ResolveSymlink(fake.CtxWithDefaultPrinter(), "baz")
148152
assert.Error(t, err)
149153
assert.Equal(t, "lstat baz: no such file or directory", err.Error())

0 commit comments

Comments
 (0)