def __call__(self): if git.is_staging_clean(): out.write("No files added to staging!") raise SystemExit(NOTHING_TO_COMMIT) retry: bool = self.arguments.get("retry") if retry: m = self.read_backup_message() else: m = self.prompt_commit_questions() out.info(f"\n{m}\n") c = git.commit(m) if c.err: out.error(c.err) # Create commit backup with open(self.temp_file, "w") as f: f.write(m) raise SystemExit(COMMIT_ERROR) if "nothing added" in c.out or "no changes added to commit" in c.out: out.error(c.out) elif c.err: out.error(c.err) else: with contextlib.suppress(FileNotFoundError): os.remove(self.temp_file) out.write(c.out) out.success("Commit successful!")
def __call__(self): values_to_add = {} # No config for commitizen exist if not self.config.path: config_path = self._ask_config_path() if "toml" in config_path: self.config = TomlConfig(data="", path=config_path) else: self.config = IniConfig(data="", path=config_path) self.config.init_empty_config_content() values_to_add["name"] = self._ask_name() tag = self._ask_tag() values_to_add["version"] = Version(tag).public values_to_add["tag_format"] = self._ask_tag_format(tag) self._update_config_file(values_to_add) out.write( "You can bump the version and create cangelog running:\n") out.info("cz bump --changelog") out.success("The configuration are all set.") else: # TODO: handle the case that config file exist but no value out.line(f"Config file {self.config.path} already exists")
def __call__(self): values_to_add = {} # No config for commitizen exist if not self.config.path: config_path = self._ask_config_path() if "toml" in config_path: self.config = TomlConfig(data="", path=config_path) elif "json" in config_path: self.config = JsonConfig(data="{}", path=config_path) elif "yaml" in config_path: self.config = YAMLConfig(data="", path=config_path) self.config.init_empty_config_content() values_to_add["name"] = self._ask_name() tag = self._ask_tag() values_to_add["version"] = Version(tag).public values_to_add["tag_format"] = self._ask_tag_format(tag) self._update_config_file(values_to_add) if questionary.confirm( "Do you want to install pre-commit hook?").ask(): self._install_pre_commit_hook() out.write( "You can bump the version and create changelog running:\n") out.info("cz bump --changelog") out.success("The configuration are all set.") else: out.line(f"Config file {self.config.path} already exists")
def is_initial_tag(self, current_tag_version: str, is_yes: bool = False) -> bool: """Check if reading the whole git tree up to HEAD is needed.""" is_initial = False if not git.tag_exist(current_tag_version): if is_yes: is_initial = True else: out.info(f"Tag {current_tag_version} could not be found. ") out.info( ( "Possible causes:\n" "- version in configuration is not the current version\n" "- tag_format is missing, check them using 'git tag --list'\n" ) ) is_initial = questionary.confirm("Is this the first tag created?").ask() return is_initial
def __call__(self): dry_run: bool = self.arguments.get("dry_run") if git.is_staging_clean() and not dry_run: raise NothingToCommitError("No files added to staging!") retry: bool = self.arguments.get("retry") if retry: m = self.read_backup_message() else: m = self.prompt_commit_questions() out.info(f"\n{m}\n") if dry_run: raise DryRunExit() signoff: bool = self.arguments.get("signoff") if signoff: c = git.commit(m, "-s") else: c = git.commit(m) if c.return_code != 0: out.error(c.err) # Create commit backup with open(self.temp_file, "w") as f: f.write(m) raise CommitError() if "nothing added" in c.out or "no changes added to commit" in c.out: out.error(c.out) else: with contextlib.suppress(FileNotFoundError): os.remove(self.temp_file) out.write(c.err) out.write(c.out) out.success("Commit successful!")
def __call__(self): cz = self.cz questions = cz.questions() answers = questionary.prompt(questions) if not answers: raise SystemExit(NO_ANSWERS) m = cz.message(answers) out.info(f"\n{m}\n") c = git.commit(m) if c.err: out.error(c.err) raise SystemExit(COMMIT_ERROR) if "nothing added" in c.out or "no changes added to commit" in c.out: out.error(c.out) elif c.err: out.error(c.err) else: out.write(c.out) out.success("Commit successful!")