Skip to content

Commit

Permalink
Merge pull request #600 from cloudflare/branch
Browse files Browse the repository at this point in the history
Fix --base-branch handling
  • Loading branch information
prymitive authored Apr 13, 2023
2 parents 26e8644 + cb1bc19 commit 5ece79f
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cmd/pint/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func actionCI(c *cli.Context) error {
}

meta.cfg.CI = detectCI(meta.cfg.CI)
baseBranch := strings.Split(meta.cfg.CI.BaseBranch, "/")[len(strings.Split(meta.cfg.CI.BaseBranch, "/"))-1]
baseBranch := meta.cfg.CI.BaseBranch
if c.String(baseBranchFlag) != "" {
baseBranch = c.String(baseBranchFlag)
}
Expand All @@ -78,7 +78,7 @@ func actionCI(c *cli.Context) error {
return fmt.Errorf("failed to get the name of current branch")
}
log.Debug().Str("current", currentBranch).Str("base", baseBranch).Msg("Got branch information")
if currentBranch == baseBranch {
if currentBranch == strings.Split(baseBranch, "/")[len(strings.Split(baseBranch, "/"))-1] {
log.Info().Str("branch", currentBranch).Msg("Running from base branch, skipping checks")
return nil
}
Expand Down
39 changes: 39 additions & 0 deletions cmd/pint/tests/0134_ci_base_branch_flag_path.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
mkdir testrepo
cd testrepo
exec git init --initial-branch=main .

cp ../src/v1.yml rules.yml
cp ../src/.pint.hcl .
env GIT_AUTHOR_NAME=pint
env [email protected]
env GIT_COMMITTER_NAME=pint
env [email protected]
exec git add .
exec git commit -am 'import rules and config'

exec git checkout -b v2
cp ../src/v2.yml rules.yml
exec git commit -am 'v2'

pint.error -l debug --no-color ci --base-branch=origin/main
! stdout .
cmp stderr ../stderr.txt

-- stderr.txt --
level=info msg="Loading configuration file" path=.pint.hcl
level=debug msg="Running git command" args=["rev-parse","--abbrev-ref","HEAD"]
level=debug msg="Got branch information" base=origin/main current=v2
level=debug msg="Running git command" args=["log","--format=%H","--no-abbrev-commit","--reverse","origin/main..HEAD"]
level=fatal msg="Fatal error" error="failed to get the list of commits to scan: fatal: ambiguous argument 'origin/main..HEAD': unknown revision or path not in the working tree.\nUse '--' to separate paths from revisions, like this:\n'git <command> [<revision>...] -- [<file>...]'\n"
-- src/v1.yml --
- record: rule1
expr: sum(foo) by(job)

-- src/v2.yml --
- record: rule1
expr: sum(foo) bi(job)

-- src/.pint.hcl --
parser {
relaxed = [".*"]
}
42 changes: 42 additions & 0 deletions cmd/pint/tests/0135_ci_base_branch_config_path.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
mkdir testrepo
cd testrepo
exec git init --initial-branch=main .

cp ../src/v1.yml rules.yml
cp ../src/.pint.hcl .
env GIT_AUTHOR_NAME=pint
env [email protected]
env GIT_COMMITTER_NAME=pint
env [email protected]
exec git add .
exec git commit -am 'import rules and config'

exec git checkout -b v2
cp ../src/v2.yml rules.yml
exec git commit -am 'v2'

pint.error -l debug --no-color ci
! stdout .
cmp stderr ../stderr.txt

-- stderr.txt --
level=info msg="Loading configuration file" path=.pint.hcl
level=debug msg="Running git command" args=["rev-parse","--abbrev-ref","HEAD"]
level=debug msg="Got branch information" base=origin/main current=v2
level=debug msg="Running git command" args=["log","--format=%H","--no-abbrev-commit","--reverse","origin/main..HEAD"]
level=fatal msg="Fatal error" error="failed to get the list of commits to scan: fatal: ambiguous argument 'origin/main..HEAD': unknown revision or path not in the working tree.\nUse '--' to separate paths from revisions, like this:\n'git <command> [<revision>...] -- [<file>...]'\n"
-- src/v1.yml --
- record: rule1
expr: sum(foo) by(job)

-- src/v2.yml --
- record: rule1
expr: sum(foo) bi(job)

-- src/.pint.hcl --
parser {
relaxed = [".*"]
}
ci {
baseBranch = "origin/main"
}
8 changes: 7 additions & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v0.43.1

### Fixed

- Fixed `--base-branch` flag handling when branch name contains `/`.

## v0.43.0

### Added
Expand Down Expand Up @@ -29,7 +35,7 @@

### Fixed

- Fixed `--initial-branch` flag handling.
- Fixed `--base-branch` flag handling.
Value of this flag wasn't being used correctly - #559.

## v0.42.0
Expand Down

0 comments on commit 5ece79f

Please sign in to comment.