+77
-3
lines changedFilter options
+77
-3
lines changed Original file line number Diff line number Diff line change
@@ -37,6 +37,10 @@ int credential_match(const struct credential *want,
37
37
#undef CHECK
38
38
}
39
39
40
+
41
+
static int credential_from_potentially_partial_url(struct credential *c,
42
+
const char *url);
43
+
40
44
static int credential_config_callback(const char *var, const char *value,
41
45
void *data)
42
46
{
@@ -82,6 +86,22 @@ static int select_all(const struct urlmatch_item *a,
82
86
return 0;
83
87
}
84
88
89
+
static int match_partial_url(const char *url, void *cb)
90
+
{
91
+
struct credential *c = cb;
92
+
struct credential want = CREDENTIAL_INIT;
93
+
int matches = 0;
94
+
95
+
if (credential_from_potentially_partial_url(&want, url) < 0)
96
+
warning(_("skipping credential lookup for key: credential.%s"),
97
+
url);
98
+
else
99
+
matches = credential_match(&want, c);
100
+
credential_clear(&want);
101
+
102
+
return matches;
103
+
}
104
+
85
105
static void credential_apply_config(struct credential *c)
86
106
{
87
107
char *normalized_url;
@@ -101,6 +121,7 @@ static void credential_apply_config(struct credential *c)
101
121
config.collect_fn = credential_config_callback;
102
122
config.cascade_fn = NULL;
103
123
config.select_fn = select_all;
124
+
config.fallback_match_fn = match_partial_url;
104
125
config.cb = c;
105
126
106
127
credential_format(c, &url);
@@ -468,6 +489,12 @@ static int credential_from_url_1(struct credential *c, const char *url,
468
489
return 0;
469
490
}
470
491
492
+
static int credential_from_potentially_partial_url(struct credential *c,
493
+
const char *url)
494
+
{
495
+
return credential_from_url_1(c, url, 1, 0);
496
+
}
497
+
471
498
int credential_from_url_gently(struct credential *c, const char *url, int quiet)
472
499
{
473
500
return credential_from_url_1(c, url, 0, quiet);
Original file line number Diff line number Diff line change
@@ -575,4 +575,42 @@ test_expect_success 'credential system refuses to work with missing protocol' '
575
575
test_i18ncmp expect stderr
576
576
'
577
577
578
+
test_expect_success 'credential config with partial URLs' '
579
+
echo "echo password=yep" | write_script git-credential-yep &&
580
+
test_write_lines url=https://user@example.com/repo.git >stdin &&
581
+
for partial in \
582
+
example.com \
583
+
user@example.com \
584
+
https:// \
585
+
https://example.com \
586
+
https://example.com/ \
587
+
https://user@example.com \
588
+
https://user@example.com/ \
589
+
https://example.com/repo.git \
590
+
https://user@example.com/repo.git \
591
+
/repo.git
592
+
do
593
+
git -c credential.$partial.helper=yep \
594
+
credential fill <stdin >stdout &&
595
+
grep yep stdout ||
596
+
return 1
597
+
done &&
598
+
599
+
for partial in \
600
+
dont.use.this \
601
+
http:// \
602
+
/repo
603
+
do
604
+
git -c credential.$partial.helper=yep \
605
+
credential fill <stdin >stdout &&
606
+
! grep yep stdout ||
607
+
return 1
608
+
done &&
609
+
610
+
git -c credential.$partial.helper=yep \
611
+
-c credential.with%0anewline.username=uh-oh \
612
+
credential fill <stdin >stdout 2>stderr &&
613
+
test_i18ngrep "skipping credential lookup for key" stderr
614
+
'
615
+
578
616
test_done
Original file line number Diff line number Diff line change
@@ -572,10 +572,14 @@ int urlmatch_config_entry(const char *var, const char *value, void *cb)
572
572
573
573
config_url = xmemdupz(key, dot - key);
574
574
norm_url = url_normalize_1(config_url, &norm_info, 1);
575
+
if (norm_url)
576
+
retval = match_urls(url, &norm_info, &matched);
577
+
else if (collect->fallback_match_fn)
578
+
retval = collect->fallback_match_fn(config_url,
579
+
collect->cb);
580
+
else
581
+
retval = 0;
575
582
free(config_url);
576
-
if (!norm_url)
577
-
return 0;
578
-
retval = match_urls(url, &norm_info, &matched);
579
583
free(norm_url);
580
584
if (!retval)
581
585
return 0;
Original file line number Diff line number Diff line change
@@ -59,6 +59,11 @@ struct urlmatch_config {
59
59
* specificity rules) than existing.
60
60
*/
61
61
int (*select_fn)(const struct urlmatch_item *found, const struct urlmatch_item *existing);
62
+
/*
63
+
* An optional callback to allow e.g. for partial URLs; it shall
64
+
* return 1 or 0 depending whether `url` matches or not.
65
+
*/
66
+
int (*fallback_match_fn)(const char *url, void *cb);
62
67
};
63
68
64
69
int urlmatch_config_entry(const char *var, const char *value, void *cb);
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4