<script lang="ts">
import { onMount } from 'svelte';
import ArrowDownIcon from 'phosphor-svelte/lib/ArrowDownIcon';
import ArrowRightIcon from 'phosphor-svelte/lib/ArrowRightIcon';
import CheckIcon from 'phosphor-svelte/lib/CheckIcon';
import CircleDashedIcon from 'phosphor-svelte/lib/CircleDashedIcon';
import CopyIcon from 'phosphor-svelte/lib/CopyIcon';
import DownloadSimpleIcon from 'phosphor-svelte/lib/DownloadSimpleIcon';
import Footer from '#lib/components/site/Footer.svelte';
import HostLogo from '#lib/components/site/migrate/HostLogo.svelte';
import MigrateHeroLedger from '#lib/components/site/migrate/MigrateHeroLedger.svelte';
import Navbar from '#lib/components/site/Navbar.svelte';
import * as Accordion from '#lib/components/ui/accordion/index.js';
import { Button } from '#lib/components/ui/button/index.js';
import { ownerProblem, parseSource, remoteUpdate, script, type Source } from '#lib/migrate.js';
import { sources as hostsFrom, type MoveSource } from '#lib/migrate-sources.js';
import { sizeAnswer } from '#lib/limits.js';
import { githubStartUrl } from '#lib/live/github.js';
import { ApiFailure, request } from '#lib/live/http.js';
import { loadMe } from '#lib/live/identity.svelte.js';
// Signed out authorizes GitHub (which signs in or creates the account) and returns here; signed in goes to the first organization's move page, or to create one.
let moveHref = $state<string | null>(null);
onMount(async () => {
try {
if (!(await loadMe())) return;
const [first] = await request<{ handle: string }[]>('GET', '/api/me/orgs');
moveHref = first ? `/${first.handle}/migration/new` : '/settings/organizations';
} catch (err) {
if (!(err instanceof ApiFailure)) throw err;
}
});
const startHref = $derived(moveHref ?? githubStartUrl('/migrate'));
let urls = $state('');
let owner = $state('');
let protocol = $state<'ssh' | 'https'>('ssh');
let copied = $state<string | null>(null);
let picked = $state<MoveSource['id']>('github');
const host = $derived(hostsFrom.find((h) => h.id === picked) ?? hostsFrom[0]);
const lines = $derived(urls.split('\n').filter((l) => l.trim() !== ''));
const parsed = $derived(lines.map(parseSource));
const sources = $derived(parsed.flatMap((p) => (p.source ? [p.source] : [])));
const duplicates = $derived(sources.map((s) => s.name).filter((n, i, all) => all.indexOf(n) !== i));
const ownerIssue = $derived(owner.trim() === '' && sources.length === 0 ? null : ownerProblem(owner.trim()));
const ready = $derived(sources.length > 0 && !ownerIssue && duplicates.length === 0);
const output = $derived(ready ? script(sources, owner.trim(), protocol) : '');
const hosts = $derived([...new Set(sources.map((s) => s.host))]);
const download = $derived(ready ? `data:text/x-shellscript;charset=utf-8,${encodeURIComponent(output)}` : null);
const copy = async (text: string, key: string) => {
await navigator.clipboard.writeText(text);
copied = key;
setTimeout(() => (copied = null), 1500);
};
const contact = (message: string) => `/contact?message=${encodeURIComponent(message)}`;
const talk = $derived(
contact(
sources.length > 0
? `We want to move ${sources.length} ${sources.length === 1 ? 'repository' : 'repositories'} from ${hosts.join(' and ')} to Sailfork. `
: 'We want to move our organization to Sailfork. '
)
);
const clones = $derived(sources.map((s: Source) => `# in ${s.name}\n${remoteUpdate(owner.trim(), protocol, s.name)}`).join('\n'));
const tryExample = (example: string) => {
if (!lines.includes(example)) urls = [...lines, example].join('\n');
};
const how = [
{ title: 'Authorize GitHub', body: 'Approve access for your account and the organizations you want to bring. New to Sailfork? This creates your account too.' },
{ title: 'Pick what moves', body: 'Every repository you can see on GitHub is listed by owner. Pick a few, or a whole organization at once.' },
{ title: 'We move it', body: 'We copy everything over and email you as each repository is ready on Sailfork. Nothing changes on GitHub.' }
];
const after: { from: string; to: string; command?: string }[] = [
{ from: 'Your clones', to: 'Point each one at Sailfork with one command:', command: 'git remote set-url origin git@sailfork.com:owner/repository.git' },
{ from: 'Signing in', to: 'Your team signs in with GitHub, so there are no new passwords to hand out.' },
{ from: 'SSH keys', to: 'Add an ed25519 or ECDSA key. RSA and DSA keys are refused, so if yours is older, make a new one:', command: 'ssh-keygen -t ed25519' },
{ from: 'Branch protection', to: 'Branch rules require a pull request and a number of approvals before anything lands on a protected branch.' }
];
const faq = [
{ q: 'Does anything change on GitHub?', a: 'No. Sailfork only reads from GitHub. Your repositories, issues and settings stay where they are until you delete them yourself.' },
{ q: 'Can my team keep working during the move?', a: 'Yes. Keep pushing where you are while repositories copy, then pick a day to switch so nobody pushes to the old remote after it.' },
{ q: 'Do commit hashes change?', a: 'No. History is copied as it is, so hashes, signatures and links to commits keep working.' },
{ q: 'Can I move from more than one host at once?', a: 'Yes. Paste repositories from GitHub, GitLab, Bitbucket and your own server into the same script, and they land under one owner on Sailfork.' },
{ q: 'How big can a repository be?', a: `${sizeAnswer} Push larger histories in parts, or tell us and we move them with you.` },
{ q: 'What about refs like refs/pull?', a: 'Only branches and tags move. Host-only refs, such as GitHub’s refs/pull, stay behind, because they belong to that host’s pull requests rather than your history.' }
];
const field = 'type-ui w-full rounded-md border border-input bg-background px-2.5 transition-[box-shadow,border-color] outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50';
const segment = (on: boolean) => [
'type-small flex h-8 cursor-pointer items-center rounded px-3 whitespace-nowrap transition-colors has-focus-visible:ring-3 has-focus-visible:ring-ring/50',
on ? 'bg-primary text-primary-foreground' : 'text-muted-foreground hover:bg-muted hover:text-foreground'
];
</script>
<svelte:head>
<title>Move to Sailfork from GitHub, GitLab or Bitbucket</title>
<meta name="description" content="Authorize GitHub and Sailfork moves your repositories, issues and pull requests for you. From GitLab, Bitbucket, Azure DevOps or your own server, one script moves every branch and tag and checks nothing was left behind." />
</svelte:head>
<Navbar />
<main>
<MigrateHeroLedger primary={moveHref ?? '/sign-up'} secondary="#sources" />
<section id="sources" aria-labelledby="sources-title" class="scroll-mt-8 border-t border-border py-20">
<div class="mx-auto grid max-w-7xl gap-10 px-4 sm:px-6 lg:grid-cols-12 lg:px-8">
<div class="lg:col-span-4">
<h2 id="sources-title" class="type-title">Where you are coming from</h2>
<p class="type-body mt-3 max-w-[36ch] text-muted-foreground">Code moves from anywhere git runs. How much else comes with it depends on the host.</p>
</div>
<div class="grid min-w-0 grid-cols-[minmax(0,1fr)] gap-8 lg:col-span-8">
<fieldset>
<legend class="sr-only">Host you are moving from</legend>
<div class="flex max-w-full flex-wrap gap-1 rounded-md border border-input bg-background p-0.5 sm:inline-flex">
{#each hostsFrom as h (h.id)}
<label class={segment(picked === h.id)}>
<input type="radio" class="sr-only" name="host" value={h.id} bind:group={picked} /><HostLogo host={h.id} class="mr-2 size-3.5" />{h.name}
</label>
{/each}
</div>
</fieldset>
<div class="grid gap-6" aria-live="polite">
<div class="grid grid-cols-[2.5rem_minmax(0,1fr)] gap-x-4">
<HostLogo host={host.id} class="mt-1 size-8 text-foreground" />
<div>
<p class="type-heading">{host.mode}</p>
<p class="type-body mt-1 max-w-[56ch] text-muted-foreground">{host.summary}</p>
</div>
</div>
<dl class="grid gap-x-10 sm:grid-cols-2">
{#each host.carried as item (item.title)}
<div class="border-t border-border py-5">
<dt class="type-heading flex items-center gap-2">
{#if item.auto}
<CheckIcon class="size-3.5 shrink-0 text-primary" aria-hidden="true" />
{:else}
<CircleDashedIcon class="size-3.5 shrink-0 text-muted-foreground" aria-hidden="true" />
{/if}
{item.title}
</dt>
<dd class="type-body mt-1 max-w-[42ch] text-muted-foreground">{item.body}</dd>
</div>
{/each}
</dl>
<div class="flex flex-wrap gap-3">
{#if host.id === 'github'}
<Button href={startHref}>Authorize GitHub<ArrowRightIcon aria-hidden="true" /></Button>
<Button href="#how" variant="outline"><ArrowDownIcon aria-hidden="true" />See how it works</Button>
{:else}
<Button href="#script" onclick={() => tryExample(host.example)}><ArrowDownIcon aria-hidden="true" />Write the script for {host.id === 'server' ? 'your server' : host.name}</Button>
{#if host.id !== 'server'}
<Button href={contact(`We want to move from ${host.name} to Sailfork, including more than the code. `)} variant="outline">Plan it with us<ArrowRightIcon aria-hidden="true" /></Button>
{/if}
{/if}
</div>
</div>
</div>
</div>
</section>
<section id="how" aria-labelledby="how-title" class="scroll-mt-8 border-t border-border py-20">
<div class="mx-auto grid max-w-7xl gap-10 px-4 sm:px-6 lg:grid-cols-12 lg:px-8">
<div class="lg:col-span-4">
<h2 id="how-title" class="type-title">Moving from GitHub</h2>
<p class="type-body mt-3 max-w-[36ch] text-muted-foreground">Three steps, and only the first two are yours.</p>
</div>
<ol class="lg:col-span-8">
{#each how as step, i (step.title)}
<li class="grid grid-cols-[2.5rem_minmax(0,1fr)] gap-x-4 border-t border-border py-5">
<span class="type-heading text-muted-foreground tabular-nums">{i + 1}</span>
<div>
<p class="type-heading">{step.title}</p>
<p class="type-body mt-1 max-w-[56ch] text-muted-foreground">{step.body}</p>
</div>
</li>
{/each}
</ol>
</div>
</section>
<section aria-labelledby="after-title" class="border-t border-border py-20">
<div class="mx-auto grid max-w-7xl gap-10 px-4 sm:px-6 lg:grid-cols-12 lg:px-8">
<div class="lg:col-span-4">
<h2 id="after-title" class="type-title">Your team, after the move</h2>
<p class="type-body mt-3 max-w-[36ch] text-muted-foreground">A few minutes each, mostly on day one.</p>
</div>
<dl class="lg:col-span-8">
{#each after as row (row.from)}
<div class="grid gap-x-10 gap-y-1 border-t border-border py-4 sm:grid-cols-[12rem_minmax(0,1fr)]">
<dt class="type-ui text-muted-foreground">{row.from}</dt>
<dd class="type-body min-w-0 break-words">
{row.to}
{#if row.command}
<span class="mt-2 flex items-center gap-2">
<code class="type-code min-w-0 flex-1 overflow-x-auto bg-muted/50 px-2 py-1 whitespace-pre">{row.command}</code>
<Button variant="ghost" size="icon-sm" onclick={() => copy(row.command ?? '', row.from)} aria-label="Copy {row.command}">
{#if copied === row.from}<CheckIcon aria-hidden="true" />{:else}<CopyIcon aria-hidden="true" />{/if}
</Button>
</span>
{/if}
</dd>
</div>
{/each}
</dl>
</div>
</section>
<section id="script" aria-labelledby="move-title" class="scroll-mt-8 border-t border-border py-20">
<div class="mx-auto grid max-w-7xl gap-10 px-4 sm:px-6 lg:grid-cols-12 lg:px-8">
<div class="lg:col-span-4">
<h2 id="move-title" class="type-title">Move it yourself</h2>
<p class="type-body mt-3 max-w-[36ch] text-muted-foreground">
From GitLab, Bitbucket, Azure DevOps or your own server, paste the repositories and run the script we write for you. It copies every branch and tag and checks nothing was left behind. Create the empty repositories on Sailfork first.
</p>
</div>
<div class="grid min-w-0 grid-cols-[minmax(0,1fr)] gap-6 lg:col-span-8">
<div class="grid gap-2">
<label for="sources" class="type-ui">Repositories to move</label>
<textarea
id="sources"
bind:value={urls}
rows="4"
spellcheck="false"
autocomplete="off"
placeholder={'https://github.com/acme-pay/api\ngit@gitlab.com:acme-pay/platform/billing.git\nhttps://dev.azure.com/acme-pay/payments/_git/ledger'}
aria-describedby="sources-help"
class="{field} py-2 font-mono"
></textarea>
<p id="sources-help" class="type-small text-muted-foreground" aria-live="polite">
{#if lines.length === 0}
One per line, the way you would pass it to git clone.
{:else}
{sources.length} of {lines.length} {lines.length === 1 ? 'line is' : 'lines are'} ready{hosts.length ? `, from ${hosts.join(' and ')}` : ''}.
{/if}
</p>
{#if parsed.some((p) => p.problem) || duplicates.length > 0}
<ul class="type-small grid gap-1 text-destructive">
{#each parsed.filter((p) => p.problem) as p, i (i)}
<li><span class="font-mono">{p.line}</span>: {p.problem}</li>
{/each}
{#each [...new Set(duplicates)] as name (name)}
<li>Two lines would both become <span class="font-mono">{name}</span>. Rename one on Sailfork and move it on its own.</li>
{/each}
</ul>
{/if}
</div>
<div class="grid gap-4 sm:grid-cols-[minmax(0,1fr)_auto] sm:items-end">
<div class="grid gap-2">
<label for="owner" class="type-ui">Owner on Sailfork</label>
<div class="flex h-9 items-center rounded-md border border-input bg-background transition-[box-shadow,border-color] focus-within:border-ring focus-within:ring-3 focus-within:ring-ring/50">
<span class="type-small shrink-0 border-r border-input px-2.5 text-muted-foreground">sailfork.com/</span>
<input
id="owner"
bind:value={owner}
spellcheck="false"
autocomplete="off"
placeholder="your-handle or your-org"
aria-invalid={ownerIssue ? 'true' : undefined}
aria-describedby={ownerIssue ? 'owner-problem' : undefined}
class="type-ui h-full min-w-0 flex-1 bg-transparent px-2.5 font-mono outline-none placeholder:font-sans placeholder:text-muted-foreground"
/>
</div>
</div>
<fieldset>
<legend class="sr-only">Push over</legend>
<div class="inline-flex rounded-md border border-input bg-background p-0.5">
{#each [{ v: 'ssh', l: 'SSH' }, { v: 'https', l: 'HTTPS' }] as const as o (o.v)}
<label class={segment(protocol === o.v)}>
<input type="radio" class="sr-only" name="protocol" value={o.v} bind:group={protocol} />{o.l}
</label>
{/each}
</div>
</fieldset>
</div>
{#if ownerIssue}<p id="owner-problem" class="type-small -mt-3 text-destructive">{ownerIssue}</p>{/if}
<div class="min-w-0">
<div class="flex items-center justify-between gap-4">
<p class="type-ui">The script</p>
{#if ready}
<div class="flex gap-1">
<Button variant="ghost" size="sm" onclick={() => copy(output, 'script')}>
{#if copied === 'script'}<CheckIcon aria-hidden="true" />Copied{:else}<CopyIcon aria-hidden="true" />Copy{/if}
</Button>
<Button variant="ghost" size="sm" href={download} download="move-to-sailfork.sh"><DownloadSimpleIcon aria-hidden="true" />Download</Button>
</div>
{/if}
</div>
{#if ready}
<pre class="type-code mt-2 max-h-96 overflow-auto border-y border-border bg-muted/50 px-5 py-4">{output}</pre>
<div class="mt-3 flex items-center justify-between gap-4">
<p class="type-small text-muted-foreground">Then, in every existing clone:</p>
<Button variant="ghost" size="sm" onclick={() => copy(clones, 'clones')}>
{#if copied === 'clones'}<CheckIcon aria-hidden="true" />Copied{:else}<CopyIcon aria-hidden="true" />Copy{/if}
</Button>
</div>
<pre class="type-code mt-2 overflow-x-auto border-y border-border bg-muted/50 px-5 py-3">{clones}</pre>
{:else}
<p class="type-small mt-2 border-y border-border py-6 text-muted-foreground">
{sources.length === 0 ? 'Paste at least one repository above.' : 'Add the owner on Sailfork to finish the script.'}
</p>
{/if}
</div>
</div>
</div>
</section>
<section id="faq" aria-labelledby="faq-title" class="scroll-mt-8 border-t border-border py-20">
<div class="mx-auto grid max-w-7xl gap-10 px-4 sm:px-6 lg:grid-cols-12 lg:px-8">
<div class="lg:col-span-4">
<h2 id="faq-title" class="type-title">Questions before a move</h2>
<p class="type-body mt-3 max-w-[36ch] text-muted-foreground">
Moving a large organization? <a href={talk} class="inline-flex items-center gap-1 text-primary underline underline-offset-4">
Plan it with us<ArrowRightIcon class="size-3.5" aria-hidden="true" />
</a>
</p>
</div>
<Accordion.Root type="single" class="border-b border-border lg:col-span-8">
{#each faq as item (item.q)}
<Accordion.Item value={item.q} class="border-t border-border">
<Accordion.Trigger class="type-heading gap-4 py-5">{item.q}</Accordion.Trigger>
<Accordion.Content class="pb-5">
<p class="type-body max-w-[62ch] text-muted-foreground animate-in fade-in-0 slide-in-from-top-1 duration-200 ease-snappy motion-reduce:animate-none">{item.a}</p>
</Accordion.Content>
</Accordion.Item>
{/each}
</Accordion.Root>
</div>
</section>
</main>
<Footer />