3535
3636
3737# Application version
38- ver = '0.8.3 '
38+ ver = '0.8.5 '
3939
4040# Default paths to Mercurial and Git
4141hg_cmd = 'hg'
@@ -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 )
@@ -1544,7 +1552,7 @@ def import_(url, path=None, ignore=False, depth=None, protocol=None, top=True):
15441552 error ("Directory \" %s\" is not empty. Please ensure that the destination folder is empty." % repo .path , 1 )
15451553
15461554 text = "Importing program" if top else "Adding library"
1547- action ("%s \" %s\" from \" %s/ \" %s" % (text , relpath (cwd_root , repo .path ), repo .url , ' at ' + (repo .revtype (repo .rev , True ))))
1555+ action ("%s \" %s\" from \" %s\" %s" % (text , relpath (cwd_root , repo .path ), formaturl ( repo .url , protocol ) , ' at ' + (repo .revtype (repo .rev , True ))))
15481556 if repo .clone (repo .url , repo .path , rev = repo .rev , depth = depth , protocol = protocol ):
15491557 with cd (repo .path ):
15501558 Program (repo .path ).set_root ()
0 commit comments