@@ -181,6 +181,15 @@ void rugged_remote_init_callbacks_and_payload_from_options(
181
181
}
182
182
}
183
183
184
+ static void init_custom_headers (VALUE rb_options , git_strarray * custom_headers )
185
+ {
186
+ if (!NIL_P (rb_options ))
187
+ {
188
+ VALUE rb_headers = rb_hash_aref (rb_options , CSTR2SYM ("headers" ));
189
+ rugged_rb_ary_to_strarray (rb_headers , custom_headers );
190
+ }
191
+ }
192
+
184
193
static int parse_prune_type (VALUE rb_prune_type )
185
194
{
186
195
if (rb_prune_type == Qtrue ) {
@@ -254,11 +263,15 @@ static VALUE rugged_rhead_new(const git_remote_head *head)
254
263
* of the Rugged::Credentials types, or a proc returning one of the former.
255
264
* The proc will be called with the +url+, the +username+ from the url (if applicable) and
256
265
* a list of applicable credential types.
266
+ *
267
+ * :headers ::
268
+ * Extra HTTP headers to include with the request (only applies to http:// or https:// remotes)
257
269
*/
258
270
static VALUE rb_git_remote_ls (int argc , VALUE * argv , VALUE self )
259
271
{
260
272
git_remote * remote ;
261
273
git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT ;
274
+ git_strarray custom_headers = {0 };
262
275
const git_remote_head * * heads ;
263
276
264
277
struct rugged_remote_cb_payload payload = { Qnil , Qnil , Qnil , Qnil , Qnil , Qnil , 0 };
@@ -276,8 +289,9 @@ static VALUE rb_git_remote_ls(int argc, VALUE *argv, VALUE self)
276
289
return rb_funcall (self , rb_intern ("to_enum" ), 2 , CSTR2SYM ("ls" ), rb_options );
277
290
278
291
rugged_remote_init_callbacks_and_payload_from_options (rb_options , & callbacks , & payload );
292
+ init_custom_headers (rb_options , & custom_headers );
279
293
280
- if ((error = git_remote_connect (remote , GIT_DIRECTION_FETCH , & callbacks , NULL )) ||
294
+ if ((error = git_remote_connect (remote , GIT_DIRECTION_FETCH , & callbacks , & custom_headers )) ||
281
295
(error = git_remote_ls (& heads , & heads_len , remote )))
282
296
goto cleanup ;
283
297
@@ -287,6 +301,7 @@ static VALUE rb_git_remote_ls(int argc, VALUE *argv, VALUE self)
287
301
cleanup :
288
302
289
303
git_remote_disconnect (remote );
304
+ git_strarray_free (& custom_headers );
290
305
291
306
if (payload .exception )
292
307
rb_jump_tag (payload .exception );
@@ -442,6 +457,9 @@ static VALUE rb_git_remote_push_refspecs(VALUE self)
442
457
* The proc will be called with the +url+, the +username+ from the url (if
443
458
* applicable) and a list of applicable credential types.
444
459
*
460
+ * :headers ::
461
+ * Extra HTTP headers to include with the request (only applies to http:// or https:// remotes)
462
+ *
445
463
* Example:
446
464
*
447
465
* remote = repo.remotes["origin"]
@@ -452,6 +470,7 @@ static VALUE rb_git_remote_check_connection(int argc, VALUE *argv, VALUE self)
452
470
{
453
471
git_remote * remote ;
454
472
git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT ;
473
+ git_strarray custom_headers = {0 };
455
474
struct rugged_remote_cb_payload payload = { Qnil , Qnil , Qnil , Qnil , Qnil , Qnil , 0 };
456
475
VALUE rb_direction , rb_options ;
457
476
ID id_direction ;
@@ -470,10 +489,13 @@ static VALUE rb_git_remote_check_connection(int argc, VALUE *argv, VALUE self)
470
489
rb_raise (rb_eTypeError , "Invalid direction. Expected :fetch or :push" );
471
490
472
491
rugged_remote_init_callbacks_and_payload_from_options (rb_options , & callbacks , & payload );
492
+ init_custom_headers (rb_options , & custom_headers );
473
493
474
- error = git_remote_connect (remote , direction , & callbacks , NULL );
494
+ error = git_remote_connect (remote , direction , & callbacks , & custom_headers );
475
495
git_remote_disconnect (remote );
476
496
497
+ git_strarray_free (& custom_headers );
498
+
477
499
if (payload .exception )
478
500
rb_jump_tag (payload .exception );
479
501
@@ -499,6 +521,9 @@ static VALUE rb_git_remote_check_connection(int argc, VALUE *argv, VALUE self)
499
521
* The proc will be called with the +url+, the +username+ from the url (if applicable) and
500
522
* a list of applicable credential types.
501
523
*
524
+ * :headers ::
525
+ * Extra HTTP headers to include with the request (only applies to http:// or https:// remotes)
526
+ *
502
527
* :progress ::
503
528
* A callback that will be executed with the textual progress received from the remote.
504
529
* This is the text send over the progress side-band (ie. the "counting objects" output).
@@ -548,6 +573,7 @@ static VALUE rb_git_remote_fetch(int argc, VALUE *argv, VALUE self)
548
573
Data_Get_Struct (self , git_remote , remote );
549
574
550
575
rugged_remote_init_callbacks_and_payload_from_options (rb_options , & opts .callbacks , & payload );
576
+ init_custom_headers (rb_options , & opts .custom_headers );
551
577
552
578
if (!NIL_P (rb_options )) {
553
579
VALUE rb_val = rb_hash_aref (rb_options , CSTR2SYM ("message" ));
@@ -561,6 +587,7 @@ static VALUE rb_git_remote_fetch(int argc, VALUE *argv, VALUE self)
561
587
error = git_remote_fetch (remote , & refspecs , & opts , log_message );
562
588
563
589
xfree (refspecs .strings );
590
+ git_strarray_free (& opts .custom_headers );
564
591
565
592
if (payload .exception )
566
593
rb_jump_tag (payload .exception );
@@ -603,6 +630,9 @@ static VALUE rb_git_remote_fetch(int argc, VALUE *argv, VALUE self)
603
630
* A callback that will be executed each time a reference is updated remotely. It will be
604
631
* passed the +refname+, +old_oid+ and +new_oid+.
605
632
*
633
+ * :headers ::
634
+ * Extra HTTP headers to include with the push (only applies to http:// or https:// remotes)
635
+ *
606
636
* Example:
607
637
*
608
638
* remote = Rugged::Remote.lookup(@repo, 'origin')
@@ -627,10 +657,12 @@ static VALUE rb_git_remote_push(int argc, VALUE *argv, VALUE self)
627
657
Data_Get_Struct (self , git_remote , remote );
628
658
629
659
rugged_remote_init_callbacks_and_payload_from_options (rb_options , & opts .callbacks , & payload );
660
+ init_custom_headers (rb_options , & opts .custom_headers );
630
661
631
662
error = git_remote_push (remote , & refspecs , & opts );
632
663
633
664
xfree (refspecs .strings );
665
+ git_strarray_free (& opts .custom_headers );
634
666
635
667
if (payload .exception )
636
668
rb_jump_tag (payload .exception );
0 commit comments