mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-18 23:02:31 +03:00
link to cross-repo unified diff on github
This commit is contained in:
parent
46fe51eeda
commit
c3ac916c32
@ -109,8 +109,8 @@
|
|||||||
</SelectItem>
|
</SelectItem>
|
||||||
</Select>
|
</Select>
|
||||||
<p class="project-setup__description-text text-base-body-12">
|
<p class="project-setup__description-text text-base-body-12">
|
||||||
You have branches from multiple remotes. If you want to specify a push target for creating
|
You have branches from multiple remotes. If you want to specify a remote for creating
|
||||||
branches that is different from your production branch, change it here.
|
branches that is different from the remote that your target branch is on, change it here.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
@ -347,23 +347,32 @@ export class BaseBranch {
|
|||||||
return this.lastFetchedMs ? new Date(this.lastFetchedMs) : undefined;
|
return this.lastFetchedMs ? new Date(this.lastFetchedMs) : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get pushRepoBaseUrl(): string {
|
||||||
|
return this.cleanUrl(this.pushRemoteUrl);
|
||||||
|
}
|
||||||
|
|
||||||
get repoBaseUrl(): string {
|
get repoBaseUrl(): string {
|
||||||
if (this.pushRemoteUrl.startsWith('http')) {
|
return this.cleanUrl(this.remoteUrl);
|
||||||
return this.pushRemoteUrl.replace('.git', '');
|
}
|
||||||
|
|
||||||
|
// turn a git remote url into a web url (github, gitlab, bitbucket, etc)
|
||||||
|
private cleanUrl(url: string): string {
|
||||||
|
if (url.startsWith('http')) {
|
||||||
|
return url.replace('.git', '').trim();
|
||||||
} else {
|
} else {
|
||||||
return this.pushRemoteUrl.replace(':', '/').replace('git@', 'https://').replace('.git', '');
|
return url.replace(':', '/').replace('git@', 'https://').replace('.git', '').trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
commitUrl(commitId: string): string | undefined {
|
commitUrl(commitId: string): string | undefined {
|
||||||
// Different Git providers use different paths for the commit url:
|
// Different Git providers use different paths for the commit url:
|
||||||
if (this.isBitBucket) {
|
if (this.isBitBucket) {
|
||||||
return `${this.repoBaseUrl}/commits/${commitId}`;
|
return `${this.pushRepoBaseUrl}/commits/${commitId}`;
|
||||||
}
|
}
|
||||||
if (this.isGitlab) {
|
if (this.isGitlab) {
|
||||||
return `${this.repoBaseUrl}/-/commit/${commitId}`;
|
return `${this.pushRepoBaseUrl}/-/commit/${commitId}`;
|
||||||
}
|
}
|
||||||
return `${this.repoBaseUrl}/commit/${commitId}`;
|
return `${this.pushRepoBaseUrl}/commit/${commitId}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
get shortName() {
|
get shortName() {
|
||||||
@ -374,11 +383,37 @@ export class BaseBranch {
|
|||||||
if (!upstreamBranchName) return undefined;
|
if (!upstreamBranchName) return undefined;
|
||||||
const baseBranchName = this.branchName.split('/')[1];
|
const baseBranchName = this.branchName.split('/')[1];
|
||||||
const branchName = upstreamBranchName.split('/').slice(3).join('/');
|
const branchName = upstreamBranchName.split('/').slice(3).join('/');
|
||||||
|
|
||||||
|
if (this.pushRemoteName) {
|
||||||
|
if (this.isGitHub) {
|
||||||
|
// master...schacon:docs:Virtual-branch
|
||||||
|
const pushUsername = this.extractUsernameFromGitHubUrl(this.pushRemoteUrl);
|
||||||
|
const pushRepoName = this.extractRepoNameFromGitHubUrl(this.pushRemoteUrl);
|
||||||
|
return `${this.repoBaseUrl}/compare/${baseBranchName}...${pushUsername}:${pushRepoName}:${branchName}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (this.isBitBucket) {
|
if (this.isBitBucket) {
|
||||||
return `${this.repoBaseUrl.trim()}/branch/${branchName}?dest=${baseBranchName}`;
|
return `${this.repoBaseUrl}/branch/${branchName}?dest=${baseBranchName}`;
|
||||||
}
|
}
|
||||||
// The following branch path is good for at least Gitlab and Github:
|
// The following branch path is good for at least Gitlab and Github:
|
||||||
return `${this.repoBaseUrl.trim()}/compare/${baseBranchName}...${branchName}`;
|
return `${this.repoBaseUrl}/compare/${baseBranchName}...${branchName}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private extractUsernameFromGitHubUrl(url: string): string | null {
|
||||||
|
const regex = /github\.com[/:]([a-zA-Z0-9_-]+)\/.*/;
|
||||||
|
const match = url.match(regex);
|
||||||
|
return match ? match[1] : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private extractRepoNameFromGitHubUrl(url: string): string | null {
|
||||||
|
const regex = /github\.com[/:]([a-zA-Z0-9_-]+)\/([a-zA-Z0-9_-]+)/;
|
||||||
|
const match = url.match(regex);
|
||||||
|
return match ? match[2] : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private get isGitHub(): boolean {
|
||||||
|
return this.repoBaseUrl.includes('github.com');
|
||||||
}
|
}
|
||||||
|
|
||||||
private get isBitBucket(): boolean {
|
private get isBitBucket(): boolean {
|
||||||
|
Loading…
Reference in New Issue
Block a user