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

Include pattern in .gitignore is not respected #436

Open
gustavkj opened this issue Nov 28, 2023 · 2 comments
Open

Include pattern in .gitignore is not respected #436

gustavkj opened this issue Nov 28, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@gustavkj
Copy link
Collaborator

Describe the bug
This is most likely a bug in go-git. I ran an job to update files in the .github/workflows directory on multiple repos (same as #435). When it worked for most repos, one repo ended up with an empty PR, which was curious. On closer inspection, that repo had a .gitignore file that used the include pattern (see below). Changing the config to git-type: cmd worked (once I had closed the old PR).

.*
!.github
Config file
# Base URL of the (v3) GitHub API, needs to be changed if GitHub enterprise is used. Or the url to a self-hosted GitLab instance.
base-url: https://github.company.com/api/v3

# The name of the branch where changes are committed.
branch: update-internal-actions

# Use a code search to find a set of repositories to target (GitHub only). Repeated results from a given repository will be ignored, forks are NOT included by default (use `fork:true` to include them). See the GitHub documentation for full syntax: https://docs.github.com/en/search-github/searching-on-github/searching-code.
code-search: "internal/github-action extension:yml extension:yaml path:.github -org:org-a -org:org-b -org:ab-archive"

# The commit message. Will default to title + body if none is set.
commit-message: "refactor: update internal actions"

# What should happen if the branch already exist.
# Available values:
#   skip: Skip making any changes to the existing branch and do not create a new pull request.
#   replace: Replace the existing content of the branch by force pushing any new changes, then reuse any existing pull request, or create a new one if none exist.
conflict-strategy: skip

# Create pull request(s) as draft.
draft: false

# Run without pushing changes or creating pull requests
dry-run: false

# Fork the repository instead of creating a new branch on the same owner.
fork: true

# The type of git implementation to use.
# Available values:
#   go: Uses go-git, a Go native implementation of git. This is compiled with the multi-gitter binary, and no extra dependencies are needed.
#   cmd: Calls out to the git command. This requires git to be installed and available with by calling "git".
git-type: go

# The file where all logs should be printed to. "-" means stdout
log-file: "-"

# The formatting of the logs. Available values: text, json, json-pretty
log-format: text

# The level of logging that should be made. Available values: trace, debug, info, error
log-level: info

# The file that the output of the script should be outputted to. "-" means stdout
output: "-"

# The body of the commit message. Will default to everything but the first line of the commit message if none is set.
pr-body: |
  This is an automated PR to update the internal actions in this repository.

To Reproduce
Steps to reproduce the behavior:

  1. Have a repo with a .gitignore file using the include pattern
  2. Run multi-gitter run ./replace.sh --config ./multi-gitter-config.yml --token $GITHUB_TOKEN where replace.sh updates files in the .github/workflows directory.
  3. The PR is created, but it is empty without any changes.

Expected behavior
It should create the PR, but also include the changes in files matching the include pattern in the .gitignore file.

Additional context
Add any other context about the problem here.
It is for example often useful to include detailed logs from a run with --log-level=trace.

@gustavkj gustavkj added the bug Something isn't working label Nov 28, 2023
@lindell
Copy link
Owner

lindell commented Nov 28, 2023

I assume this is the same as #356?

It seems that go-gits implementation of gitignore is indeed not 1:1 with "normal" git. It seems that inclusion patterns should be supported, but something is apparently not matching.

https://pkg.go.dev/github.com/go-git/go-git/[email protected]/plumbing/format/gitignore

@lindell
Copy link
Owner

lindell commented Nov 28, 2023

I tried to add this test

func (s *MatcherSuite) TestMatcher_Match2(c *C) {
	ps := []Pattern{
		ParsePattern(".*", nil),
		ParsePattern("!.included", nil),
	}

	m := NewMatcher(ps)
	c.Assert(m.Match([]string{".test-file"}, false), Equals, true)
	c.Assert(m.Match([]string{".test", "file"}, false), Equals, true)
	c.Assert(m.Match([]string{".included", "file"}, false), Equals, false)
}

And it passes ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants