-
Notifications
You must be signed in to change notification settings - Fork 391
Conversation
Co-Authored-By: Tilde Ann Thurium <annthurium@github.com>
Repro steps: open repo with merge conflict click undo see error (cannot do a soft reset in the middle of a merge) expected: no change to commit message box actual: commit message from last commit appears in box
See #1464 (for performance)
It's best to assume that template users craft their template exactly as they want it. For example, I have two empty lines at the beginning of mine so that I can quickly type my message.
We don't want it to be at the end
According to @smashwilson > it may be worth triggering some of that behavior manually if a user aborts (or, eventually, initiates) a merge through our UI. in terms of reliability - on all three platforms there is some risk of dropped events that increases with the number of events that arrive in quick succession (like if a ton of files are created at once). merges in huge repositories _might_ trigger this but it shouldn't be common. Co-Authored-By: Ash Wilson <smashwilson@gmail.com>
Co-Authored-By: Matt <mattmattmatt@users.noreply.github.com>
We don't want to be setting up a commit template for every single test that runs. We do it locally for the tests that need it
Co-Authored-By: Katrina Uychaco <katrina@github.com>
const regex = new RegExp('^~([^/]*)/'); | ||
templatePath = templatePath.trim().replace(regex, (_, user) => { | ||
// if no user is specified, fall back to using the home directory. | ||
return `${user ? path.join(path.dirname(homeDir), user) : homeDir}/`; |
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.
@smashwilson: can you test this on non-Mac operating systems? We want to make sure if a username is specified, it does the right thing for our Linux and or Windows users.
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.
Can do, and will report back 🙇
One thing that I can see right away is that this won't handle ~root/
correctly; on most *nix systems, that should expand to /root
, not /users/root
. In general the right thing to do on Unix-y systems is to use getpwnam(3)
to read the definitive information, taking into account any weird local network drive setups and so on. Windows I'm less familiar with.
There are a few tilde-expansion libraries on npm, but unfortunately looking at their source it doesn't look like many of them handle all of this correctly either! I found one that uses etc-passwd to read its info, but I don't believe it has any accommodations for Windows. This may be a sign that this isn't important enough to hold up the 🚢 for 😉
Co-Authored-By: Katrina Uychaco <katrina@github.com>
This only works for commit message templates where every line starts with a #. We explored using isCommitMessageClean to try and handle commit message templates that have uncommented lines. We're not calling didUpdate every time the commit message is updated, so it's out of sync, and we decided it was getting too edge casey out there. Co-Authored-By: Katrina Uychaco <katrina@github.com>
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 have a bunch of assorted feedback, but no bugs or blockers 😄
I'll test the ~
expansion logic on Windows and Linux when I get the chance and leave a 👍 or ❌ accordingly.
lib/git-shell-out-strategy.js
Outdated
// Regex translation: | ||
// ^~ line starts with tilde | ||
// ([^/]*)/ captures non-forwardslash characters before first slash | ||
const regex = new RegExp('^~([^/]*)/'); |
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.
Is there a reason this is constructed with new RegExp()
rather than as a regexp literal? Is it just for readability so you don't have to escape all of the /
and get into leaning-toothpick-syndrome?
A more descriptive name than regex
may be nice too 😄 How about something like tildeExpansionPattern
?
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 didn't really have a strong reason for preferring the regexp constructor over literals here. We went with what the original author had.
Out of curiosity, we looked to see if there was a performance difference. Answer: not really.
https://www.measurethat.net/Benchmarks/Show/1734/1/regexp-constructor-vs-literal
We did give it a more descriptive name, and moved it out of this function so as to avoid creating a new regex every time.
const regex = new RegExp('^~([^/]*)/'); | ||
templatePath = templatePath.trim().replace(regex, (_, user) => { | ||
// if no user is specified, fall back to using the home directory. | ||
return `${user ? path.join(path.dirname(homeDir), user) : homeDir}/`; |
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.
Can do, and will report back 🙇
One thing that I can see right away is that this won't handle ~root/
correctly; on most *nix systems, that should expand to /root
, not /users/root
. In general the right thing to do on Unix-y systems is to use getpwnam(3)
to read the definitive information, taking into account any weird local network drive setups and so on. Windows I'm less familiar with.
There are a few tilde-expansion libraries on npm, but unfortunately looking at their source it doesn't look like many of them handle all of this correctly either! I found one that uses etc-passwd to read its info, but I don't believe it has any accommodations for Windows. This may be a sign that this isn't important enough to hold up the 🚢 for 😉
async updateCommitMessageAfterFileSystemChange(events) { | ||
for (let i = 0; i < events.length; i++) { | ||
const event = events[i]; | ||
const endsWith = (...segments) => event.path.endsWith(path.join(...segments)); |
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.
Might be worth extracting this to helpers.js
?
It is a one-liner, but eh.
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.
sure! Good suggestion. Extracted.
test/models/repository.test.js
Outdated
return {repository, observer}; | ||
} | ||
|
||
function expectEvents(repository, ...suffixes) { |
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.
Yeah, these would be great to extract to a helper and clean up a bit... We have a few places that test Real Filesystem Events ™️ where these would be nice.
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.
How does this look b3c9ec7?
Co-Authored-By: Katrina Uychaco <katrina@github.com>
Co-Authored-By: Katrina Uychaco <katrina@github.com>
Co-Authored-By: Tilde Ann Thurium <annthurium@github.com>
Tests were failing because my global config was being used to look up the commit template
Co-Authored-By: Ash Wilson <smashwilson@gmail.com>
I just found a bug on Windows. If I run
From the message, I'm guessing that the fetched commit template is Oddly it's fine if I ctrl-F5 with no |
Path logic is 👍 on Windows: I verified both |
👍 to path logic on Linux as well. (And I was able to reproduce the |
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 probably fix that stack trace I found when running git config --unset commit.template
with an Atom window open. Other than that, looks good - all of the path wrangling worked correctly on Windows and Linux 👍
Description of the Change
This PR re-introduces the commit message template feature, originally introduced in #1713. It re-works some of the implementation, cleans up tests, and additionally fixes the merge message regression.
With these change, the repository model now manages and updates the commit message based on file system events indicating that the config has changed or a merge has been initiated/completed.
/cc @annthurium
Alternate Designs
N/A
Benefits
Folks will be able to make commits with the aid of commit message templates
Possible Drawbacks
The usual drawbacks associated with code changes. This feature in particular touches a part of the system that is complex and fairly edge-casey...
Applicable Issues
Original PR - #1713
Reverted PR - #1754
Metrics
N/A
Tests
Added unit tests for:
Manually tested:
tab
bing to commit box, cursor is at beginning of template (rather than at the very end)@smashwilson to test manually on Linux and Windows
Documentation
User Experience Research (Optional)
N/A
TODO: