Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Diffing Display #1419

Merged
merged 12 commits into from
Feb 16, 2021
Merged

Update Diffing Display #1419

merged 12 commits into from
Feb 16, 2021

Conversation

runewake2
Copy link
Contributor

@runewake2 runewake2 commented Feb 5, 2021

Attempts to improve the UX of kpt package diffs like experienced in #1377

update upstream directory names

kpt-12348765 might now appear as kpt-upstream-examples-cockroachdb-ProjectVersion-12348765 where:

  • upstream references that the package was fetched from the source package. The local copy will appear as local instead.
  • examples references the Git project name. In this case taken from: https://github.com/kubernetes/examples
  • cockroachdb references the directory containing the upstream package. In this case taken from: staging/cockroachdb
  • ProjectVersion is a string constant that represents a version stored in the projects Kptfile. During remote or 3way diffs this may also appear as the provided reference (main, master etc).

add output of staged directories to stdout, this information looks like this:

Staging cockroachdb at /tmp/kpt-local-943465024
Staging https://github.com/kubernetes/examples/staging/cockroachdb:PackageVersion at /tmp/kpt-upstream-examples-cockroachdb-ProjectVersion-535434399
Staging https://github.com/kubernetes/examples/staging/cockroachdb:master at /tmp/kpt-upstream-examples-cockroachdb-master-555934580
  • PackageVersion represents a package which matches the package version stored in the projects Kptfile
  • master will represent the remote reference used during a 3way diff.

The /tmp directory will appear differently depending on the system (MacOS, Linux or Windows OS).

There are some known issues with this approach:

  1. When a diffing UI is used the "Staging..." text may not be obvious (hidden by the UI window) and the directories do not capture the complete information yet.
  2. Performing diffs against a series of temporary directories is still confusing. Note here: Kpt's diff is not atomic and will change the directory it is run against - this is the motivation for tmp directories - this prevents expected differences from being diffed like in the Kptfile but also means that a diff should not be run directly against the local package.

- update upstream directory names
- add logging of staged directories
- reduces the length of diffed directories
- uses short commit sha or up to 7 branch characters
@mikebz
Copy link
Contributor

mikebz commented Feb 9, 2021

is there a test we need to develop or update to make sure we don't regress this functionality in the future?

@runewake2
Copy link
Contributor Author

We do not currently have tests over the specific parts of code I've touched here. However there are a few tests covering the complete diff functionality.

I'm working on developing tests in parallel but wanted to create this first to get feedback on the experience it creates.

- refactor shortSha
- use one staging directory instead of three
internal/util/diff/diff.go Outdated Show resolved Hide resolved
kptFile.Upstream.Git.Repo,
kptFile.Upstream.Git.Directory,
kptFile.Upstream.Git.Commit,
upstreamPkg)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question as above. Do people expect to see the directory where things are staged after the "at..."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pkg variables store the path to the directory containing the staged package. This may be refactored in the future. The path is returned from the stageDirectory and GetPkg functions.

}

// defaultPkgGetter uses get.Command abstraction to implement PkgGetter.
type defaultPkgGetter struct{}

func (pg defaultPkgGetter) GetPkg(repo, path, ref string) (string, error) {
dir, err := ioutil.TempDir("", "kpt-")
// GetPkg checks out a repository into a temporary directory for diffing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<3 the extra comments. Thanks for relaying the context!

@runewake2
Copy link
Contributor Author

After latest changes directories will be staged similar to:

/tmp/kpt-165532019/local-master-75f116a
/tmp/kpt-165532019/remote-master-75f116a
/tmp/kpt-165532019/target-master

The target directory is only used when 3way, combined or remote diffs are run.

target-master relies upon the passed in ref to diff against. This defaults to master or main but can be a tag, branch or sha depending on the values provided.

@runewake2 runewake2 merged commit ca4befc into kptdev:master Feb 16, 2021
@runewake2 runewake2 deleted the diffing branch February 16, 2021 20:06
runewake2 added a commit to runewake2/kpt that referenced this pull request May 6, 2021
* Update diff info
- update upstream directory names

* Distinguish local and remote in dir names

* Introduce a descriptive reference name in dir

* Rename diffed directories
- reduces the length of diffed directories
- uses short commit sha or up to 7 branch characters

* Update local diff path.

* Create shared staging directory
- refactor shortSha
- use one staging directory instead of three

* Add error handling for staging directory

* Place staging dir naming under test
- add accounting for some extra edge cases
runewake2 added a commit that referenced this pull request May 13, 2021
* Update Diffing Display (#1419)

* Update diff info
- update upstream directory names

* Distinguish local and remote in dir names

* Introduce a descriptive reference name in dir

* Rename diffed directories
- reduces the length of diffed directories
- uses short commit sha or up to 7 branch characters

* Update local diff path.

* Create shared staging directory
- refactor shortSha
- use one staging directory instead of three

* Add error handling for staging directory

* Place staging dir naming under test
- add accounting for some extra edge cases

* Update tests

* Remove extra comment

* Add help message when diff fails (#1466)

* Add help message when diff fails

* Remove unused code

* Address Pr comments

* Refactor tests

* Update test to validate arguments

* Fix linting error
frankfarzan pushed a commit to frankfarzan/kpt that referenced this pull request Jun 3, 2021
* Update Diffing Display (kptdev#1419)

* Update diff info
- update upstream directory names

* Distinguish local and remote in dir names

* Introduce a descriptive reference name in dir

* Rename diffed directories
- reduces the length of diffed directories
- uses short commit sha or up to 7 branch characters

* Update local diff path.

* Create shared staging directory
- refactor shortSha
- use one staging directory instead of three

* Add error handling for staging directory

* Place staging dir naming under test
- add accounting for some extra edge cases

* Update tests

* Remove extra comment

* Add help message when diff fails (kptdev#1466)

* Add help message when diff fails

* Remove unused code

* Address Pr comments

* Refactor tests

* Update test to validate arguments

* Fix linting error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants