@@ -1454,15 +1454,24 @@ def thunk(parsed_args):
14541454def new (name , scm = 'git' , program = False , library = False , mbedlib = False , create_only = False , depth = None , protocol = None ):
14551455 global cwd_root
14561456
1457- d_path = name or os .getcwd ()
1458- p_path = Repo . findparent (d_path ) or d_path
1457+ d_path = os . path . abspath ( name or os .getcwd () )
1458+ p_path = os . path . dirname (d_path )
14591459 if program and library :
14601460 error ("Cannot use both --program and --library options." , 1 )
14611461 elif program or library :
14621462 d_type = 'library' if library else 'program'
14631463 else :
1464+ pp = Program (p_path )
1465+ pd = Program (d_path )
1466+ if pp .path == pd .path :
1467+ d_type = 'library' if os .path .abspath (p_path ) != os .path .abspath (d_path ) else 'program'
1468+ else :
1469+ d_type = 'library' if not pp .is_cwd and os .path .abspath (p_path ) != os .path .abspath (d_path ) else 'program'
1470+
1471+ if os .path .exists (d_path ):
14641472 p = Program (d_path )
1465- d_type = 'library' if p and not p .is_cwd and os .path .abspath (p_path ) != os .path .abspath (d_path ) else 'program'
1473+ if (d_type == 'program' and not p .is_cwd ) or (d_type == 'library' and Repo .isrepo (d_path )):
1474+ error ("A %s with name \" %s\" already exists." % (d_type , os .path .basename (d_path )), 1 )
14661475
14671476 if scm and scm != 'none' :
14681477 if os .path .isdir (d_path ) and Repo .isrepo (d_path ):
@@ -1486,7 +1495,6 @@ def new(name, scm='git', program=False, library=False, mbedlib=False, create_onl
14861495
14871496 action ("Creating new %s \" %s\" (%s)" % (d_type , os .path .basename (d_path ), scm ))
14881497 p = Program (d_path )
1489-
14901498 if d_type == 'program' :
14911499 # This helps sub-commands to display relative paths to the created program
14921500 cwd_root = os .path .abspath (d_path )
0 commit comments