35
35
36
36
37
37
# Application version
38
- ver = '0.8.3 '
38
+ ver = '0.8.5 '
39
39
40
40
# Default paths to Mercurial and Git
41
41
hg_cmd = 'hg'
@@ -1454,15 +1454,24 @@ def thunk(parsed_args):
1454
1454
def new (name , scm = 'git' , program = False , library = False , mbedlib = False , create_only = False , depth = None , protocol = None ):
1455
1455
global cwd_root
1456
1456
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 )
1459
1459
if program and library :
1460
1460
error ("Cannot use both --program and --library options." , 1 )
1461
1461
elif program or library :
1462
1462
d_type = 'library' if library else 'program'
1463
1463
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 ):
1464
1472
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 )
1466
1475
1467
1476
if scm and scm != 'none' :
1468
1477
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
1486
1495
1487
1496
action ("Creating new %s \" %s\" (%s)" % (d_type , os .path .basename (d_path ), scm ))
1488
1497
p = Program (d_path )
1489
-
1490
1498
if d_type == 'program' :
1491
1499
# This helps sub-commands to display relative paths to the created program
1492
1500
cwd_root = os .path .abspath (d_path )
@@ -1544,7 +1552,7 @@ def import_(url, path=None, ignore=False, depth=None, protocol=None, top=True):
1544
1552
error ("Directory \" %s\" is not empty. Please ensure that the destination folder is empty." % repo .path , 1 )
1545
1553
1546
1554
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 ))))
1548
1556
if repo .clone (repo .url , repo .path , rev = repo .rev , depth = depth , protocol = protocol ):
1549
1557
with cd (repo .path ):
1550
1558
Program (repo .path ).set_root ()
0 commit comments