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

Fix git-init in case master is not the default branch #2835

Merged
merged 1 commit into from
Jun 24, 2020

Conversation

vinamra28
Copy link
Member

@vinamra28 vinamra28 commented Jun 18, 2020

Changes

This fix will patch the git-init such that if user doesn't provides revision then instead of taking master as the default branch we are doing the symbolic-link to the HEAD branch. Instead of making the assumption that we should use master when the revision is empty, we are inspecting the remote.

Fixes #2822

Signed-off-by: vinamra28 [email protected]

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

  • Includes tests (if functionality changed/added)
  • Includes docs (if user facing)
  • Commit messages follow commit message best practices
  • Release notes block has been filled in or deleted (only if no user facing changes)

See the contribution guide for more details.

Double check this list of stuff that's easy to miss:

Reviewer Notes

If API changes are included, additive changes must be approved by at least two OWNERS and backwards incompatible changes must be approved by more than 50% of the OWNERS, and they must first be added in a backwards compatible way.

Release Notes

The Git PipelineResource now inspects remote repository to determine the correct default branch to use when no revision has been specified.

/kind bug

@tekton-robot tekton-robot added the kind/bug Categorizes issue or PR as related to a bug. label Jun 18, 2020
@tekton-robot tekton-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 18, 2020
@tekton-robot
Copy link
Collaborator

Hi @vinamra28. Thanks for your PR.

I'm waiting for a tektoncd member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@tekton-robot
Copy link
Collaborator

This PR cannot be merged: expecting exactly one kind/ label

Available kind/ labels are:

kind/bug: Categorizes issue or PR as related to a bug.
kind/flake: Categorizes issue or PR as related to a flakey test
kind/cleanup: Categorizes issue or PR as related to cleaning up code, process, or technical debt.
kind/design: Categorizes issue or PR as related to design.
kind/documentation: Categorizes issue or PR as related to documentation.
kind/feature: Categorizes issue or PR as related to a new feature.
kind/misc: Categorizes issue or PR as a miscellaneuous one.

@ghost
Copy link

ghost commented Jun 18, 2020

/ok-to-test

@tekton-robot tekton-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 18, 2020
@vinamra28
Copy link
Member Author

@vdemeester could you please take a look at the PR 🙂

pkg/git/git.go Outdated
@@ -65,7 +65,7 @@ func Fetch(logger *zap.SugaredLogger, spec FetchSpec) error {
}

if spec.Revision == "" {
spec.Revision = "master"
spec.Revision = "HEAD"
Copy link
Member

Choose a reason for hiding this comment

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

I think we should run git symbolic-ref refs/remotes/origin/HEAD only if spec.Revision is empty and extract the default branch name from it. So something like :

remoteHead, err := run(logger, "", "symbolic-ref", "refs/remotes/origin/HEAD")
if err != nil {
	return err
}
spec.Revision = strings.ReplaceAll(remoteHead, "refs/remotes/origin/", "") // this would display `master` or `main`, or …

Copy link
Member Author

Choose a reason for hiding this comment

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

@vdemeester : I tried this out locally on my terminal and also as you suggested but this didn't worked out. On my terminal I got the following error:-

[vinjain@vinjain output]$ git remote show origin
* remote origin
  Fetch URL: https:/spring-projects/spring-petclinic.git
  Push  URL: https:/spring-projects/spring-petclinic.git
  HEAD branch: main
  Remote branches:
    gh-pages  new (next fetch will store in remotes/origin)
    main      new (next fetch will store in remotes/origin)
    wavefront new (next fetch will store in remotes/origin)
[vinjain@vinjain output]$ git symbolic-ref refs/remotes/origin/HEAD
fatal: ref refs/remotes/origin/HEAD is not a symbolic ref

Copy link
Member

Choose a reason for hiding this comment

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

@vinamra28 you are right, it needs to happend after the fetch 🤔

@vinamra28 vinamra28 force-pushed the vinamra28/git-res-fix branch 2 times, most recently from fd38d0e to f5ec9c7 Compare June 19, 2020 12:40
@vinamra28
Copy link
Member Author

/retest

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

think we should have an e2e test that runs against sprint-petclinic or a tektoncd/* controlled repository with a default branch with non master to make sure it works fine 👼

@tekton-robot tekton-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 23, 2020
@vinamra28
Copy link
Member Author

@vdemeester added e2e tests as well for both v1beta1 and v1alpha1 for spring-petclinic repository

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/resource/v1alpha1/git/git_resource.go 85.4% 84.8% -0.6

@vinamra28 vinamra28 force-pushed the vinamra28/git-res-fix branch 2 times, most recently from 4cc2688 to fde0cfb Compare June 23, 2020 10:59
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/resource/v1alpha1/git/git_resource.go 85.4% 84.8% -0.6

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/resource/v1alpha1/git/git_resource.go 85.4% 84.8% -0.6

@vinamra28
Copy link
Member Author

/test pull-tekton-pipeline-integration-tests

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

/lgtm

func getGitPipelineResourceSpringPetClinic(revision, refspec, sslverify, httpproxy, httpsproxy, noproxy string) *v1alpha1.PipelineResource {
return tb.PipelineResource(gitSourceResourceName, tb.PipelineResourceSpec(
v1alpha1.PipelineResourceTypeGit,
tb.PipelineResourceSpecParam("Url", "https:/spring-projects/spring-petclinic"),
Copy link
Member

Choose a reason for hiding this comment

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

I think, long term, we should use a project we control (just in case) 😝

Copy link
Member Author

Choose a reason for hiding this comment

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

actually there was no repo in tektoncd/* which does not have master as the default branch. Earlier we had the v1beta1 branch in tektoncd/catalog as the default branch but now it has been merged to master. That's why I went to spring-petclinic repo for testing 😅

Copy link
Member

Choose a reason for hiding this comment

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

@vinamra28 yep, that's fine for now 😉

Copy link

Choose a reason for hiding this comment

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

Created #2854 to track.

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 24, 2020
@ghost
Copy link

ghost commented Jun 24, 2020

I think there are two more things that need to be resolved and then this is ready to merge:

  1. docs/resources.md should include a description of this new behavior. Right now it says:

    _If no revision is specified, the resource will default to master`.

  2. We should have Release Notes in the PR description describing the user-visible change. Something like this:

    The Git PipelineResource now inspects remote repositories to determine the correct default branch to use when no revision has been specified.

As an aside, we'll need to also update documentation for the git-clone catalog entry when we move to this new version of git-init. I'll create an issue for this.

@vinamra28
Copy link
Member Author

Thank you @sbwsg. Will do this. Thanks for guidance 😄

This fix will patch the `git-init` such that if user doesn't provides revision then instead of taking `master` as the default branch we are doing the `symbolic-link` to the HEAD branch. Also added e2e tests for it.

Signed-off-by: vinamra28 <[email protected]>
@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label Jun 24, 2020
@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 24, 2020
Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 24, 2020
@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sbwsg, vdemeester

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@vinamra28
Copy link
Member Author

/test pull-tekton-pipeline-integration-tests

@tekton-robot tekton-robot merged commit 9aff0a0 into tektoncd:master Jun 24, 2020
@vinamra28 vinamra28 deleted the vinamra28/git-res-fix branch June 24, 2020 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

git-init: do not assume master as default branch
3 participants