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

Fix create directory behavior #983

Merged
merged 6 commits into from
Mar 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/nimble.nim
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,7 @@ proc init(options: Options) =
raise nimbleError("Please install git or mercurial first")

# Determine the package name.
let hasProjectName = options.action.projName != ""
let pkgName =
if options.action.projName != "":
options.action.projName
Expand All @@ -974,7 +975,7 @@ proc init(options: Options) =

# Determine the package root.
let pkgRoot =
if pkgName == os.getCurrentDir().splitPath.tail:
if not hasProjectName:
os.getCurrentDir()
else:
os.getCurrentDir() / pkgName
Expand Down
1 change: 1 addition & 0 deletions tests/tester.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import testscommon

# suits imports

import tinitcommand
import tcheckcommand
import tcleancommand
import tdevelopfeature
Expand Down
19 changes: 19 additions & 0 deletions tests/tinitcommand.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{.used.}

import unittest, os
import testscommon

from nimblepkg/common import cd

suite "init":
## https://github.com/nim-lang/nimble/pull/983
test "init within directory that is invalid package name will not create new directory":
let tempdir = getTempDir() / "a-b"
createDir(tempdir)
cd(tempdir):
let args = ["init"]
let (output, exitCode) = execNimbleYes(args)
discard output
check exitCode == QuitSuccess
check not dirExists("a_b")
check fileExists("a_b.nimble")