Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 🎸 added optional refcount flag #469

Closed
wants to merge 2 commits into from

Conversation

mahendraHegde
Copy link

Fixes : #464
refcount optional flag added

BREAKING CHANGE: 🧨 No

Description

implemented an option for the --count option flag that gets passed into the git ref command that populates the list of references.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Checklist:

  • I have read the CONTRIBUTING document.
  • My commits follow the commitizen commit convention
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

@jwu910 jwu910 self-assigned this Feb 24, 2020
@jwu910
Copy link
Owner

jwu910 commented Feb 24, 2020

Just started reviewing :)

Copy link
Owner

@jwu910 jwu910 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @mahendraHegde please take a look at my comments

@kienD Can you take a look at the implementation and see what you think around the use of options?

index.js Outdated
app.start(process.argv.slice(2)).catch(error => {
const args = process.argv
.slice(2)
.reduce((acc, val) => acc.concat(val.split('=')), []); // support both "key=val" and "key val"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to communicate the usage of this logic in an inline-comment

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also not 100% convinced we need to pre-process the flags right now. Can you explain the need?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not necessary, only if you want to provide --count=2 this prepossessing is needed.
--count 2 will work just fine even without the preprocessing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I often use both the formats while providing args to CLI tools and most tools support it.
I'll remove it , if you think it is not necessary

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding to the conversation instead of the new commits: I don't think it is necessary in this case with as few arguments as we have. The way we currently have our options for CIO set up, its a very simple statement and will not work if we add more options in the future.

My reasoning for not wanting to add this line in is that when we get around to adding in a second option, this will break and we won't be able to parse options. I had plans to introduce a cli parsing library at that point. Though it would require some organization of this file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modified.

src/app.js Outdated
@@ -58,6 +59,8 @@ export const start = async args => {
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]));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is creating a side effect of the flag option persisting. Is that the intention? I think options being passed should just act as an overriding flag for a single execution. If we need to persist options through the cli instead of editing the config file, then we can create a ticket to check for a persist/save option in the future.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it was intentional, I'll modify it for a single execution then.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that this should be for single execution only.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need to add error handling as well for cases where the end user uses a flag but does not pass a value or passes an invalid value like... --count one....etc..

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jwu910 @kienD modified it.

src/utils/git.js Outdated
@@ -182,7 +182,7 @@ const getRefs = async () => {
'for-each-ref',
`--sort=${conf.get('sort')}`,
'--format=%(refname)',
'--count=500',
`--count=${conf.get('refCount')}`,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To build on the comment about not changing the config object. When a user passes the option to override the count, i think we can use that over the options only when present, otherwise we can use the default options.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modified accordingly.

README.md Outdated
Comment on lines 157 to 162
To set `refCount` , start with the flag `--count`

```
checkit --count 20
OR
checkit --count=20
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May not be necessary per my comments later in the review

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@kienD kienD self-assigned this Mar 2, 2020
@jwu910
Copy link
Owner

jwu910 commented Mar 11, 2020

Side note before I finish reviewing, can you update your commit message? This is not a bug fix, the changes are still part of a feature addition. Thanks

@jwu910 jwu910 requested review from jwu910 and kienD March 11, 2020 15:31
src/app.js Outdated
@@ -315,7 +319,7 @@ export const start = async args => {
* Update current screen with current remote
*/
const refreshTable = () => {
const tableData = state.currentRemote.refs
const tableData = ((state.currentRemote && state.currentRemote.refs) || [])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What did you run into that prompted you to add this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you give refCount value very low such as 1 , remotes may not have heads and
here the currentRemote will be set to undefined and will result a crash.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is an acceptable error and reason to crash. It only crashes if you attempt to select an item that does not exist--but effectively an edge case

The purpose of Check It Out is to change branches and if any user is using --count=1 there will only be one option to switch to, or no options depending on the first ref returned from the ref getter.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you suggesting we should let it crash @jwu910 ?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the app does not crash on start, it crashes when you are selecting nothing essentially. But you wouldn't use CIO in this manner. The function you linked to is being invoked in a try-catch already.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jwu910 can you review? its been very long

@mahendraHegde mahendraHegde force-pushed the CIO-464 branch 2 times, most recently from e6d8ad5 to bb61201 Compare March 13, 2020 13:52
refcount optional flag added

BREAKING CHANGE: 🧨 No

✅ Closes: jwu910#464
refCount should only be valid for current execution

BREAKING CHANGE: 🧨 No

✅ Closes: jwu910#464
@stale
Copy link

stale bot commented May 20, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added wontfix This will not be worked on and removed wontfix This will not be worked on labels May 20, 2020
@jwu910
Copy link
Owner

jwu910 commented May 27, 2020

@mahendraHegde I'll try to take a look when I get a chance. Been pretty busy lately with everything going on. It'll be a full fresh review though since it's been so long.

/CC: @kienD

@jwu910 jwu910 requested a review from kienD June 3, 2020 17:56
@stale
Copy link

stale bot commented Aug 2, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Aug 2, 2020
@stale
Copy link

stale bot commented Aug 16, 2020

This issue has been automatically closed due to inactivity. If this issue has not been resolved, please reopen the issue. Thank you.

@stale stale bot closed this Aug 16, 2020
@mahendraHegde
Copy link
Author

no stale

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ref count should have an option flag
3 participants