-
Notifications
You must be signed in to change notification settings - Fork 37
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
Add git initialization to new
command
#320
Conversation
Thanks! Catching this on mobile. I'll review later. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only comment is that I'd think we'd want the initialize logic in ops, but I can check that out another time if you don't feel up to making that change here.
Curious why you didn't think it would make sense to do that.
Would be able to maybe add a simple little test there too. |
I was thinking that |
@LoipesMas without looking at this too closely, seems like So to test the interface and not the implementation, we could test 2 scenarios; 1. default (no option flag passed, init new project with .git) and 2. no git flag. In both, I would think just adjust the of course, I haven't looked at this yet. So maybe disregard me for the time being LOL Oh crap, you're totally right, |
@LoipesMas I think we're going to start following the MVC design paradigm in the future. I've been mocking up kind of what that looks like, to me at least, here. But at the end of the day, this is @cnpryer brain-baby, so he has emperor Palpatine style ultimate power. |
Seems sensible to me. |
Yeah, I think it's reasonable to have someone with more decisive power in this scenario. I don't have the full view of the project and often it's more of an issue of keeping things consistent rather than finding objectively best solution. |
No need for the commander vibes! I always appreciate wise advice. Don't be afraid to disagree. With that said I do agree with the point about consistency. I think over time as things stabilize we'll have less issues with that. The goals in the readme are supposed to drive that consistency. So any feedback on clarity there is appreciated as well. |
Oh, I won't be! ;] |
I moved the git init to function in opts and added tests, but one thing I wasn't sure about was whether that new function or the command function should handle the conditionality. Passing an argument to the function that can make the function do completely nothing seems wrong. But with the condition checking in command function I had to test the whole command, which seems like something we do not do. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but one thing I wasn't sure about was whether that new function or the command function should handle the conditionality.
I think of it as the bin space is a separate application altogether than depends on our lib and the ops implementations. So calling init_vcs
from the bin space (CLI app) is correct imo.
src/bin/huak/commands/new.rs
Outdated
#[cfg(test)] | ||
mod tests { | ||
use tempfile::tempdir; | ||
|
||
#[test] | ||
fn initializes_git() { | ||
let directory = tempdir().unwrap().into_path(); | ||
std::env::set_current_dir(&directory).unwrap(); | ||
super::run("foo".to_owned(), true, false, false).unwrap(); | ||
let proj_dir = directory.join("foo"); | ||
assert!(proj_dir.is_dir()); | ||
assert!(proj_dir.join(".git").is_dir()); | ||
} | ||
|
||
#[test] | ||
fn does_not_initialize_git() { | ||
let directory = tempdir().unwrap().into_path(); | ||
std::env::set_current_dir(&directory).unwrap(); | ||
super::run("foo".to_owned(), true, false, true).unwrap(); | ||
let proj_dir = directory.join("foo"); | ||
assert!(proj_dir.is_dir()); | ||
assert!(!proj_dir.join(".git").exists()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should test in the ops space.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue here is that we can test init_vcs
from ops space, but we can't test there whether the argument passed to command::new::run
is being correctly used, which is what these tests test (in addition to init_vcs
, but that's a side effect).
And I'm not sure what needs to be tested and what doesn't. Personally I'm not a big fan of unit testing, especially granular/specific ones. So, for me, a more general test that covers a bigger part of the functionality is good enough. But to each their own. And I don't mind writing the tests themselves, it's just that I don't feel where the coverage line should be drawn.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but we can't test there whether the argument passed to
command::new::run
is being correctly used
This is a separate issue that we haven't solved yet for every other command as well. The tradeoff is manageable while the CLI app logic is super light. I've tinkered with testing through clap
usage that I'd like to introduce here at some point. That's when I think testing in the bin space will be appropriate.
Personally I'm not a big fan of unit testing, especially granular/specific ones
Hmm interesting. I'm the opposite. I like tons of unit-level coverage.
it's just that I don't feel where the coverage line should be drawn.
I personally don't see an issue with over-optimizing for more coverage (making the tradeoff of redundancy if needed). But I don't think we're at a point where we need to worry about any redundant testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would compare premature testing to premature optimization. Unless it's some critical part, you probably don't need it tested. In this situation, even if something went wrong, worse case scenario is a git repo is not initialized. Which would be pretty easy to notice and then to debug.
IMO it's a waste of developers' time, when writing tests and then when refactoring (and not even including conversations like this :P ). But then again, of all the things to "waste" time on, tests are not so bad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO requiring contributions to be paired with sufficient testing isn't more than what should be expected. I don't believe tests are ever premature. The earlier on the simpler the tests (in theory). If what you are contributing is simple but requires significant effort to test, then I'd reconsider the implementation.
It's, imo, similar to choosing to using a more complicated programming language like Rust. You make an investment early on that feels like it's time potentially better spent elsewhere, but the ROI is worth it since that investment pays off with better stability, more correct code, etc..
It's roughly the same idea. The tests may seem like overkill today, but as we start adding more and more in, we'll be happy we have that coverage when we want to sustain our pace of development without breaking existing logic. Whether or not the coverage is related, the piece of mind alone is a huge win.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I'm a little confused how this is related to moving the tests to ops::new
😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We went on a bit of a tangent here.
Also I'm a little confused how this is related to moving the tests to
ops::new
Barely at all. I just haven't been at my workstation to do the change until now. Done now.
To end the discussion: We have to draw a line somewhere. I would draw it in a different spot, but I accept where you draw it.
LGTM ty! |
Closes #281
Added initialization of basic git repo to the
new
command. Can be skipped with--no-vcs
. Addsgit2
dependency, as discussed in the issue.I considered moving the
init
call tocreate_project
, but that didn't feel right.