Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ git commit -m "message 2"
malas pr # Generates PR from ALL commits in your branch
```

### Using a Custom Base Branch
By default, malas pr compares your current branch against the detected base branch (typically main). You can override this by specifying a different base branch using the --base option:
```bash
# Compare 'development' branch against 'staging' instead of 'main'
malas pr --base staging

# Compare 'feature-branch' against 'develop'
malas pr --base develop
```
This mode will:
- Automatically detect your current branch
- Find all commits since the base branch (main/master)
Expand All @@ -138,7 +147,7 @@ git add <file1> <file2>
malas pr # Generates PR from staged files
```

**Note**: If you have staged files, `malas pr` will use them. Otherwise, it will automatically use your commits.
**Note**: If you have staged files, `malas pr` will use them. Otherwise, it will automatically use your commits. When using commits, the `--base` argument allows you to specify the branch to compare against.

## Advanced Configuration

Expand Down
4 changes: 2 additions & 2 deletions out/git/gitUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ export const getDiffFromBaseBranch = async () => {
}
}
};
export const getCommitMessages = async () => {
export const getCommitMessages = async (targetBranch) => {
try {
const baseBranch = await getBaseBranch();
const baseBranch = targetBranch || await getBaseBranch();
const { stdout: messages } = await execa("git", [
"log",
`${baseBranch}..HEAD`,
Expand Down
16 changes: 11 additions & 5 deletions out/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const runGenerate = async () => {
}
}
};
const pullRequest = async () => {
const pullRequest = async (baseArg) => {
try {
await assertGitRepo();
const stagedFiles = await getStagedFiles();
Expand All @@ -122,14 +122,14 @@ const pullRequest = async () => {
else {
// Using commits from branch
const currentBranch = await getCurrentBranch();
const baseBranch = await getBaseBranch();
const baseBranch = baseArg || await getBaseBranch();
console.log(`No staged files detected. Using commits from branch '${currentBranch}' (base: ${baseBranch})...`);
if (currentBranch === baseBranch) {
console.error(`You are currently on the base branch (${baseBranch}). Please switch to a feature branch or stage some files to generate a pull request.`);
process.exit(1);
}
// Get commits and diff from base branch
commitMessages = await getCommitMessages();
commitMessages = await getCommitMessages(baseBranch);
if (commitMessages.length === 0) {
console.log(`No commits found on branch '${currentBranch}' since '${baseBranch}'. Please make some commits or stage some files before generating a pull request description.`);
process.exit(1);
Expand Down Expand Up @@ -213,8 +213,14 @@ const argv = yargs(hideBin(process.argv))
.command("generate", "Generate a commit message based on staged files", async () => { }, async () => {
await runGenerate();
})
.command("pr", "Generate a pull request description based on staged files", async () => { }, async () => {
await pullRequest();
.command("pr", "Generate a pull request description based on staged files", (yargs) => {
return yargs.option("base", {
alias: "b",
describe: "Base branch for pull request (default: auto-detected)",
type: "string",
});
}, async (argv) => {
await pullRequest(argv.base);
})
.help().argv;
if (Array.isArray(argv._) && argv._.length === 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/git/gitUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ export const getDiffFromBaseBranch = async (): Promise<string> => {
}
};

export const getCommitMessages = async (): Promise<string[]> => {
export const getCommitMessages = async (targetBranch: string): Promise<string[]> => {
try {
const baseBranch = await getBaseBranch();
const baseBranch = targetBranch || await getBaseBranch();

const { stdout: messages } = await execa("git", [
"log",
Expand Down
18 changes: 12 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const runGenerate = async () => {
}
};

const pullRequest = async () => {
const pullRequest = async (baseArg?: string) => {
try {
await assertGitRepo();

Expand All @@ -156,7 +156,7 @@ const pullRequest = async () => {
} else {
// Using commits from branch
const currentBranch = await getCurrentBranch();
const baseBranch = await getBaseBranch();
const baseBranch = baseArg || await getBaseBranch();

console.log(
`No staged files detected. Using commits from branch '${currentBranch}' (base: ${baseBranch})...`
Expand All @@ -170,7 +170,7 @@ const pullRequest = async () => {
}

// Get commits and diff from base branch
commitMessages = await getCommitMessages();
commitMessages = await getCommitMessages(baseBranch);

if (commitMessages.length === 0) {
console.log(
Expand Down Expand Up @@ -294,9 +294,15 @@ const argv = yargs(hideBin(process.argv))
.command(
"pr",
"Generate a pull request description based on staged files",
async () => {},
async () => {
await pullRequest();
(yargs) => {
return yargs.option("base", {
alias: "b",
describe: "Base branch for pull request (default: auto-detected)",
type: "string",
});
},
async (argv) => {
await pullRequest(argv.base);
}
)
.help().argv as any;
Expand Down