def get_new_command(command): missing_file = re.findall( r"error: pathspec '([^']*)' " r"did not match any file\(s\) known to git.", command.output)[0] closest_branch = utils.get_closest(missing_file, get_branches(), fallback_to_first=False) if closest_branch: return replace_argument(command.script, missing_file, closest_branch) elif command.script_parts[1] == 'checkout': return replace_argument(command.script, 'checkout', 'checkout -b') else: return shell.and_('git branch {}', '{}').format(missing_file, command.script)
def get_new_command(command): unknown_branch = re.findall(r'merge: (.+) - not something we can merge', command.output)[0] remote_branch = re.findall(r'Did you mean this\?\n\t([^\n]+)', command.output)[0] return replace_argument(command.script, unknown_branch, remote_branch)
def get_new_command(command): # If --set-upstream or -u are passed, remove it and its argument. This is # because the remaining arguments are concatenated onto the command suggested # by git, which includes --set-upstream and its argument command_parts = command.script_parts[:] upstream_option_index = _get_upstream_option_index(command_parts) if upstream_option_index is not None: command_parts.pop(upstream_option_index) # In case of `git push -u` we don't have next argument: if len(command_parts) > upstream_option_index: command_parts.pop(upstream_option_index) else: # the only non-qualified permitted options are the repository and refspec; git's # suggestion include them, so they won't be lost, but would be duplicated otherwise. push_idx = command_parts.index('push') + 1 while len(command_parts) > push_idx and command_parts[ len(command_parts) - 1][0] != '-': command_parts.pop(len(command_parts) - 1) arguments = re.findall(r'git push (.*)', command.output)[-1].replace("'", r"\'").strip() return replace_argument(" ".join(command_parts), 'push', 'push {}'.format(arguments))
def get_new_command(command): for idx, arg in enumerate(command.script_parts[1:]): # allowed params to ADB are a/d/e/s/H/P/L where s, H, P and L take additional args # for example 'adb -s 111 logcat' or 'adb -e logcat' if not arg[0] == '-' and not command.script_parts[idx] in ('-s', '-H', '-P', '-L'): adb_cmd = get_closest(arg, _ADB_COMMANDS) return replace_argument(command.script, arg, adb_cmd)
def get_new_command(command): destination = _get_destination(command) paths = _get_all_absolute_paths_from_history(command) return [ replace_argument(command.script, destination, path) for path in paths if path.endswith(destination) and Path(path).expanduser().exists() ]
def get_new_command(command): misspelled_task = regex.findall(command.output)[0] if misspelled_task in npm_commands: yarn_command = npm_commands[misspelled_task] return replace_argument(command.script, misspelled_task, yarn_command) else: tasks = _get_all_tasks() return replace_command(command, misspelled_task, tasks)
def get_new_command(command): stash_cmd = command.script_parts[2] fixed = utils.get_closest(stash_cmd, stash_commands, fallback_to_first=False) if fixed is not None: return replace_argument(command.script, stash_cmd, fixed) else: cmd = command.script_parts[:] cmd.insert(2, 'save') return ' '.join(cmd)
def get_new_command(command): broken_cmd = re.findall(r'ERROR: unknown command \"([a-z]+)\"', command.output)[0] new_cmd = re.findall(r'maybe you meant \"([a-z]+)\"', command.output)[0] return replace_argument(command.script, broken_cmd, new_cmd)
def get_new_command(command): return replace_argument(command.script, 'tag', 'tag --force')
def test_replace_argument(args, result): assert replace_argument(*args) == result
def get_new_command(command): not_exist_formula = re.findall(r'Error: No available formula for ([a-z]+)', command.output)[0] exist_formula = _get_similar_formula(not_exist_formula) return replace_argument(command.script, not_exist_formula, exist_formula)
def get_new_command(command): if re.search(help_regex, command.output) is not None: match_obj = re.search(help_regex, command.output, re.I) return match_obj.group(1) return replace_argument(command.script, '-h', '--help')
def get_new_command(command): to = command.output.split('`')[1] return replace_argument(command.script, to[1:], to)
def get_new_command(command): return replace_argument(command.script, 'diff', 'diff --no-index')
def get_new_command(command): return replace_argument(command.script, 'diff', 'diff --staged')
def get_new_command(command): npm_commands = _get_available_commands(command.output) wrong_command = _get_wrong_command(command.script_parts) fixed = get_closest(wrong_command, npm_commands) return replace_argument(command.script, wrong_command, fixed)
def get_new_command(command): return replace_argument(command.script, '-d', '-D')
def get_new_command(command): return replace_argument(command.script, 'push', 'push --force-with-lease')
def get_new_command(command): return shell.and_(replace_argument(command.script, 'push', 'pull'), command.script)
def get_new_command(command): command_name = _get_command_name(command) return replace_argument(command.script, command_name, u'env "PATH=$PATH" {}'.format(command_name))
def get_new_command(command): return replace_argument(command.script, "-s", "-S")
def get_new_command(command): return replace_argument(command.script, 'set-url', 'add')
def get_new_command(command): return replace_argument(command.script, 'pull', 'clone')
def get_new_command(command): broken = command.script_parts[1] fix = re.findall(r'Did you mean `([^`]*)`', command.output)[0] return replace_argument(command.script, broken, fix)
def get_new_command(command): mistake = re.search(INVALID_CHOICE, command.output).group(1) options = re.findall(OPTIONS, command.output, flags=re.MULTILINE) return [replace_argument(command.script, mistake, o) for o in options]