| | @@ -172,11 +172,11 @@ |
| 172 | 172 | if( g.url.protocol==0 ){ |
| 173 | 173 | if( urlOptional ) fossil_exit(0); |
| 174 | 174 | usage("URL"); |
| 175 | 175 | } |
| 176 | 176 | user_select(); |
| 177 | | - if( g.argc==2 ){ |
| 177 | + if( g.url.isAlias ){ |
| 178 | 178 | if( ((*pSyncFlags) & (SYNC_PUSH|SYNC_PULL))==(SYNC_PUSH|SYNC_PULL) ){ |
| 179 | 179 | fossil_print("Sync with %s\n", g.url.canonical); |
| 180 | 180 | }else if( (*pSyncFlags) & SYNC_PUSH ){ |
| 181 | 181 | fossil_print("Push to %s\n", g.url.canonical); |
| 182 | 182 | }else if( (*pSyncFlags) & SYNC_PULL ){ |
| | @@ -197,11 +197,11 @@ |
| 197 | 197 | ** wiki pages, tickets, and tech-notes, as well as forum content. Add |
| 198 | 198 | ** the --private option to pull private branches. Use the |
| 199 | 199 | ** "configuration pull" command to pull website configuration details. |
| 200 | 200 | ** |
| 201 | 201 | ** If URL is not specified, then the URL from the most recent clone, push, |
| 202 | | -** pull, remote-url, or sync command is used. See "fossil help clone" for |
| 202 | +** pull, remote, or sync command is used. See "fossil help clone" for |
| 203 | 203 | ** details on the URL formats. |
| 204 | 204 | ** |
| 205 | 205 | ** Options: |
| 206 | 206 | ** |
| 207 | 207 | ** -B|--httpauth USER:PASS Credentials for the simple HTTP auth protocol, |
| | @@ -217,11 +217,11 @@ |
| 217 | 217 | ** --ssh-command SSH Use SSH as the "ssh" command |
| 218 | 218 | ** -v|--verbose Additional (debugging) output |
| 219 | 219 | ** --verily Exchange extra information with the remote |
| 220 | 220 | ** to ensure no content is overlooked |
| 221 | 221 | ** |
| 222 | | -** See also: clone, config pull, push, remote-url, sync |
| 222 | +** See also: clone, config pull, push, remote, sync |
| 223 | 223 | */ |
| 224 | 224 | void pull_cmd(void){ |
| 225 | 225 | unsigned configFlags = 0; |
| 226 | 226 | unsigned syncFlags = SYNC_PULL; |
| 227 | 227 | unsigned urlOmitFlags = 0; |
| | @@ -248,11 +248,11 @@ |
| 248 | 248 | ** wiki pages, tickets, and tech-notes, as well as forum content. Use |
| 249 | 249 | ** --private to also push private branches. Use the "configuration |
| 250 | 250 | ** push" command to push website configuration details. |
| 251 | 251 | ** |
| 252 | 252 | ** If URL is not specified, then the URL from the most recent clone, push, |
| 253 | | -** pull, remote-url, or sync command is used. See "fossil help clone" for |
| 253 | +** pull, remote, or sync command is used. See "fossil help clone" for |
| 254 | 254 | ** details on the URL formats. |
| 255 | 255 | ** |
| 256 | 256 | ** Options: |
| 257 | 257 | ** |
| 258 | 258 | ** -B|--httpauth USER:PASS Credentials for the simple HTTP auth protocol, |
| | @@ -266,11 +266,11 @@ |
| 266 | 266 | ** --ssh-command SSH Use SSH as the "ssh" command |
| 267 | 267 | ** -v|--verbose Additional (debugging) output |
| 268 | 268 | ** --verily Exchange extra information with the remote |
| 269 | 269 | ** to ensure no content is overlooked |
| 270 | 270 | ** |
| 271 | | -** See also: clone, config push, pull, remote-url, sync |
| 271 | +** See also: clone, config push, pull, remote, sync |
| 272 | 272 | */ |
| 273 | 273 | void push_cmd(void){ |
| 274 | 274 | unsigned configFlags = 0; |
| 275 | 275 | unsigned syncFlags = SYNC_PUSH; |
| 276 | 276 | process_sync_args(&configFlags, &syncFlags, 0, 0); |
| | @@ -293,11 +293,11 @@ |
| 293 | 293 | ** Synchronize all sharable changes between the local repository and a |
| 294 | 294 | ** remote repository. Sharable changes include public check-ins and |
| 295 | 295 | ** edits to wiki pages, tickets, and technical notes. |
| 296 | 296 | ** |
| 297 | 297 | ** If URL is not specified, then the URL from the most recent clone, push, |
| 298 | | -** pull, remote-url, or sync command is used. See "fossil help clone" for |
| 298 | +** pull, remote, or sync command is used. See "fossil help clone" for |
| 299 | 299 | ** details on the URL formats. |
| 300 | 300 | ** |
| 301 | 301 | ** Options: |
| 302 | 302 | ** |
| 303 | 303 | ** -B|--httpauth USER:PASS Credentials for the simple HTTP auth protocol, |
| | @@ -312,11 +312,11 @@ |
| 312 | 312 | ** -u|--unversioned Also sync unversioned content |
| 313 | 313 | ** -v|--verbose Additional (debugging) output |
| 314 | 314 | ** --verily Exchange extra information with the remote |
| 315 | 315 | ** to ensure no content is overlooked |
| 316 | 316 | ** |
| 317 | | -** See also: clone, pull, push, remote-url |
| 317 | +** See also: clone, pull, push, remote |
| 318 | 318 | */ |
| 319 | 319 | void sync_cmd(void){ |
| 320 | 320 | unsigned configFlags = 0; |
| 321 | 321 | unsigned syncFlags = SYNC_PUSH|SYNC_PULL; |
| 322 | 322 | if( find_option("unversioned","u",0)!=0 ){ |
| | @@ -347,49 +347,159 @@ |
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | /* |
| 350 | 350 | ** COMMAND: remote-url |
| 351 | 351 | ** |
| 352 | | -** Usage: %fossil remote-url ?URL|off? |
| 353 | | -** |
| 354 | | -** Query and/or change the default server URL used by the "pull", "push", |
| 355 | | -** and "sync" commands. |
| 356 | | -** |
| 357 | | -** The remote-url is set automatically by a "clone" command or by any |
| 358 | | -** "sync", "push", or "pull" command that specifies an explicit URL. |
| 359 | | -** The default remote-url is used by auto-syncing and by "sync", "push", |
| 360 | | -** "pull" that omit the server URL. |
| 361 | | -** |
| 362 | | -** See "fossil help clone" for further information about URL formats |
| 363 | | -** |
| 364 | | -** See also: clone, push, pull, sync |
| 352 | +** Usage: %fossil remote ?SUBCOMMAND ...? |
| 353 | +** |
| 354 | +** Use this command to view or modify that set of remote repositories |
| 355 | +** used for sync, push, and pull. |
| 356 | +** |
| 357 | +** The default remote is set automatically by a "clone" command or by any |
| 358 | +** "sync", "push", or "pull" command that specifies an explicit URL |
| 359 | +** and omits the --once flag. The default remote is used by |
| 360 | +** auto-syncing and by "sync", "push", and "pull" that omit the server URL. |
| 361 | +** Additional remotes can be added using the "add" command or deleted |
| 362 | +** using the "delete" command. The name of additional remotes can be |
| 363 | +** used as an argument to the "sync", "push", and "pull" commands where |
| 364 | +** one would normally put a URL argument. |
| 365 | +** |
| 366 | +** See "fossil help clone" for further information about URL formats. |
| 367 | +** |
| 368 | +** The official name of this command is "remote-url" but most people |
| 369 | +** use the shortened name "remote". |
| 370 | +** |
| 371 | +** Subcommands: |
| 372 | +** |
| 373 | +** > %fossil remote |
| 374 | +** |
| 375 | +** With no arguments, this command show the current default remote. |
| 376 | +** Or if there is no default, it shows "off". The default remote is |
| 377 | +** used by autosync. The default remote is whatever URL was specified |
| 378 | +** for the most recent "sync", "push", or "pull" command that omitted |
| 379 | +** the --once option. |
| 380 | +** |
| 381 | +** > %fossil remote add NAME URL |
| 382 | +** |
| 383 | +** Add a new URL to the set of remotes. The new URL is assigned the |
| 384 | +** symbolic identifier "NAME". Subsequently, NAME can be used in place |
| 385 | +** of the full URL on commands like "push" and "pull". |
| 386 | +** |
| 387 | +** > %fossil remote delete NAME |
| 388 | +** |
| 389 | +** Delete a URL previously added by the "add" subcommand. |
| 390 | +** |
| 391 | +** > %fossil remote list |
| 392 | +** |
| 393 | +** Show all remote URLs |
| 394 | +** |
| 395 | +** > %fossil remote off |
| 396 | +** |
| 397 | +** Disable the default URL. Use this as a shorthand to prevent |
| 398 | +** autosync while in airplane mode, for example. |
| 399 | +** |
| 400 | +** > %fossil remote URL |
| 401 | +** |
| 402 | +** Make URL the new default URL. The prior default URL is replaced. |
| 365 | 403 | */ |
| 366 | 404 | void remote_url_cmd(void){ |
| 367 | | - char *zUrl; |
| 405 | + char *zUrl, *zArg; |
| 406 | + int nArg; |
| 368 | 407 | db_find_and_open_repository(0, 0); |
| 369 | 408 | |
| 370 | 409 | /* We should be done with options.. */ |
| 371 | 410 | verify_all_options(); |
| 372 | 411 | |
| 373 | | - if( g.argc!=2 && g.argc!=3 ){ |
| 374 | | - usage("?URL|off?"); |
| 412 | + if( g.argc==2 ){ |
| 413 | + /* "fossil remote" with no arguments: Show the last sync URL. */ |
| 414 | + zUrl = db_get("last-sync-url", 0); |
| 415 | + if( zUrl==0 ){ |
| 416 | + fossil_print("off\n"); |
| 417 | + }else{ |
| 418 | + url_parse(zUrl, 0); |
| 419 | + fossil_print("%s\n", g.url.canonical); |
| 420 | + } |
| 421 | + return; |
| 422 | + } |
| 423 | + zArg = g.argv[2]; |
| 424 | + nArg = (int)strlen(zArg); |
| 425 | + if( strcmp(zArg,"off")==0 ){ |
| 426 | + /* fossil remote off |
| 427 | + ** Forget the last-sync-URL and its password |
| 428 | + */ |
| 429 | + if( g.argc!=3 ) usage("off"); |
| 430 | +remote_delete_default: |
| 431 | + db_multi_exec( |
| 432 | + "DELETE FROM config WHERE name GLOB 'last-sync-*';" |
| 433 | + ); |
| 434 | + return; |
| 435 | + } |
| 436 | + if( strncmp(zArg, "list", nArg)==0 || strcmp(zArg,"ls")==0 ){ |
| 437 | + Stmt q; |
| 438 | + if( g.argc!=3 ) usage("list"); |
| 439 | + db_prepare(&q, |
| 440 | + "SELECT 'default', value FROM config WHERE name='last-sync-url'" |
| 441 | + " UNION ALL " |
| 442 | + "SELECT substr(name,10), value FROM config" |
| 443 | + " WHERE name GLOB 'sync-url:*'" |
| 444 | + " ORDER BY 1" |
| 445 | + ); |
| 446 | + while( db_step(&q)==SQLITE_ROW ){ |
| 447 | + fossil_print("%-18s %s\n", db_column_text(&q,0), db_column_text(&q,1)); |
| 448 | + } |
| 449 | + db_finalize(&q); |
| 450 | + return; |
| 451 | + } |
| 452 | + if( strcmp(zArg, "add")==0 ){ |
| 453 | + char *zName; |
| 454 | + char *zUrl; |
| 455 | + UrlData x; |
| 456 | + if( g.argc!=5 ) usage("add NAME URL"); |
| 457 | + memset(&x, 0, sizeof(x)); |
| 458 | + zName = g.argv[3]; |
| 459 | + zUrl = g.argv[4]; |
| 460 | + if( strcmp(zName,"default")==0 ) goto remote_add_default; |
| 461 | + url_parse_local(zUrl, URL_PROMPT_PW, &x); |
| 462 | + db_begin_write(); |
| 463 | + db_multi_exec( |
| 464 | + "REPLACE INTO config(name, value, mtime)" |
| 465 | + " VALUES('sync-url:%q',%Q,now())", |
| 466 | + zName, x.canonical |
| 467 | + ); |
| 468 | + db_multi_exec( |
| 469 | + "REPLACE INTO config(name, value, mtime)" |
| 470 | + " VALUES('sync-pw:%q',obscure(%Q),now())", |
| 471 | + zName, x.passwd |
| 472 | + ); |
| 473 | + db_commit_transaction(); |
| 474 | + return; |
| 475 | + } |
| 476 | + if( strncmp(zArg, "delete", nArg)==0 ){ |
| 477 | + char *zName; |
| 478 | + if( g.argc!=4 ) usage("delete NAME"); |
| 479 | + zName = g.argv[3]; |
| 480 | + db_begin_write(); |
| 481 | + db_multi_exec("DELETE FROM config WHERE name glob 'sync-url:%q'", zName); |
| 482 | + db_multi_exec("DELETE FROM config WHERE name glob 'sync-pw:%q'", zName); |
| 483 | + db_commit_transaction(); |
| 484 | + return; |
| 375 | 485 | } |
| 376 | | - if( g.argc==3 ){ |
| 486 | + if( sqlite3_strlike("http://%",zArg,0)==0 |
| 487 | + || sqlite3_strlike("https://%",zArg,0)==0 |
| 488 | + || sqlite3_strlike("ssh:%",zArg,0)==0 |
| 489 | + || sqlite3_strlike("file:%",zArg,0)==0 |
| 490 | + || db_exists("SELECT 1 FROM config WHERE name='sync-url:%q'",zArg) |
| 491 | + ){ |
| 492 | +remote_add_default: |
| 377 | 493 | db_unset("last-sync-url", 0); |
| 378 | 494 | db_unset("last-sync-pw", 0); |
| 379 | | - if( is_false(g.argv[2]) ) return; |
| 380 | | - url_parse(g.argv[2], URL_REMEMBER|URL_PROMPT_PW|URL_ASK_REMEMBER_PW); |
| 381 | | - } |
| 382 | | - url_remember(); |
| 383 | | - zUrl = db_get("last-sync-url", 0); |
| 384 | | - if( zUrl==0 ){ |
| 385 | | - fossil_print("off\n"); |
| 386 | | - return; |
| 387 | | - }else{ |
| 388 | | - url_parse(zUrl, 0); |
| 389 | | - fossil_print("%s\n", g.url.canonical); |
| 390 | | - } |
| 495 | + url_parse(g.argv[2], URL_REMEMBER|URL_PROMPT_PW|URL_ASK_REMEMBER_PW); |
| 496 | + url_remember(); |
| 497 | + return; |
| 498 | + } |
| 499 | + fossil_fatal("unknown command \"%s\" - should be a URL or one of: " |
| 500 | + "add delete list off", zArg); |
| 391 | 501 | } |
| 392 | 502 | |
| 393 | 503 | /* |
| 394 | 504 | ** COMMAND: backup* |
| 395 | 505 | ** |
| 396 | 506 | |