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

git-worktree functionality for managing multiple working trees #339

Merged
merged 37 commits into from
Feb 27, 2021

Conversation

nelsonni
Copy link
Member

@nelsonni nelsonni commented Feb 18, 2021

Description:

Cards linked to files on git branches that do not match the current repository branch have previously required creating temporary shadow clones of the repository in order to switch branches and copy the necessary files. This process is costly and also leaves no recourse for any subsequent changes to be saved and tracked via version control.

git-worktree provides the ability to manage multiple working trees:

A git repository can support multiple working trees, allowing you to check out more than one branch at a time. With git worktree add a new working tree is associated with the repository. This new working tree is called a "linked working tree" as opposed to the "main working tree" prepared by git-init[1] or git-clone[1]. A repository has one main working tree (if it’s not a bare repository) and zero or more linked working trees. When you are done with a linked working tree, remove it with git worktree remove.

In its simplest form, git worktree add automatically creates a new branch whose name is the final component of , which is convenient if you plan to work on a new topic. For instance, git worktree add ../hotfix creates new branch hotfix and checks it out at path ../hotfix. To instead work on an existing branch in a new working tree, use git worktree add . On the other hand, if you just plan to make some experimental changes or do testing without disturbing existing development, it is often convenient to create a throwaway working tree not associated with any branch. For instance, git worktree add -d creates a new working tree with a detached HEAD at the same commit as the current branch.

Implementing git-worktree within isomoprhic-git would be ideal, but until then we can wrap the functionality of git-worktree around the necessary functions exposed by isomorphic-git. The following functions must be implemented:

This PR resolves #69, and signifies the following version changes:

  • MAJOR version increase
  • MINOR version increase
  • PATCH version increase

Changes:

This PR makes the following changes:

  • git-worktree.add function creates a new linked worktree directory outside of the main worktree directory and checks out the target commit-ish branch/commit.
  • git-worktree.list returns a formatted collection of Worktree objects containing a path to the linked worktree root directory, a branch name or symbolic ref pointed to by each worktree, a SHA-1 hash for the revision/commit that represents the current state of the worktree index, and indicators for bare repository and detached state statuses.
  • git-worktree.prune for removing entries from the $GIT_DIR/worktrees directory for any linked worktrees that have subsequently seen their worktree root directory deleted.
  • git-worktree.remove for cleanly removing a linked worktree (including entries in $GIT_DIR/worktrees); requires the use of the force parameter for unclean worktrees (untracked files or modifications in tracked files) or ones with submodules.

Checklist:

Before submitting this PR, I have verified that my code:

  • Resides on a fix/ or feat/ branch that was initially branched off from development.
  • Passes code linting (yarn lint) and unit testing (yarn test).
  • Successfully builds a distribution package (yarn package).

Additionally, I have verified that:

  • My name is listed in the Contributors section, or this PR includes a request to add my name.
  • I have read and am aware of the CONTRIBUTING guide for this project.

@nelsonni nelsonni added bug Bug reports or bug fixes feature Feature requests or improvements labels Feb 18, 2021
@nelsonni nelsonni added this to the v1.0.0 milestone Feb 18, 2021
@nelsonni
Copy link
Member Author

@jettseale This PR is currently a draft, but please try out the tests to see if anything breaks on your Windows system.

@nelsonni nelsonni requested a review from jettseale February 18, 2021 23:32
Copy link
Collaborator

@jettseale jettseale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I ran yarn test, one of the tests errored and five of them failed. Below are screenshots of the failing and erroring tests:
1
2
3
4
5
6

@nelsonni nelsonni force-pushed the feat/git-worktree branch 2 times, most recently from c550e6f to d43cc23 Compare February 22, 2021 22:56
@nelsonni nelsonni marked this pull request as ready for review February 25, 2021 21:46
@nelsonni nelsonni requested a review from jettseale February 25, 2021 21:47
Copy link
Collaborator

@jettseale jettseale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I ran yarn test, I got two failing tests in the git-worktree.add suite:
1
Looks like a simple Windows pathing issue.

Copy link
Collaborator

@jettseale jettseale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the fix caused new errors for those same two tests:

2

@nelsonni nelsonni requested a review from jettseale February 27, 2021 01:31
@nelsonni nelsonni merged commit 1d0392e into development Feb 27, 2021
@nelsonni nelsonni deleted the feat/git-worktree branch February 27, 2021 03:26
@nelsonni nelsonni linked an issue Mar 17, 2021 that may be closed by this pull request
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug reports or bug fixes feature Feature requests or improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

git-worktree implementation Submodule for src/containers/git.ts testing adds unnecessary complexity
2 participants