Skip to content

Commit efef9f5

Browse files
committed
Fix version labeling in monorepos by adding --first-parent to git log
In monorepo setups using path filtering (tagPrefix), git log --merges would hide merge commits due to "History Simplification" if the merge result was TREESAME to the second parent. Adding --first-parent ensures that merge commits on the release branch that affect the specified path are correctly captured, allowing tagpr to identify PR labels (major, minor, etc.) for correct versioning.
1 parent 9d0f650 commit efef9f5

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

tagpr.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ func (tp *tagpr) Run(ctx context.Context) error {
405405
tp.setOutput("pull_request", string(b))
406406
return nil
407407
}
408-
mergeLogArgs := []string{"log", "--merges", "--pretty=format:%P",
408+
mergeLogArgs := []string{"log", "--merges", "--first-parent", "--pretty=format:%P",
409409
fmt.Sprintf("%s..%s/%s", fromCommitish, tp.remoteName, releaseBranch)}
410410
if tp.normalizedTagPrefix != "" {
411411
mergeLogArgs = append(mergeLogArgs, "--", strings.TrimSuffix(tp.normalizedTagPrefix, "/"))

tagpr_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,9 +472,9 @@ func TestBuildGitLogArgsWithPathFilter(t *testing.T) {
472472
},
473473
{
474474
name: "merge log with prefix",
475-
baseArgs: []string{"log", "--merges", "--pretty=format:%P", "v1.0.0..origin/main"},
475+
baseArgs: []string{"log", "--merges", "--first-parent", "--pretty=format:%P", "v1.0.0..origin/main"},
476476
normalizedTagPrefix: "packages/core/",
477-
wantArgs: []string{"log", "--merges", "--pretty=format:%P", "v1.0.0..origin/main", "--", "packages/core"},
477+
wantArgs: []string{"log", "--merges", "--first-parent", "--pretty=format:%P", "v1.0.0..origin/main", "--", "packages/core"},
478478
},
479479
{
480480
name: "cherry-pick log with prefix",

0 commit comments

Comments
 (0)