@@ -24,8 +24,9 @@ static const char * const builtin_remote_usage[] = {
24
24
N_ ("git remote set-branches [--add] <name> <branch>..." ),
25
25
N_ ("git remote get-url [--push] [--all] <name>" ),
26
26
N_ ("git remote set-url [--push] <name> <newurl> [<oldurl>]" ),
27
- N_ ("git remote set-url --add <name> <newurl>" ),
28
- N_ ("git remote set-url --delete <name> <url>" ),
27
+ N_ ("git remote set-url --add [--push] <name> <newurl>" ),
28
+ N_ ("git remote set-url --delete [--push] <name> <url>" ),
29
+ N_ ("git remote set-url --save-to-push <name> <url>" ),
29
30
NULL
30
31
};
31
32
@@ -77,8 +78,9 @@ static const char * const builtin_remote_geturl_usage[] = {
77
78
78
79
static const char * const builtin_remote_seturl_usage [] = {
79
80
N_ ("git remote set-url [--push] <name> <newurl> [<oldurl>]" ),
80
- N_ ("git remote set-url --add <name> <newurl>" ),
81
- N_ ("git remote set-url --delete <name> <url>" ),
81
+ N_ ("git remote set-url --add [--push] <name> <newurl>" ),
82
+ N_ ("git remote set-url --delete [--push] <name> <url>" ),
83
+ N_ ("git remote set-url --save-to-push <name> <url>" ),
82
84
NULL
83
85
};
84
86
@@ -1519,7 +1521,7 @@ static int get_url(int argc, const char **argv)
1519
1521
1520
1522
static int set_url (int argc , const char * * argv )
1521
1523
{
1522
- int i , push_mode = 0 , add_mode = 0 , delete_mode = 0 ;
1524
+ int i , push_mode = 0 , save_to_push = 0 , add_mode = 0 , delete_mode = 0 ;
1523
1525
int matches = 0 , negative_matches = 0 ;
1524
1526
const char * remotename = NULL ;
1525
1527
const char * newurl = NULL ;
@@ -1532,6 +1534,8 @@ static int set_url(int argc, const char **argv)
1532
1534
struct option options [] = {
1533
1535
OPT_BOOL ('\0' , "push" , & push_mode ,
1534
1536
N_ ("manipulate push URLs" )),
1537
+ OPT_BOOL ('\0' , "save-to-push" , & save_to_push ,
1538
+ N_ ("change fetching URL behavior" )),
1535
1539
OPT_BOOL ('\0' , "add" , & add_mode ,
1536
1540
N_ ("add URL" )),
1537
1541
OPT_BOOL ('\0' , "delete" , & delete_mode ,
@@ -1543,6 +1547,8 @@ static int set_url(int argc, const char **argv)
1543
1547
1544
1548
if (add_mode && delete_mode )
1545
1549
die (_ ("--add --delete doesn't make sense" ));
1550
+ if (save_to_push && (push_mode || add_mode || delete_mode ))
1551
+ die (_ ("--save-to-push cannot be used with other options" ));
1546
1552
1547
1553
if (argc < 3 || argc > 4 || ((add_mode || delete_mode ) && argc != 3 ))
1548
1554
usage_with_options (builtin_remote_seturl_usage , options );
@@ -1564,6 +1570,16 @@ static int set_url(int argc, const char **argv)
1564
1570
urlset = remote -> pushurl ;
1565
1571
urlset_nr = remote -> pushurl_nr ;
1566
1572
} else {
1573
+ if (save_to_push ) {
1574
+ if (remote -> url_nr != 1 )
1575
+ die (_ ("--save-to-push can only be used when only one url is defined" ));
1576
+
1577
+ strbuf_addf (& name_buf , "remote.%s.pushurl" , remotename );
1578
+ git_config_set_multivar (name_buf .buf ,
1579
+ remote -> url [0 ], "^$" , 0 );
1580
+ strbuf_reset (& name_buf );
1581
+ }
1582
+
1567
1583
strbuf_addf (& name_buf , "remote.%s.url" , remotename );
1568
1584
urlset = remote -> url ;
1569
1585
urlset_nr = remote -> url_nr ;
0 commit comments