diff --git a/README.md b/README.md index 54dd8824..d7ed5910 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,7 @@ using matched rule and run it. Rules enabled by default: * `cd_mkdir` – creates directories before cd'ing into them; * `cp_omitting_directory` – adds `-a` when you `cp` directory; * `fix_alt_space` – replaces Alt+Space with Space character; +* `git_add` – fix *"Did you forget to 'git add'?"*; * `git_no_command` – fixes wrong git commands like `git brnch`; * `git_push` – adds `--set-upstream origin $branch` to previous failed `git push`; * `has_exists_script` – prepends `./` when script/binary exists; diff --git a/thefuck/rules/git_add.py b/thefuck/rules/git_add.py new file mode 100644 index 00000000..66c7f1dc --- /dev/null +++ b/thefuck/rules/git_add.py @@ -0,0 +1,15 @@ +import re + + +def match(command, settings): + return ('git' in command.script + and 'did not match any file(s) known to git.' in command.stderr + and "Did you forget to 'git add'?" in command.stderr) + + +def get_new_command(command, settings): + missing_file = re.findall( + r"error: pathspec '([^']*)' " + "did not match any file\(s\) known to git.", command.stderr)[0] + + return 'git add -- {} && {}'.format(missing_file, command.script)