Skip to content

Commit 0372d00

Browse files
committed
Fix git-lfs not found in Flatpak build
Closes #180
1 parent 418e2f6 commit 0372d00

5 files changed

Lines changed: 47 additions & 5 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ Simply install GitHub Desktop Plus from [Flathub](https://flathub.org/en/apps/io
260260
flatpak install flathub io.github.pol_rivero.github-desktop-plus
261261
```
262262

263+
> **NOTE:** Git hooks will run inside the Flatpak sandbox and cannot access programs installed on your system (such as version managers,
264+
> linters, or other tools your hooks rely on). If your hooks depend on such programs, install a native package instead.
265+
263266
---
264267

265268
</details>

app/src/lib/hooks/hooks-proxy.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { spawn } from 'child_process'
22
import { basename, resolve, join } from 'path'
33
import { ProcessProxyConnection as Connection } from 'process-proxy'
44
import type { HookCallbackOptions } from '../git'
5-
import { resolveGitBinary } from 'dugite'
5+
import { resolveGitBinary, resolveGitExecPath } from 'dugite'
66
import { ShellEnvResult } from './get-shell-env'
77
import { shellFriendlyNames } from './config'
88
import { Writable } from 'stream'
@@ -145,7 +145,9 @@ export const createHooksProxy = (
145145
]
146146

147147
const terminalOutput: Buffer[] = []
148-
const gitPath = resolveGitBinary(resolve(__dirname, 'git'))
148+
const gitDir = resolve(__dirname, 'git')
149+
const gitPath = resolveGitBinary(gitDir)
150+
const gitExecPath = resolveGitExecPath(gitDir)
149151
const shellEnv = await getShellEnv(proxyCwd)
150152

151153
if (shellEnv.kind === 'failure') {
@@ -174,9 +176,20 @@ export const createHooksProxy = (
174176

175177
const child = spawn(gitPath, args, {
176178
cwd: proxyCwd,
177-
// GITHUB_DESKTOP lets hooks know they're run from GitHub Desktop.
178-
// See https://github.com/desktop/desktop/issues/19001
179-
env: { ...shellEnv.env, ...safeEnv, GITHUB_DESKTOP: '1' },
179+
env: {
180+
...shellEnv.env,
181+
...safeEnv,
182+
// The bundled Git can't resolve its own exec-path when spawned this
183+
// way (it reports "//libexec/git-core"), so set it explicitly. Native
184+
// Git prepends GIT_EXEC_PATH to the hook's PATH, which is what makes
185+
// the bundled git-lfs (and git) findable from inside the hook. This
186+
// matters most in sandboxed builds (e.g. Flatpak) where no system
187+
// git-lfs exists on PATH to fall back on.
188+
GIT_EXEC_PATH: gitExecPath,
189+
// GITHUB_DESKTOP lets hooks know they're run from GitHub Desktop.
190+
// See https://github.com/desktop/desktop/issues/19001
191+
GITHUB_DESKTOP: '1',
192+
},
180193
signal: abortController.signal,
181194
})
182195
.on('close', (code, signal) => resolve({ code, signal }))

app/src/ui/preferences/git.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,20 @@ export class Git extends React.Component<IGitProps> {
8383
private renderHooksSettings() {
8484
return (
8585
<>
86+
{__FLATPAK__ && (
87+
<div className="git-hooks-flatpak-warning">
88+
<span className="warning-icon">⚠️</span>
89+
You're running the Flatpak version. Git hooks run inside the Flatpak
90+
sandbox and cannot access programs installed on your system (such as
91+
version managers, linters, or other tools your hooks rely on). If
92+
your hooks depend on such programs, install a native package
93+
instead. See the{' '}
94+
<LinkButton uri="https://github.com/pol-rivero/github-desktop-plus#download-and-installation-">
95+
installation instructions
96+
</LinkButton>
97+
.
98+
</div>
99+
)}
86100
<Checkbox
87101
label="Load Git hook environment variables from shell"
88102
ariaDescribedBy="git-hooks-env-description"

app/styles/_ui.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
@import 'ui/_pull-request-quick-view';
106106
@import 'ui/discard-changes-retry';
107107
@import 'ui/_git-email-not-found-warning';
108+
@import 'ui/_git-hooks-flatpak-warning';
108109
@import 'ui/_branch-select';
109110
@import 'ui/_popover-dropdown';
110111
@import 'ui/_pull-request-files-changed';
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.git-hooks-flatpak-warning {
2+
.warning-icon {
3+
color: var(--warning-badge-icon-color);
4+
}
5+
6+
.link-button-component {
7+
display: inline;
8+
}
9+
10+
margin-bottom: var(--spacing-double);
11+
}

0 commit comments

Comments
 (0)