Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uv init fails to create .git directory or .gitignore file when inside git repo #11655

Open
mason-fabel opened this issue Feb 20, 2025 · 5 comments · May be fixed by #11785
Open

uv init fails to create .git directory or .gitignore file when inside git repo #11655

mason-fabel opened this issue Feb 20, 2025 · 5 comments · May be fixed by #11785
Labels
bug Something isn't working

Comments

@mason-fabel
Copy link

mason-fabel commented Feb 20, 2025

Summary

When inside of a git repo, running uv init my-project --vsc=git does not create a .git directory or .gitignore file in my-project.

For example, my $HOME is a git repo containing my dotfiles, and I'm trying to create an uv project at $HOME/dev/my-project.

Output

$ uv init my-project --vcs=git --verbose
DEBUG uv 0.6.2
DEBUG Checking for Python environment at `my-project/.venv`
DEBUG Searching for default Python interpreter in managed installations or search path
DEBUG Searching for managed installations at `/home/username/.local/share/uv/python`
DEBUG Found `cpython-3.13.0-linux-x86_64-gnu` at `/usr/bin/python` (first executable in the search path)
DEBUG Writing python versions to `/home/username/dev/my-project/.python-version`
$ rm -rf my-project
$ uv init my-project --verbose
DEBUG uv 0.6.2
DEBUG Checking for Python environment at `my-project/.venv`
DEBUG Searching for default Python interpreter in managed installations or search path
DEBUG Searching for managed installations at `/home/username/.local/share/uv/python`
DEBUG Found `cpython-3.13.0-linux-x86_64-gnu` at `/usr/bin/python` (first executable in the search path)
DEBUG Detected existing version control system: git
DEBUG Writing python versions to `/home/username/dev/my-project/.python-version`
Initialized project `my-project` at `/home/username/dev/my-project`

Example

git init
uv init my-project --vcs=git
cd my-project

# Expected: default uv .gitignore file
# Result: cat: .gitignore: No such file or directory
cat .gitignore

# Expected: new .git directory
# Result: ls: cannot access '.git': No such file or directory
ls .git

Platform

Fedora Linux 41 (Sway) - Linux 6.12.4-200.fc41.x86_64 x86_64 GNU/Linux

Version

uv 0.6.2

Python version

Python 3.13.0

@mason-fabel mason-fabel added the bug Something isn't working label Feb 20, 2025
@mason-fabel
Copy link
Author

mason-fabel commented Feb 20, 2025

Maybe this shouldn't be labelled as a bug? Reading the comments at

(Some(vcs), Some(existing)) => {
// If they differ, raise an error.
if vcs != existing {
anyhow::bail!("The project is already in a version control system (`{existing}`); cannot initialize with `--vcs {vcs}`");
}
// Otherwise, ignore the specified VCS, since it's already in use.
VersionControlSystem::None
}
it looks like I'm running into an intentional design (or at least an unconsidered edge case).

I get what uv is doing by default, it's probably the correct default even, but I would like something like uv init my-project --vsc=git --force to confirm that I really mean it when I'm asking for a fresh .git directory and I know what I'm doing. I'm borrowing the --force flag from git, I have no particular attachment to that name.

@zanieb
Copy link
Member

zanieb commented Feb 20, 2025

I feel like this is a valid use-case. I think we could perhaps treat an explicit --vcs=git as "force" (vs the default "auto" behavior)

@mason-fabel
Copy link
Author

mason-fabel commented Feb 20, 2025

That makes sense to me. In fact, that's what I initially assumed would happen and led to this issue.

I haven't finished setting up the repo locally, but I'm happy to work on a patch for this. Would (Some(vcs), Some(existing)) => vcs be an appropriate solution, or are there other edge cases I'm not aware of in play here?

mason-fabel pushed a commit to mason-fabel/uv that referenced this issue Feb 26, 2025
Fixes some tests in when parent dir has .git dir

Resolves astral-sh#11655
@mason-fabel mason-fabel linked a pull request Feb 26, 2025 that will close this issue
@Chaoses-Ib
Copy link

Regarding the default behavior, how about creating .gitignore but without .git? Currently, one has to write .gitignore manually if the project is inited inside an existing repo that doesn't have ignore rules for Python. If uv creates .gitignore by default, this can be skipped, and if someone doesn't want it they can simply remove it, much eaiser than the opposite.

@mason-fabel
Copy link
Author

@Chaoses-Ib I don't understand, what are you proposing? Are you saying uv init <project> should always create a .gitignore, even when <project> is inside a git repo?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants