@@ -22,15 +22,32 @@ export const cloneRepository = async (
22
22
progress : onProgress ,
23
23
} ) . cwd ( {
24
24
path,
25
- } )
26
-
27
- await git . clone (
28
- cloneUrl ,
29
- path ,
30
- [
31
- "--bare" ,
32
- ]
33
- ) ;
25
+ } ) ;
26
+
27
+ const isAzureDevOps = remoteUrl . hostname . includes ( 'devops' ) ;
28
+
29
+ if ( isAzureDevOps && remoteUrl . password ) {
30
+ const token = remoteUrl . password ;
31
+ const authHeader = `Authorization: Basic ${ Buffer . from ( `:${ token } ` ) . toString ( 'base64' ) } ` ;
32
+
33
+ await git . clone (
34
+ remoteUrl . origin + remoteUrl . pathname ,
35
+ path ,
36
+ [
37
+ "--bare" ,
38
+ "-c" ,
39
+ `http.extraHeader=${ authHeader } `
40
+ ]
41
+ ) ;
42
+ } else {
43
+ await git . clone (
44
+ remoteUrl . toString ( ) ,
45
+ path ,
46
+ [
47
+ "--bare" ,
48
+ ]
49
+ ) ;
50
+ }
34
51
35
52
await unsetGitConfig ( path , [ "remote.origin.url" ] ) ;
36
53
} catch ( error : unknown ) {
@@ -63,14 +80,31 @@ export const fetchRepository = async (
63
80
progress : onProgress ,
64
81
} ) . cwd ( {
65
82
path : path ,
66
- } )
67
-
68
- await git . fetch ( [
69
- cloneUrl ,
70
- "+refs/heads/*:refs/heads/*" ,
71
- "--prune" ,
72
- "--progress"
73
- ] ) ;
83
+ } ) ;
84
+
85
+ const isAzureDevOps = remoteUrl . hostname . includes ( 'devops' ) ;
86
+
87
+ if ( isAzureDevOps && remoteUrl . password ) {
88
+ const token = remoteUrl . password ;
89
+ const authHeader = `Authorization: Basic ${ Buffer . from ( `:${ token } ` ) . toString ( 'base64' ) } ` ;
90
+
91
+ // Temporarily set git configuration
92
+ await git . addConfig ( 'http.extraHeader' , authHeader ) ;
93
+
94
+ await git . fetch ( [
95
+ remoteUrl . origin + remoteUrl . pathname ,
96
+ "+refs/heads/*:refs/heads/*" ,
97
+ "--prune" ,
98
+ "--progress"
99
+ ] ) ;
100
+ } else {
101
+ await git . fetch ( [
102
+ remoteUrl . toString ( ) ,
103
+ "+refs/heads/*:refs/heads/*" ,
104
+ "--prune" ,
105
+ "--progress"
106
+ ] ) ;
107
+ }
74
108
} catch ( error : unknown ) {
75
109
const baseLog = `Failed to fetch repository: ${ path } ` ;
76
110
if ( env . SOURCEBOT_LOG_LEVEL !== "debug" ) {
0 commit comments