Fix #1407: Make 'kpt pkg get' use current directory when '.' is specified#4334
Fix #1407: Make 'kpt pkg get' use current directory when '.' is specified#4334ciaranjohnston wants to merge 7 commits intomainfrom
Conversation
✅ Deploy Preview for kptdocs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
b8ecd88 to
e2529dc
Compare
e2529dc to
5616f86
Compare
There was a problem hiding this comment.
Pull request overview
Adjusts kpt pkg get destination resolution so that explicitly specifying the current directory (. / paths that clean to .) places the package contents directly in that directory, aligning behavior with git clone and kpt cfg set.
Changes:
- Added an
explicitDestsignal through argument parsing to distinguish defaulted destinations from user-provided ones. - Updated destination selection logic to treat explicit
.as “use current directory”, while keeping the default “create package-name subdir” behavior when dest is omitted. - Updated
get.Run()to allow using an existing empty destination directory.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/lib/util/parse/parse.go | Threads explicitDest through parsing and adjusts getDest() behavior for explicit current-directory destinations. |
| pkg/lib/util/parse/parse_test.go | Updates parsing tests for the new GitParseArgs signature and destination expectations. |
| commands/pkg/get/cmdget.go | Tracks whether destination was explicitly provided and passes it into parsing. |
| internal/util/get/get.go | Permits existing empty destination directories (instead of erroring on any existing path). |
| commands/pkg/get/cmdget_test.go | Updates get command tests to reflect the new explicit-. behavior and unchanged default behavior when dest is omitted. |
| commands/pkg/diff/cmddiff_test.go | Updates diff tests to use the adjusted default pkg get destination behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| case err == nil: | ||
| // Destination exists - check if it's an empty directory | ||
| if !destInfo.IsDir() { | ||
| return errors.E(op, errors.Exist, types.UniquePath(c.Destination), fmt.Errorf("destination exists and is not a directory")) | ||
| } |
There was a problem hiding this comment.
Allowing an existing empty destination directory introduces a data-loss risk on failure: later errors (e.g., during WriteFile/fetchPackages) call cleanUpDirAndError, which unconditionally os.RemoveAll(c.Destination). If the destination pre-existed (especially when it’s the current directory), this can delete user-owned directories/content. Track whether the destination directory was created by this run and only RemoveAll when it was created; otherwise clean up only the files created by the command (or skip removal).
…fied When users explicitly pass '.' as the destination directory, kpt pkg get now places files directly in the current directory, matching the behavior of 'git clone' and 'kpt cfg set'. Changes: - Modified parse.GitParseArgs() to track if destination was explicitly provided - Updated getDest() to use current directory directly when explicitly specified - Modified get.Run() to allow using existing empty directories - Preserved default behavior: when no destination is provided, still creates a subdirectory with the package name Fixes #1407 Signed-off-by: Ciaran Johnston <ciaran.johnston@ericsson.com>
Signed-off-by: Ciaran Johnston <ciaran.johnston@ericsson.com>
…tions - Changed getDest() to check cleaned path (v) instead of originalV for '.' comparison - Updated tests to expect current directory when './' or '.' is explicitly passed - Fixed TestCmdMainBranch_execute to not pass './' explicitly - Fixed TestCmd_fail to use non-existent destination directory Signed-off-by: Ciaran Johnston <ciaran.johnston@ericsson.com>
The test was explicitly passing './' as the destination, which with the new behavior means 'use current directory directly'. Since the test runs in a non-empty workspace directory, this caused a conflict. Removing the explicit destination argument allows the default behavior to create a subdirectory with the package name, which is what the test expects. Signed-off-by: Ciaran Johnston <ciaran.johnston@ericsson.com>
5616f86 to
656576a
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
134d60e to
656576a
Compare
Signed-off-by: Ciaran Johnston <ciaran.johnston@ericsson.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Ciaran Johnston <ciaran.johnston@ericsson.com>
Signed-off-by: Ciaran Johnston <ciaran.johnston@ericsson.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
pkg/lib/util/parse/parse.go:263
os.Stat(v)errors other thanIsNotExistaren’t handled. IfStatreturns (nil, err) for e.g. permission/IO errors, the code will fall through and later callf.IsDir(), which will panic. Handle the non-nilerrcase explicitly (returning a wrapped/annotated error) before dereferencingf.
f, err := os.Stat(v)
if os.IsNotExist(err) {
parent := filepath.Dir(v)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
When users explicitly pass '.' as the destination directory, kpt pkg get now places files directly in the current directory, matching the behavior of 'git clone' and 'kpt cfg set'.
Changes:
Fixes #1407