-
Notifications
You must be signed in to change notification settings - Fork 413
More Better Worktree Support #603
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
Merged
Merged
Changes from 17 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
dfd5fc9
Intial support for working with worktrees
mkeeler 8fca1ee
Ignore the deprecated git_transfer_progress type alias in systest
mkeeler 714beb6
First round of experimental multi-repo testing
mkeeler 9e89b47
Fix macro hygene error in `repo_test`
foriequal0 a4be5a9
Match worktree version const types with other version consts
foriequal0 fbd13a1
Match worktree naming conventions with other entities
foriequal0 c55c334
Move conversions to under its namespaces and match naming convention
foriequal0 8a79cdd
Match WorktreeAddOptions style with other options
foriequal0 daba2aa
Use ptr::null_mut() rather than 0
foriequal0 b8ab3a3
Take `Option<>` where API may take NULL as opts
foriequal0 8db7070
Create TempDirs to hold multiple `TempDir`s
foriequal0 6d31b71
Implement multi-repo testing
foriequal0 8e17a98
Use repo.workdir() to get working directory
foriequal0 b51bf5c
Remove unnecessary and dangerous conversion for Cstring into *mut c_char
foriequal0 7c820bc
Fix comments
foriequal0 42cd516
Remove println
foriequal0 a81f3ad
Make Worktree::is_prunable return Result
foriequal0 fab731c
fixup! Remove init
foriequal0 966c34d
fixup! use try_call!
foriequal0 491efd4
fixup! use unwrap since it's expected to always be utf-8
foriequal0 7ba981c
fixup! Remove conversion aliases
foriequal0 3327e21
fixup! Store raw git_worktree_add_options in WorktreeAddOptions
foriequal0 79d4459
fixup! Store raw git_worktree_prune_options in WorktreePruneOptions
foriequal0 dd529ae
fixup! Remove repo_test! macros
foriequal0 f73d6a2
fixup! Make sure `Reference` outlive `WorktreeAddOptions`
foriequal0 858a446
fixup! Remove unnecessary `unsafe impl Send`
foriequal0 d0418f7
fixup! Don't skip git_transfer_progress
foriequal0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ use crate::stash::{stash_cb, StashApplyOptions, StashCbData}; | |
use crate::string_array::StringArray; | ||
use crate::tagforeach::{tag_foreach_cb, TagForeachCB, TagForeachData}; | ||
use crate::util::{self, path_to_repo_path, Binding}; | ||
use crate::worktree::{Worktree, WorktreeAddOptions}; | ||
use crate::CherrypickOptions; | ||
use crate::RevertOptions; | ||
use crate::{ | ||
|
@@ -162,6 +163,19 @@ impl Repository { | |
} | ||
} | ||
|
||
/// Attempt to open an already-existing repository from a worktree. | ||
pub fn open_from_worktree(worktree: &Worktree) -> Result<Repository, Error> { | ||
crate::init(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this can be skipped since the presence of |
||
let mut ret = ptr::null_mut(); | ||
unsafe { | ||
try_call!(raw::git_repository_open_from_worktree( | ||
&mut ret, | ||
worktree.raw() | ||
)); | ||
Ok(Binding::from_raw(ret)) | ||
} | ||
} | ||
|
||
/// Attempt to open an already-existing repository at or above `path` | ||
/// | ||
/// This starts at `path` and looks up the filesystem hierarchy | ||
|
@@ -2791,6 +2805,63 @@ impl Repository { | |
Ok(Binding::from_raw(ret)) | ||
} | ||
} | ||
|
||
/// Lists all the worktrees for the repository | ||
pub fn worktrees(&self) -> Result<StringArray, Error> { | ||
let mut arr = raw::git_strarray { | ||
strings: ptr::null_mut(), | ||
count: 0, | ||
}; | ||
unsafe { | ||
try_call!(raw::git_worktree_list(&mut arr, self.raw)); | ||
Ok(Binding::from_raw(arr)) | ||
} | ||
} | ||
|
||
/// Opens a worktree by name for the given repository | ||
/// | ||
/// This can open any worktree that the worktrees method returns. | ||
pub fn find_worktree(&self, name: &str) -> Result<Worktree, Error> { | ||
let mut raw = ptr::null_mut(); | ||
let raw_name = CString::new(name)?; | ||
unsafe { | ||
try_call!(raw::git_worktree_lookup(&mut raw, self.raw, raw_name)); | ||
Ok(Binding::from_raw(raw)) | ||
} | ||
} | ||
|
||
/// Open a worktree of a the repository | ||
/// | ||
/// If a repository is not the main tree but a worktree, this | ||
/// function will look up the worktree inside the parent | ||
/// repository and create a new `git_worktree` structure. | ||
pub fn to_worktree(&self) -> Result<Worktree, Error> { | ||
Worktree::open_from_repository(self) | ||
} | ||
|
||
/// Creates a new worktree for the repository | ||
pub fn worktree( | ||
&self, | ||
name: &str, | ||
path: &Path, | ||
opts: Option<&WorktreeAddOptions<'_>>, | ||
) -> Result<Worktree, Error> { | ||
let mut raw = ptr::null_mut(); | ||
let raw_name = CString::new(name)?; | ||
let raw_path = path.into_c_string()?; | ||
|
||
unsafe { | ||
let opts = opts.map(|o| o.raw()); | ||
try_call!(raw::git_worktree_add( | ||
&mut raw, | ||
self.raw, | ||
raw_name, | ||
raw_path, | ||
opts.as_ref() | ||
)); | ||
Ok(Binding::from_raw(raw)) | ||
} | ||
} | ||
} | ||
|
||
impl Binding for Repository { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we probably don't need to update old tests like this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll revert old tests
, but keep worktree tests. I'll moveand worktree tests. Let smoke tests be simple smoke tests.repo_test
macro toworktree.rs