Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How does the library resolve the the git executable when not given in env vars? #165

Closed
ysabri opened this issue Feb 19, 2018 · 1 comment

Comments

@ysabri
Copy link
Contributor

ysabri commented Feb 19, 2018

So I have been wondering how does dugite resolve the the git executable path.

From what I have seen in the code; if given, it uses either the GIT_EXEC_PATH or the LOCAL_GIT_DIRECTORY, which after reading the documentation I am not sure what is the difference between them?

My problem is when the library is not given any of the above vars, how does it resolve the git executable path?

I am wondering this, because when I included the library in my app and ran git config --list both my email and name were configured already. How does this happen if dugite is using its own installation of git? What happens if there is no local install of git because as far as I know git won't commit without a name and email setup. Thanks!

@shiftkey
Copy link
Member

@ysabri when you install the dugite package, it'll fetch the embedded Git distribution for your platform and extract it on disk alongside the other package contents.

You should have a layout similar to this:

~/src/desktop/app/node_modules/dugite/
$ tree -L 3
.
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── build
│   └── lib
│       ├── errors.d.ts
│       ├── errors.js
│       ├── errors.js.map
│       ├── git-environment.d.ts
│       ├── git-environment.js
│       ├── git-environment.js.map
│       ├── git-process.d.ts
│       ├── git-process.js
│       ├── git-process.js.map
│       ├── index.d.ts
│       ├── index.js
│       └── index.js.map
├── git
│   ├── bin
│   │   └── git
│   ├── libexec
│   │   └── git-core
│   └── share
│       └── git-core
├── node_modules
├── package.json
└── script
    ├── config.js
    └── download-git.js

10 directories, 20 files

To resolve the Git distribution directory, this function is used if LOCAL_GIT_DIRECTORY is not set:

function resolveEmbeddedGitDir(): string {
const s = path.sep
return path
.resolve(__dirname, '..', '..', 'git')
.replace(/[\\\/]app.asar[\\\/]/, `${s}app.asar.unpacked${s}`)
}

This is basically looking for the git directory at the root of the package.

When GIT_EXEC_PATH is also not set, it's at a known location based on the current platform. That's this code:

const gitDir = resolveGitDir()
if (
process.platform === 'darwin' ||
process.platform === 'linux' ||
process.platform === 'android'
) {
return path.join(gitDir, 'libexec', 'git-core')
} else if (process.platform === 'win32') {
return path.join(gitDir, 'mingw64', 'libexec', 'git-core')
}

Let me know if you have any other questions about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants