GithubHelp home page GithubHelp logo

commitplease's People

Contributors

amitse avatar arschmitz avatar jzaefferer avatar leobalter avatar maks3w avatar rxaviers avatar scottgonzalez avatar stevemao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

commitplease's Issues

Using `commit -v` when validation fails causes the entire diff to be dumped as part of error message

The project which I'm trying to contribute to has commitplease enabled with default settings. I've tried git commit -v but apparently failed to provide a component name. The resulting error message from commitplease dumped the entire previous contents of .git/COMMIT_EDITMSG, which includes git's own comments and diff and floods my terminal output. Example:

$ git commit -v
Invalid commit message, please fix the following issues:

- First line (subject) must indicate the component

Commit message was:

{MY SUBJECT LINE}

{MY COMMIT MESSAGE BODY}
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
{100s OF LINES OF DIFF FOLLOWS}

What I expected: only my subject line and message to be outputted (the content that would actually get used as the commit message), and git's own comments and diff stripped away.

Now that I think of it, if the error is really just about the subject line, then the error output could just list the subject line I provided (since that's what needs fixing), and not even the commit body.

Related: #19

Allow usage without git hook

@rxaviers wants to use this module without the git hook. Separating the validation from the hook, into a separate projects/module is one way. I wonder if a flag in the parent projects package.json could be used instead.

Test with gitx

Got an informal error report where committing with gitx always failed, and the output from commitplease doesn't show up

Project seems to be for osx-only: http://gitx.frim.nl/

@all3fox can you test this?

Warn instead of aborting

Hi Jörn,

On invalid commit messages, the commit is aborted by the hook. For me, it would be of more value if it didn't abort it. But, instead give me a warn message saying:

"Hey! The commit is invalid for reason. Please, git commit --amend and fix it!"

Amending is faster for me... But, I don't know if this is doable.

Thanks!

PS: this is more of a question than a bug.

Validate user name/email

Sometimes someone lands a PR with a bad name or email. It would be great to have an option to require authors in the format "Name1 Name2 [email protected]" with some level of validation. There are (rare) cases where a single name is allowed but perhaps that could be elided using two spaces or something. I don't think we ever want to have a bad email.

Investigate other platforms

Could we get commitplease into Python, Ruby, Go etc. projects? Could either do native implementations (porting the whole thing to Python) or just figuring out a way to run the existing code, but install it as a Python package (pip?). Nodejs is a reasonable system dependency, but not every project uses npm.

Whitelist component for fixup commits

#26 suggests allowing "fixup!" as a prefix to whitelist, but that's very specifc to the --fixup flag and will reuse the existing commit message. In our current PR workflows, we use something like "[fix]: description of the fixup".

Could also whitelist /\[[^\]]+\]:/ (anything in square brackets), along with "fixup!" and "squash!".

Commit template

From qunitjs/qunit#679 (comment), where @mislav wrote:


it looks like every user needs to configure this locally.

Just like hooks need to be configured locally per-repo as well. If you could set up git hooks, then you could also set up the template.

Here's an alternative to a template: a git hook that prepares the commit message before it opens in your text editor by listing the existing components:

#!/bin/bash
# .git/hooks/prepare-commit-msg
set -e

file="$1"
mode="$2"

list_components() {
  git log --no-merges --format='%s' | grep : | cut -d: -f1 | \
    sort | uniq -c | sort -rn | head -10 | sed 's/^.\{1,\}[[:digit:]] //'
}

if [ -z "$mode" ]; then
  c="$(git config core.commentchar || echo '#')"
  { echo "$c Please prefix the subject line with \"Component:\""
    echo -n "$c Example components: "
    list_components | xargs | sed 's/ /, /g'
    cat "$file"
  } > "${file}.new"
  mv "${file}.new" "$file"
fi

The effect it has on the default message when I git commit:

# Please prefix the subject line with "Component:"
# Example components: Build, qunit, Core, Tests, Test, QUnit, Grunt, Assert, Reporter, Readme

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
...

I like that idea, since it'll help providing a correct commit message on the first attempt.

The example components are somewhat questionable, as existing jQuery repositories often have common components that are actually bad examples. This could be replaced by a fixed list, as suggested in #23.

Read core.commentchar config instead of assuming default #

In git, the commentchar can be configured. git config core.commentchar returns the custom character or nothing, where nothing means the default # character is used.

This requires sync exec, which I currently don't want to deal with (sync-exec module is a rather big dependency). Node 0.12 should ship with execSync, making this a lot easier.

Its also not something anyone has actually reported as a problem. When the first person actually runs into this issue, I can still address it.

Use ES2015

Use babel or bublé (along with rollup?) to allow using ES2015 for development, but publish ES5 code to npm.

fs.existsSync followed by fs.mkdirSync fail with EEXIST

