| 153 | |
| 154 | |
| 155 | def check_gitignore(git_root, io, ask=True): |
| 156 | if not git_root: |
| 157 | return |
| 158 | |
| 159 | try: |
| 160 | repo = git.Repo(git_root) |
| 161 | patterns_to_add = [] |
| 162 | |
| 163 | if not repo.ignored(".aider"): |
| 164 | patterns_to_add.append(".aider*") |
| 165 | |
| 166 | env_path = Path(git_root) / ".env" |
| 167 | if env_path.exists() and not repo.ignored(".env"): |
| 168 | patterns_to_add.append(".env") |
| 169 | |
| 170 | if not patterns_to_add: |
| 171 | return |
| 172 | |
| 173 | gitignore_file = Path(git_root) / ".gitignore" |
| 174 | if gitignore_file.exists(): |
| 175 | try: |
| 176 | content = io.read_text(gitignore_file) |
| 177 | if content is None: |
| 178 | return |
| 179 | if not content.endswith("\n"): |
| 180 | content += "\n" |
| 181 | except OSError as e: |
| 182 | io.tool_error(f"Error when trying to read {gitignore_file}: {e}") |
| 183 | return |
| 184 | else: |
| 185 | content = "" |
| 186 | except ANY_GIT_ERROR: |
| 187 | return |
| 188 | |
| 189 | if ask: |
| 190 | io.tool_output("You can skip this check with --no-gitignore") |
| 191 | if not io.confirm_ask(f"Add {', '.join(patterns_to_add)} to .gitignore (recommended)?"): |
| 192 | return |
| 193 | |
| 194 | content += "\n".join(patterns_to_add) + "\n" |
| 195 | |
| 196 | try: |
| 197 | io.write_text(gitignore_file, content) |
| 198 | io.tool_output(f"Added {', '.join(patterns_to_add)} to .gitignore") |
| 199 | except OSError as e: |
| 200 | io.tool_error(f"Error when trying to write to {gitignore_file}: {e}") |
| 201 | io.tool_output( |
| 202 | "Try running with appropriate permissions or manually add these patterns to .gitignore:" |
| 203 | ) |
| 204 | for pattern in patterns_to_add: |
| 205 | io.tool_output(f" {pattern}") |
| 206 | |
| 207 | |
| 208 | def check_streamlit_install(io): |