Skip to content

Commit

Permalink
tests: Add tests for git.branch util
Browse files Browse the repository at this point in the history
  • Loading branch information
angelmadames committed Apr 1, 2024
1 parent 5ccf912 commit c943274
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
26 changes: 14 additions & 12 deletions src/commands/git/branch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@ export const gitBranchCommand = () => {
const config = projectConfig();

command
.name('branch')
.description('Abstracts the git branch command so it is run in all available repositories.')
.argument('<ref>', 'The name of the branch to create.')
.action((ref) => {
const { repositories } = config;
for (const repo of repositories) {
git.branch({
path: `${config.paths.repos_root}/${repo}`,
ref,
});
}
});
.name('branch')
.description(
'Abstracts the git branch command so it is run in all available repositories.',
)
.argument('<ref>', 'The name of the branch to create.')
.action((ref) => {
const { repositories } = config;
for (const repo of repositories) {
git.branch({
path: `${config.paths.repos_root}/${repo}`,
ref,
});
}
});

return command;
};
Expand Down
4 changes: 2 additions & 2 deletions src/commands/git/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Command } from 'commander';
import { gitBranchCommand } from './branch';
import { gitCheckoutCommand } from './checkout';
import { gitCloneCommand } from './clone';
import { gitBranchCommand } from './branch';

export const gitCommand = () => {
const command = new Command();
Expand All @@ -11,7 +11,7 @@ export const gitCommand = () => {
.description('All git commands abstracted by DEMS')
.addCommand(gitCloneCommand())
.addCommand(gitCheckoutCommand())
.addCommand(gitBranchCommand())
.addCommand(gitBranchCommand());

return command;
};
Expand Down
2 changes: 1 addition & 1 deletion src/utils/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const git = {
}
cmd.run(`git -C ${path} checkout -b ${ref}`);
log.success(`Branch ${ref} was created successfully!`);
}
},
};

export const getRepoName = ({ repo }: Pick<GitParams, 'repo'>) => {
Expand Down
11 changes: 7 additions & 4 deletions test/utils/git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,13 @@ describe('Utils: git', () => {

expect(fs.existsSync).toHaveBeenLastCalledWith(`${path}/.git`);
expect(fs.lstatSync).toHaveBeenLastCalledWith(`${path}/.git`);
expect(execSync).toHaveBeenCalledWith(`git -C ${path} checkout -b ${ref}`, {
stdio: 'inherit',
encoding: 'utf-8',
});
expect(execSync).toHaveBeenCalledWith(
`git -C ${path} checkout -b ${ref}`,
{
stdio: 'inherit',
encoding: 'utf-8',
},
);
});
});

Expand Down

0 comments on commit c943274

Please sign in to comment.