Skip to content

Commit d68b2cb

Browse files
authored
Fix create directory behavior (#983)
1 parent 6a2cf71 commit d68b2cb

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/nimble.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,7 @@ proc init(options: Options) =
963963
raise nimbleError("Please install git or mercurial first")
964964

965965
# Determine the package name.
966+
let hasProjectName = options.action.projName != ""
966967
let pkgName =
967968
if options.action.projName != "":
968969
options.action.projName
@@ -974,7 +975,7 @@ proc init(options: Options) =
974975

975976
# Determine the package root.
976977
let pkgRoot =
977-
if pkgName == os.getCurrentDir().splitPath.tail:
978+
if not hasProjectName:
978979
os.getCurrentDir()
979980
else:
980981
os.getCurrentDir() / pkgName

tests/tester.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import testscommon
55

66
# suits imports
77

8+
import tinitcommand
89
import tcheckcommand
910
import tcleancommand
1011
import tdevelopfeature

tests/tinitcommand.nim

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{.used.}
2+
3+
import unittest, os
4+
import testscommon
5+
6+
from nimblepkg/common import cd
7+
8+
suite "init":
9+
## https://github.com/nim-lang/nimble/pull/983
10+
test "init within directory that is invalid package name will not create new directory":
11+
let tempdir = getTempDir() / "a-b"
12+
createDir(tempdir)
13+
cd(tempdir):
14+
let args = ["init"]
15+
let (output, exitCode) = execNimbleYes(args)
16+
discard output
17+
check exitCode == QuitSuccess
18+
check not dirExists("a_b")
19+
check fileExists("a_b.nimble")

0 commit comments

Comments
 (0)