question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

lib/git return type audit

See original GitHub issue

Many of our functions in lib/git have the return type Promise<void>. This makes it difficult for callers to know if the function succeeded or failed (unless it throws an error).

This is particularly important for cases like https://github.com/desktop/desktop/blob/aa79543d8d373763dccc7a51a26e277db1d5960c/app/src/lib/stores/app-store.ts#L3134 where the merge may fail (for expected reasons) be we need to have that information as the caller.

Goal

Determine the appropriate return type for each of these functions.

Akin to https://github.com/desktop/desktop/issues/5923, it may be appropriate for some functions to return a sha or some other information on success, but at many of these functions should at least return true or a generic “success” type to indicate to the caller that nothing went wrong. (we should have at the very least exit codes from git() for all of these functions to judge that by.)

Functions to Audit

(these are all functions with the return type Promise<void> in lib/git)

  • createMergeCommit
  • setRemoteURL
  • applyPatchToIndex
  • renameBranch
  • checkoutBranch
  • checkoutPaths
  • clone
  • setGlobalConfigValue
  • writeGitDescription
  • fetchRefspec
  • fetch
  • saveGitIgnore
  • initGitRepository
  • installGlobalLFSFilters
  • abortMerge
  • pull
  • push
  • revertCommit
  • unstageAllFiles
  • resetSubmodulePaths
  • stageFiles
  • updateRef

Notes

Any PRs that change these return types should also include tests that verify those types are returned in the right situations so we don’t inadvertently cause regressions.

cc @shiftkey, as well as @say25 for additional thoughts since they’ve done prior work like this

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

2reactions
shiftkeycommented, Jan 10, 2019

@outofambit @say25 I have a few questions about this but am swamped with 1.6 stuff. Please hang on a bit before we dive into PRs.

0reactions
outofambitcommented, May 21, 2019

this might be worth revisiting (post 1.7.0) since we experienced some pain (and lost time debugging) over in #7474, due to returning Promise<void> into gitStore.performFailableGitOperation

i made a quick fix by returning true at the end of checkout which might be a decent first iteration here just to alleviate this potential gotcha.

Read more comments on GitHub >

github_iconTop Results From Across the Web

libgit2 API
libgit2. git_libgit2_features git_libgit2_init git_libgit2_opts git_libgit2_prerelease ... reset. git_reset git_reset_default git_reset_from_annotated ...
Read more >
git_diff_option_t - libgit2 API
May be combined with GIT_DIFF_IGNORE_CASE to specify that a file that has changed case will be returned as an add/delete pair. GIT_DIFF_DISABLE_PATHSPEC_MATCH.
Read more >
Oid functions - libgit2 API
The OID shortener is used to process a list of OIDs in text form and return the shortest length that would uniquely identify...
Read more >
101 Libgit2 Samples
Return codes from public APIs indicate general failure category. For extended information, libgit2 keeps some data in thread-local storage:.
Read more >
Authenticating against a server - libgit2
The credentials are returned using the same pattern which libgit2 uses for its API: the first parameter is an output parameter and the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found