There is a problem with angular continuous integration. My suspicion is that the repository is created in between the calls to fs.existsSync and fs.mkdirSync, leading to failure. So, I am fixing our install.js script to "ask forgiveness not permission" like so:

function xmkdirSync (path, mode) {
  try {
    fs.mkdirSync(path, mode)
  } catch (err) {
    if (/EPERM/.test(err.message)) {
      console.error('Failed to create: ' + git)
      console.error('Make sure you have the necessary permissions')
    } else if (/EEXIST/.test(err.message)) {
      // do nothing
    } else {
      throw err
    }
  }
}

Is that ok? Is there perhaps some other issue I am missing?

Verbose flag

If user uses --verbose with git commit command, commitplease will try to validate added/removed lines

Support for Angular commit message style guides

I'd like to see more adoption of this project. For that it should have presents and options to support more commit message style guides. The one I'm aware of is the angular style guide for commit message. There are probably more.

I hope more people are interested in extending this project to support the style of commit messages. I've already solved the git commit-msg hook integration.

Rejects merge commit messages

The default merge message - e.g. "Merge branch 'one' into two" - is rejected by commitplease with the following message:

"- First line (subject) must indicate the component"

It seems like commitplease should probably be ok with these messages.

Install fails when a submodule uses commitplease

As the title states I am using a project as a submodule which uses commitplease.

The basic structure is that I have a master project which has several Docker containers. The master project pulls several submodules including one which has commitplease as a dev dependency. When the container which has commitplease in tries to do an npm install as build of the build container phase, the installation fails, I believe because submodules do not have a local .git folder, it is actually a reference to the submodule .git folder in the parent project.

The only workaround I have so far found is to remove commitplease as a dependency after updating the submodules and before building but this isn't an ideal situation.

Any help or guidance you could provide would be much appreciated, I have posted the nam error below for reference.

Thanks!

fatal: Not a git repository: ../.git/modules/customer_management_system
/root/cms/node_modules/commitplease/lib/sanitize.js:13
    throw error
    ^

Error: Command failed: git config --get core.commentchar
fatal: Not a git repository: ../.git/modules/customer_management_system

    at checkExecSyncError (child_process.js:483:13)
    at Object.execSync (child_process.js:523:13)
    at Object.<anonymous> (/root/cms/node_modules/commitplease/lib/sanitize.js:6:21)
    at Module._compile (module.js:556:32)
    at Object.Module._extensions..js (module.js:565:10)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)
    at Module.require (module.js:483:17)
    at require (internal/module.js:20:19)
npm info lifecycle [email protected]~install: Failed to exec install script
npm WARN [email protected] No repository field.
npm ERR! Linux 4.4.15-moby
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v6.4.0
npm ERR! nam  v3.10.3
npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: `node install`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script 'node install'.
npm ERR! Make sure you have the latest version of node.js and nam installed.
npm ERR! If you do, this is most likely a problem with the commit please package
npm ERR! not with nam itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node install
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs commit please
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls commit please
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /root/cms/npm-debug.log

Allow git commit `--fixup` and `--squash` features

git commit flags --fixup and --squash are great in rebase-centric workflows, especially in combination with git config rebase.autosquash enabled. Unfortunately, commitplease component validation will abort these commits.

The solution would be to skip validation on commits that start with "fixup!" or "squash!". These are temporary commits that will get merged into others on the next rebase, so it makes no sense to perform validation on them at this moment.

Show error in git GUI applications

Find a way to pass error message to git GUI applications like TortoiseGit or SourceTree.

Currently the commit fails in TortoiseGit but no specific error message is shown:

Invalid commit message, please fix the following issues:



git did not exit cleanly (exit code 1) (327 ms @ 05.02.2014 18:46:17)

Would be nice to have a possibility to do so.

Collaboration with similar tools

While looking for tools to generate changelogs, I've come across these two tools, that are quite similar to commitplease:

Neither automatically installs the commit-msg hook, the latter project recommends https://www.npmjs.com/package/ghooks for that.

If nothing else, we could mention these tools as alternatives. Maybe the authors would agree to deprecate their packages in favor of commitplease, since commitplease supports more presets, configuration options and automatically installs the hook.

Allow single-line commit with comments afterwards

This is valid:

Methods: Fix tests for email method. Follow-up to dd162ae
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
# Changes to be committed:

Add test watcher script

Use nodemon or similar tools to add a npm run test-watch script that reruns tests as source or test files are updated.

Allow sentences that start with "Fixes"

