Skip to content

Enhancement/malas pr#7

Open
Raychal wants to merge 2 commits intohonestyan:mainfrom
Raychal:enhancement/malas-pr
Open

Enhancement/malas pr#7
Raychal wants to merge 2 commits intohonestyan:mainfrom
Raychal:enhancement/malas-pr

Conversation

@Raychal
Copy link

@Raychal Raychal commented Feb 11, 2026

Add --base option to pr command

Description

This pull request introduces a new --base option to the malas pr command, allowing users to specify a custom base branch for pull request generation. This enhances flexibility for projects using various branching strategies.

Changes Made

  1. malas pr Command Enhancement: The pr command now accepts an optional --base (or -b) argument.
    • This argument allows users to specify a custom base branch against which their current branch's commits will be compared when generating a PR description.
    • The yargs configuration in src/index.ts has been updated to include this new option.
  2. pullRequest Function Modification:
    • The pullRequest function in src/index.ts (and its compiled JavaScript out/index.js) now accepts an optional baseArg.
    • If baseArg is provided, it overrides the automatically detected base branch and is used as the target for commit comparison.
  3. getCommitMessages Function Update:
    • The getCommitMessages function in src/git/gitUtils.ts (and out/git/gitUtils.js) has been updated to accept an optional targetBranch argument.
    • This targetBranch is used by the pullRequest function to fetch commit messages relative to the specified base branch.
  4. Documentation Update:
    • The README.md file has been updated to include a new section titled "Using a Custom Base Branch," providing examples of how to use the --base option.
    • A clarifying note has been added regarding the --base argument's applicability when using commits.

Why These Changes Were Made

  • Enhanced Flexibility: The previous implementation of malas pr defaulted to comparing against the auto-detected base branch (usually main/master). This posed limitations for development workflows that involve intermediate branches (e.g., merging feature branches into develop or staging before main).
  • Improved User Control: Users now have explicit control over which branch their current branch is compared against, allowing for more accurate and context-specific pull request descriptions.
  • Support for Diverse Workflows: This feature makes malas more adaptable to a wider range of Git branching strategies, improving its utility for different teams and projects.

Impact of These Changes

  • User-facing: Users can now easily specify a custom base branch using malas pr --base <branch-name>, making the tool more powerful for complex branching scenarios.
  • Internal: The core logic for detecting and retrieving commit messages has been refactored to accept an explicit base branch, while maintaining the default auto-detection behavior if no --base argument is provided.
  • Documentation: The README.md provides clear instructions and examples, ensuring users can quickly understand and leverage the new functionality.

How to Test

  1. Set up a local Git repository:
    mkdir malas-test && cd malas-test
    git init
    echo "initial content" > file.txt
    git add . && git commit -m "Initial commit"
    git checkout -b develop
    echo "develop content" > develop.txt
    git add . && git commit -m "feat: Add develop branch content"
    git checkout -b feature-branch
    echo "feature content 1" > feature1.txt
    git add . && git commit -m "feat: Implement feature A"
    echo "feature content 2" > feature2.txt
    git add . && git commit -m "feat: Implement feature B"
  2. Test default behavior (compare against main):
    • Ensure you are on feature-branch.
    • Run malas pr
    • Verify the generated PR description includes commits from feature-branch and develop (since develop is ahead of main).
  3. Test with --base develop (compare feature-branch against develop):
    • Ensure you are on feature-branch.
    • Run malas pr --base develop
    • Verify the generated PR description only includes "feat: Implement feature A" and "feat: Implement feature B" (i.e., commits unique to feature-branch relative to develop).
  4. Test with --base main (compare feature-branch against main):
    • Ensure you are on feature-branch.
    • Run malas pr --base main
    • Verify the generated PR description includes "feat: Implement feature A", "feat: Implement feature B", and "feat: Add develop branch content" (i.e., all commits since main).
  5. Test with non-existent base branch:
    • Run malas pr --base non-existent-branch
    • Verify that malas gracefully handles this, likely by showing a Git error message indicating the branch does not exist.

@Raychal Raychal requested a review from honestyan as a code owner February 11, 2026 14:19
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.

1 participant