Skip to content

Commit

Permalink
feat: 🎸 refCount for current execution
Browse files Browse the repository at this point in the history
refCount should only be valid for current execution

BREAKING CHANGE: 🧨 No

✅ Closes: #464
  • Loading branch information
mhegde-fala committed Mar 13, 2020
1 parent 1521d0e commit bb61201
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 21 deletions.
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,9 @@ Options include:
* A hex color code to style Check It Out
* refCount
* Type: Number
* Default: `500`
* Default: `--count 500`
* Total number of references to show.

To set `refCount` , start with the flag `--count`

```
checkit --count 20
OR
checkit --count=20
```

To reset Check It Out to its original configurations listed above, start with the flag `--reset-config`:

```
Expand Down
6 changes: 1 addition & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

const app = require('./dist/app');

const args = process.argv
.slice(2)
.reduce((acc, val) => acc.concat(val.split('=')), []); // support both "key=val" and "key val"

app.start(args).catch(error => {
app.start(process.argv.slice(2)).catch(error => {
console.error(error);
process.exit(1);
});
7 changes: 4 additions & 3 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@ const defaultConfig = {
const conf = new Configstore(pkg.name, defaultConfig);

export const start = async args => {
let refCount;
if (args[0] === '-v' || args[0] === '--version') {
process.stdout.write(pkg.version + '\n');
process.exit(0);
} else if (args[0] === '--reset-config') {
conf.all = defaultConfig;
} else if (args[0] === '--count' && args[1]) {
conf.set('refCount', parseInt(args[1]));
refCount = args[1];
}

const gitLogArguments = conf.get('gitLogArguments');
Expand Down Expand Up @@ -318,7 +319,7 @@ export const start = async args => {
* Update current screen with current remote
*/
const refreshTable = () => {
const tableData = ((state.currentRemote && state.currentRemote.refs) || [])
const tableData = state.currentRemote.refs
.filter(ref => ref.name.search(state.filterRegex) !== -1)
.map(ref => [
ref.active ? '*' : ' ',
Expand Down Expand Up @@ -348,7 +349,7 @@ export const start = async args => {
};

try {
state.setRemotes(await getRefData());
state.setRemotes(await getRefData(refCount));

state.setCurrentRemoteIndex(
state.remotes.findIndex(remote => remote.name === 'heads'),
Expand Down
9 changes: 5 additions & 4 deletions src/utils/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export const closeGitResponse = () => {
*
* @returns {Promise<Remote[]>} payload and uniqueRemotes
*/
export const getRefData = async () => {
const refs = await getRefs();
export const getRefData = async refCount => {
const refs = await getRefs(refCount);

const remotes = [];

Expand Down Expand Up @@ -177,12 +177,13 @@ export const formatRemoteBranches = async output => {
*
* @return {Promise<Ref[]>} String list of each ref associated with repository.
*/
const getRefs = async () => {
const getRefs = async refCount => {
refCount = refCount ? refCount : conf.get('refCount');
const args = [
'for-each-ref',
`--sort=${conf.get('sort')}`,
'--format=%(refname)',
`--count=${conf.get('refCount')}`,
`--count=${refCount}`,
];

return formatRemoteBranches(await execGit(args));
Expand Down

0 comments on commit bb61201

Please sign in to comment.