File tree Expand file tree Collapse file tree 3 files changed +75
-5
lines changed Expand file tree Collapse file tree 3 files changed +75
-5
lines changed Original file line number Diff line number Diff line change @@ -68,13 +68,22 @@ This file should have the following format:
68
68
------------
69
69
70
70
`<url>` is required; `#<head>` is optional.
71
- When you do not provide a refspec on the command line,
72
- git will use the following refspec, where `<head>` defaults to `master`,
73
- and `<repository>` is the name of this file
74
- you provided in the command line.
71
+
72
+ Depending on the operation, git will use one of the following
73
+ refspecs, if you don't provide one on the command line.
74
+ `<branch>` is the name of this file in `$GIT_DIR/branches` and
75
+ `<head>` defaults to `master`.
76
+
77
+ git fetch uses:
78
+
79
+ ------------
80
+ refs/heads/<head>:refs/heads/<branch>
81
+ ------------
82
+
83
+ git push uses:
75
84
76
85
------------
77
- refs/heads/<head>:<repository >
86
+ HEAD: refs/heads/<head>
78
87
------------
79
88
80
89
Original file line number Diff line number Diff line change @@ -298,6 +298,17 @@ static void read_branches_file(struct remote *remote)
298
298
}
299
299
add_url_alias (remote , p );
300
300
add_fetch_refspec (remote , strbuf_detach (& branch , 0 ));
301
+ /*
302
+ * Cogito compatible push: push current HEAD to remote #branch
303
+ * (master if missing)
304
+ */
305
+ strbuf_init (& branch , 0 );
306
+ strbuf_addstr (& branch , "HEAD" );
307
+ if (frag )
308
+ strbuf_addf (& branch , ":refs/heads/%s" , frag );
309
+ else
310
+ strbuf_addstr (& branch , ":refs/heads/master" );
311
+ add_push_refspec (remote , strbuf_detach (& branch , 0 ));
301
312
remote -> fetch_tags = 1 ; /* always auto-follow */
302
313
}
303
314
Original file line number Diff line number Diff line change @@ -494,4 +494,54 @@ test_expect_success 'allow deleting an invalid remote ref' '
494
494
495
495
'
496
496
497
+ test_expect_success ' fetch with branches' '
498
+ mk_empty &&
499
+ git branch second $the_first_commit &&
500
+ git checkout second &&
501
+ echo ".." > testrepo/.git/branches/branch1 &&
502
+ (cd testrepo &&
503
+ git fetch branch1 &&
504
+ r=$(git show-ref -s --verify refs/heads/branch1) &&
505
+ test "z$r" = "z$the_commit" &&
506
+ test 1 = $(git for-each-ref refs/heads | wc -l)
507
+ ) &&
508
+ git checkout master
509
+ '
510
+
511
+ test_expect_success ' fetch with branches containing #' '
512
+ mk_empty &&
513
+ echo "..#second" > testrepo/.git/branches/branch2 &&
514
+ (cd testrepo &&
515
+ git fetch branch2 &&
516
+ r=$(git show-ref -s --verify refs/heads/branch2) &&
517
+ test "z$r" = "z$the_first_commit" &&
518
+ test 1 = $(git for-each-ref refs/heads | wc -l)
519
+ ) &&
520
+ git checkout master
521
+ '
522
+
523
+ test_expect_success ' push with branches' '
524
+ mk_empty &&
525
+ git checkout second &&
526
+ echo "testrepo" > .git/branches/branch1 &&
527
+ git push branch1 &&
528
+ (cd testrepo &&
529
+ r=$(git show-ref -s --verify refs/heads/master) &&
530
+ test "z$r" = "z$the_first_commit" &&
531
+ test 1 = $(git for-each-ref refs/heads | wc -l)
532
+ )
533
+ '
534
+
535
+ test_expect_success ' push with branches containing #' '
536
+ mk_empty &&
537
+ echo "testrepo#branch3" > .git/branches/branch2 &&
538
+ git push branch2 &&
539
+ (cd testrepo &&
540
+ r=$(git show-ref -s --verify refs/heads/branch3) &&
541
+ test "z$r" = "z$the_first_commit" &&
542
+ test 1 = $(git for-each-ref refs/heads | wc -l)
543
+ ) &&
544
+ git checkout master
545
+ '
546
+
497
547
test_done
You can’t perform that action at this time.
0 commit comments