19
19
#include "diffcore.h"
20
20
#include "diff.h"
21
21
#include "object-store.h"
22
+ #include "dir.h"
22
23
23
24
#define OPT_QUIET (1 << 0)
24
25
#define OPT_CACHED (1 << 1)
@@ -1359,7 +1360,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)
1359
1360
char * p , * path = NULL , * sm_gitdir ;
1360
1361
struct strbuf sb = STRBUF_INIT ;
1361
1362
struct string_list reference = STRING_LIST_INIT_NODUP ;
1362
- int dissociate = 0 ;
1363
+ int dissociate = 0 , require_init = 0 ;
1363
1364
char * sm_alternate = NULL , * error_strategy = NULL ;
1364
1365
1365
1366
struct option module_clone_options [] = {
@@ -1386,6 +1387,8 @@ static int module_clone(int argc, const char **argv, const char *prefix)
1386
1387
OPT__QUIET (& quiet , "Suppress output for cloning a submodule" ),
1387
1388
OPT_BOOL (0 , "progress" , & progress ,
1388
1389
N_ ("force cloning progress" )),
1390
+ OPT_BOOL (0 , "require-init" , & require_init ,
1391
+ N_ ("disallow cloning into non-empty directory" )),
1389
1392
OPT_END ()
1390
1393
};
1391
1394
@@ -1413,6 +1416,10 @@ static int module_clone(int argc, const char **argv, const char *prefix)
1413
1416
} else
1414
1417
path = xstrdup (path );
1415
1418
1419
+ if (validate_submodule_git_dir (sm_gitdir , name ) < 0 )
1420
+ die (_ ("refusing to create/use '%s' in another submodule's "
1421
+ "git dir" ), sm_gitdir );
1422
+
1416
1423
if (!file_exists (sm_gitdir )) {
1417
1424
if (safe_create_leading_directories_const (sm_gitdir ) < 0 )
1418
1425
die (_ ("could not create directory '%s'" ), sm_gitdir );
@@ -1424,6 +1431,8 @@ static int module_clone(int argc, const char **argv, const char *prefix)
1424
1431
die (_ ("clone of '%s' into submodule path '%s' failed" ),
1425
1432
url , path );
1426
1433
} else {
1434
+ if (require_init && !access (path , X_OK ) && !is_empty_dir (path ))
1435
+ die (_ ("directory not empty: '%s'" ), path );
1427
1436
if (safe_create_leading_directories_const (path ) < 0 )
1428
1437
die (_ ("could not create directory '%s'" ), path );
1429
1438
strbuf_addf (& sb , "%s/index" , sm_gitdir );
@@ -1478,6 +1487,8 @@ static void determine_submodule_update_strategy(struct repository *r,
1478
1487
die (_ ("Invalid update mode '%s' configured for submodule path '%s'" ),
1479
1488
val , path );
1480
1489
} else if (sub -> update_strategy .type != SM_UPDATE_UNSPECIFIED ) {
1490
+ if (sub -> update_strategy .type == SM_UPDATE_COMMAND )
1491
+ BUG ("how did we read update = !command from .gitmodules?" );
1481
1492
out -> type = sub -> update_strategy .type ;
1482
1493
out -> command = sub -> update_strategy .command ;
1483
1494
} else
@@ -1536,6 +1547,7 @@ struct submodule_update_clone {
1536
1547
int recommend_shallow ;
1537
1548
struct string_list references ;
1538
1549
int dissociate ;
1550
+ unsigned require_init ;
1539
1551
const char * depth ;
1540
1552
const char * recursive_prefix ;
1541
1553
const char * prefix ;
@@ -1554,7 +1566,7 @@ struct submodule_update_clone {
1554
1566
int max_jobs ;
1555
1567
};
1556
1568
#define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \
1557
- SUBMODULE_UPDATE_STRATEGY_INIT, 0, 0, -1, STRING_LIST_INIT_DUP, 0, \
1569
+ SUBMODULE_UPDATE_STRATEGY_INIT, 0, 0, -1, STRING_LIST_INIT_DUP, 0, 0, \
1558
1570
NULL, NULL, NULL, \
1559
1571
NULL, 0, 0, 0, NULL, 0, 0, 1}
1560
1572
@@ -1681,6 +1693,8 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
1681
1693
argv_array_pushl (& child -> args , "--prefix" , suc -> prefix , NULL );
1682
1694
if (suc -> recommend_shallow && sub -> recommend_shallow == 1 )
1683
1695
argv_array_push (& child -> args , "--depth=1" );
1696
+ if (suc -> require_init )
1697
+ argv_array_push (& child -> args , "--require-init" );
1684
1698
argv_array_pushl (& child -> args , "--path" , sub -> path , NULL );
1685
1699
argv_array_pushl (& child -> args , "--name" , sub -> name , NULL );
1686
1700
argv_array_pushl (& child -> args , "--url" , url , NULL );
@@ -1870,6 +1884,8 @@ static int update_clone(int argc, const char **argv, const char *prefix)
1870
1884
OPT__QUIET (& suc .quiet , N_ ("don't print cloning progress" )),
1871
1885
OPT_BOOL (0 , "progress" , & suc .progress ,
1872
1886
N_ ("force cloning progress" )),
1887
+ OPT_BOOL (0 , "require-init" , & suc .require_init ,
1888
+ N_ ("disallow cloning into non-empty directory" )),
1873
1889
OPT_END ()
1874
1890
};
1875
1891
0 commit comments