Invalid commit message, please fix the following issues:

  • Invalid ticket reference, must be /(Fixes|Closes) (.*#|gh-)[0-9]+/, was: Fixes issue where contenteditable text was getting overwritten when

Commit message was:

Autocomplete: Do not set value on multi-line input

Fixes issue where contenteditable text was getting overwritten when
wrapping past the bottom or top of the autocomplete menu.

Fixes #9771
Closes gh-1184

Error on rebase

I have received this error:

image

The context was:

  • squashing something like 16 commits
  • squash only the latests 15
  • the last one rewarding

Git opens vim to modify the message for the rewarding commit, I modified message, I think it was a correct commit message and then commitplease crashed with the above error. After that I continued the rebase and everything went well.

Why does `npm install -g commitplease` fail? Do we want/need global install?

Currently, npm install -g commitpllease does not work.

On the one hand, commitplease is supposed to be a locally installed devDependency that gets its configuration from package-local package.json and .npmrc as well as it expects to be installed into a .git directory.

On the other hand, tools like overcommit would prefer if an npm package supported global install.

So, figure out the exact reasons why a global commitplease install fails and decide if it makes sense to support global install at all. If it does, update install_command for overcommit in sds/overcommit#405

Remove quotes in angular-style error message

There's too many useless double quotes here:

- First line must be <type>"("<scope>"): "<subject>
Need an opening parethesis "("

Should look more like this:

- First line must be <type>(<scope>): <subject>
Need an opening parenthesis: (

(also fix the typo in parethesis -> parenthesis)

Allow user-defined patterns

For example, to require subject lines consisting of semver level, one or more repository-specific components (separated by commas or comma-space pairs and ending with a colon), and a non-empty sentence-case message, all of which must be separated by spaces:

"commitplease": {
  // Braces like http://tools.ietf.org/html/rfc6570 URI Template expressions
  // Expression syntax like https://tools.ietf.org/html/rfc5234#section-3.6 ABNF repetition
  // …with introduction of optional separator definition in ECMAScript RegExp syntax
  "subjectPattern": "{semver-level} {1* ,[\\x20]? components}: {message}",

  // Variables are usually arrays of acceptable values
  "semver-level": [ "major", "minor", "patch" ],
  "components": [ "Build", "Test", "Core", "Legacy" ],

  // Variables can also be ECMAScript regular expressions in ESTree format
  // https://github.com/estree/estree/blob/master/spec.md#regexpliteral
  "message": {
    "regex": { "pattern": "^[^a-z\\s].*" },

    // …plus an optional human-readable description
    "description": "non-empty and sentence case (initial letter capitalized)"
  }
}

Another possibility is dropping the RegExp/variable expansion options in favor of pure RFC 5234 + RFC 7405 ABNF.

Ticket References non-bug regex fixes

fwiw, I noticed that the regexes here could be simplified a bit

https://github.com/jzaefferer/commitplease/blob/master/lib/validate.js#L48

I noticed it mainly because of the '(sd)' vs '[sd]' semi-bug on "fix", but it doesn't really matter because they're optional -- as long as the line starts with fixSOMETHING it'll detect it and complain if it doesn't include a ticket ref. So the (e[sd]) is extra on most of those.

/^(clos[ei]|fix|resolve)/i 

should do what you want. ([ei] incase someone says Closing #nnnnn)

On-demand validation

I know that @rxaviers doesn't much like the commit-msg hook, instead prefers validation as part of npm test (locally or via CI). For Globalize, he's set up a combination of nohook: true and a grunt plugin that validates a certain range of commits: https://github.com/jquery/globalize/blob/master/package.json#L76

The issues with that approach: You need the extra code to run the validation on-demand - this could be built into commitplease instead. And adding nohook: true to package.json makes this a project-wide setting. It would be better to be able to override this per install, so he could create .npmrc with [...]commitplease.nohook:true, while everyone else on the project uses the hook.

That would also be a decent answer for parts of #67

Issue running npm install when using node via homebrew

Terminal output ( {pathToProject } is in place of actual path ) when running npm install (node v5.1.0)

[email protected] install {pathToProject}/node_modules/commitplease
node install

Detected an existing git commit-msg hook
Remove it and install this package again to install commitplease properly
Mark: git status
fatal: This operation must be run in a work tree

Due to {pathToProject}/.git/hooks/commit-msg -> #!/bin/evn node

Seems to be since homebrew doesn't use /usr/bin for node or even a symlink you have to replace:

!/bin/evn node

with

!/usr/local/bin/node

The issue is installing on a fresh machine or having to reclone said project using this npm. Is there any chance of updating this so the CLI doesn't break with homebrew's install of node? It also seems in El Capitan you can't force symlinks in the /usr/bin directory, well maybe if you disabled root user but rather not go down that road.

Example, here's the ln command and output when trying to force a symlink to that directory in El Cap:

sudo ln -sf /usr/local/bin/node /usr/bin/node
ln: /usr/bin/node: Operation not permitted

Thanks in advance.

Update readme

I've changed the defaults to match the jQuery commit message rules, should get that into the readme, along with a link to that guide. Until someone asks for different rules, that should be enough.

Support Windows

@fnagel has tested on Windows 7, the module isn't working as expected. It looks like creation of the symlink fails, but it doesn't log any errors.

Node.js documents support for symlinks on Windows. Should start by verifying that. Might be an issue with the relative path.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.