Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Conversation

@kuychaco
Copy link
Contributor

@kuychaco kuychaco commented Oct 25, 2018

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:

  • restores template after committing
  • config commit.template change
  • when merge is initiated
    • merge message replaces
      • empty commit message
      • untouched commit template
    • dirty message is left untouched
  • when merge is aborted
    • clean commit message is restored
    • commit template is restored

Manually tested:

  • When tabbing to commit box, cursor is at beginning of template (rather than at the very end)
  • Commit button is disabled when commit message contains a template. It is enabled only when commit message contains non-commented lines
  • Commit message updates correctly when expanding/closing expanded commit message editors
  • Commit message updates correctly to show merge message when merge is initiated and aborted
  • Commit message template is restored after committing

@smashwilson to test manually on Linux and Windows

Documentation

User Experience Research (Optional)

N/A

TODO:

  • clean up git strategies tests
  • de-dupe file system watching tests
  • verify template path logic works on windows and linux

kuychaco and others added 26 commits October 23, 2018 14:57
…-template"

This reverts commit c96687a, reversing
changes made to 4bc7fde.
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
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 <[email protected]>
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: Matt <[email protected]>
Co-Authored-By: Katrina Uychaco <[email protected]>
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}/`;

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.

Copy link
Contributor

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 <[email protected]>
@annthurium annthurium force-pushed the ku-tt-commit-msg-template branch from a24bad7 to acf502c Compare October 26, 2018 00:08
@coveralls
Copy link

Coverage Status

Coverage increased (+0.05%) to 84.925% when pulling acf502c on ku-tt-commit-msg-template into 32c39c2 on master.

@coveralls
Copy link

coveralls commented Oct 26, 2018

Coverage Status

Coverage decreased (-0.003%) to 84.869% when pulling 4e400bd on ku-tt-commit-msg-template into 0e906e2 on master.

Tilde Ann Thurium and others added 3 commits October 25, 2018 17:24
Co-Authored-By: Katrina Uychaco <[email protected]>
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 <[email protected]>
@kuychaco kuychaco requested a review from smashwilson October 26, 2018 18:20
Copy link
Contributor

@smashwilson smashwilson left a 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.

// Regex translation:
// ^~ line starts with tilde
// ([^/]*)/ captures non-forwardslash characters before first slash
const regex = new RegExp('^~([^/]*)/');
Copy link
Contributor

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?

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}/`;
Copy link
Contributor

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));
Copy link
Contributor

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.

Choose a reason for hiding this comment

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

sure! Good suggestion. Extracted.

return {repository, observer};
}

function expectEvents(repository, ...suffixes) {
Copy link
Contributor

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.

Copy link
Contributor Author

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?

@smashwilson
Copy link
Contributor

smashwilson commented Oct 30, 2018

I just found a bug on Windows. If I run git config --unset commit.template at the command line, the git tab errors out and leaves this stack in the console:

C:\Users\smash\src\atom\node_modules\text-buffer\lib\text-buffer.js:1319 Uncaught TypeError: Cannot read property 'split' of null
    at Diff.lineDiff.tokenize (C:\Users\smash\src\atom\node_modules\text-buffer\node_modules\diff\lib\diff\line.js:22:32)
    at Diff.diff (C:\Users\smash\src\atom\node_modules\text-buffer\node_modules\diff\lib\diff\base.js:36:39)
    at Object.diffLines (C:\Users\smash\src\atom\node_modules\text-buffer\node_modules\diff\lib\diff\line.js:47:19)
    at transact (C:\Users\smash\src\atom\node_modules\text-buffer\lib\text-buffer.js:801:29)
    at TextBuffer.transact (C:\Users\smash\src\atom\node_modules\text-buffer\lib\text-buffer.js:1316:16)
    at TextBuffer.setTextViaDiff (C:\Users\smash\src\atom\node_modules\text-buffer\lib\text-buffer.js:796:10)
    at CommitController.componentDidUpdate (C:/Users/smash/src/github/lib/controllers/commit-controller.js:113:30)
    at commitLifeCycles (C:\Users\smash\src\github\node_modules\react-dom\cjs\react-dom.development.js:14256:22)
    at commitAllLifeCycles (C:\Users\smash\src\github\node_modules\react-dom\cjs\react-dom.development.js:15342:7)
    at HTMLUnknownElement.callCallback (C:\Users\smash\src\github\node_modules\react-dom\cjs\react-dom.development.js:100:14)
    at Object.invokeGuardedCallbackDev (C:\Users\smash\src\github\node_modules\react-dom\cjs\react-dom.development.js:138:16)
    at invokeGuardedCallback (C:\Users\smash\src\github\node_modules\react-dom\cjs\react-dom.development.js:187:29)
    at commitRoot (C:\Users\smash\src\github\node_modules\react-dom\cjs\react-dom.development.js:15481:7)
    at completeRoot (C:\Users\smash\src\github\node_modules\react-dom\cjs\react-dom.development.js:16496:34)
    at performWorkOnRoot (C:\Users\smash\src\github\node_modules\react-dom\cjs\react-dom.development.js:16440:9)
    at performWork (C:\Users\smash\src\github\node_modules\react-dom\cjs\react-dom.development.js:16358:7)
    at performSyncWork (C:\Users\smash\src\github\node_modules\react-dom\cjs\react-dom.development.js:16330:3)
    at requestWork (C:\Users\smash\src\github\node_modules\react-dom\cjs\react-dom.development.js:16230:5)
    at scheduleWork$1 (C:\Users\smash\src\github\node_modules\react-dom\cjs\react-dom.development.js:16096:11)
    at Object.enqueueSetState (C:\Users\smash\src\github\node_modules\react-dom\cjs\react-dom.development.js:11185:5)
    at ObserveModel.Component.setState (C:\Users\smash\src\github\node_modules\react\cjs\react.development.js:273:16)
    at ObserveModel.didUpdate (C:/Users/smash/src/github/lib/views/observe-model.js:39:12)
    at ModelObserver._refreshModelData (C:/Users/smash/src/github/lib/models/model-observer.js:52:14)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

From the message, I'm guessing that the fetched commit template is null instead of an empty string unexpectedly?

Oddly it's fine if I ctrl-F5 with no commit.template set.

@smashwilson
Copy link
Contributor

Path logic is 👍 on Windows: I verified both ~/... and ~username/... paths. Checking Linux next...

@smashwilson
Copy link
Contributor

👍 to path logic on Linux as well. (And I was able to reproduce the --unset bug I mentioned above, so it must not be platform-specific.)

Copy link
Contributor

@smashwilson smashwilson left a 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 👍

@annthurium annthurium dismissed smashwilson’s stale review November 6, 2018 22:54

this bug has been addressed

@annthurium annthurium merged commit 26c39ee into master Nov 7, 2018
@annthurium annthurium deleted the ku-tt-commit-msg-template branch November 7, 2018 19:32
@vanessayuenn vanessayuenn mentioned this pull request Nov 21, 2018
5 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants