mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 20:29:08 -04:00
feat(repository): add ability to set working directory
This commit is contained in:
parent
b603a567b2
commit
ef29257f2e
3 changed files with 25 additions and 1 deletions
|
@ -349,7 +349,7 @@ void setHeadDetachedFromAnnotated(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the path to the working directory for this repository
|
/// Set the path to the working directory for this repository.
|
||||||
///
|
///
|
||||||
/// The working directory doesn't need to be the same one that contains the
|
/// The working directory doesn't need to be the same one that contains the
|
||||||
/// `.git` folder for this repository.
|
/// `.git` folder for this repository.
|
||||||
|
|
|
@ -167,6 +167,20 @@ class Repository {
|
||||||
/// If the repository is bare, this function will always return empty string.
|
/// If the repository is bare, this function will always return empty string.
|
||||||
String get workdir => bindings.workdir(_repoPointer);
|
String get workdir => bindings.workdir(_repoPointer);
|
||||||
|
|
||||||
|
/// Sets the path to the working directory for this repository.
|
||||||
|
///
|
||||||
|
/// The working directory doesn't need to be the same one that contains the
|
||||||
|
/// `.git` folder for this repository.
|
||||||
|
///
|
||||||
|
/// If this repository is bare, setting its working directory will turn it into a
|
||||||
|
/// normal repository, capable of performing all the common workdir operations
|
||||||
|
/// (checkout, status, index manipulation, etc).
|
||||||
|
///
|
||||||
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
|
void setWorkdir(String path, [bool updateGitlink = false]) {
|
||||||
|
bindings.setWorkdir(_repoPointer, path, updateGitlink);
|
||||||
|
}
|
||||||
|
|
||||||
/// Releases memory allocated for repository object.
|
/// Releases memory allocated for repository object.
|
||||||
void free() {
|
void free() {
|
||||||
bindings.free(_repoPointer);
|
bindings.free(_repoPointer);
|
||||||
|
|
|
@ -154,6 +154,16 @@ void main() {
|
||||||
expect(repo.namespace, '');
|
expect(repo.namespace, '');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('successfully sets working directory', () {
|
||||||
|
final tmpWorkDir = '${Directory.systemTemp.path}/tmp_work_dir/';
|
||||||
|
Directory(tmpWorkDir).createSync();
|
||||||
|
|
||||||
|
repo.setWorkdir(tmpWorkDir);
|
||||||
|
expect(repo.workdir, tmpWorkDir);
|
||||||
|
|
||||||
|
Directory(tmpWorkDir).deleteSync();
|
||||||
|
});
|
||||||
|
|
||||||
group('setHead', () {
|
group('setHead', () {
|
||||||
test('successfully sets head when target is reference', () {
|
test('successfully sets head when target is reference', () {
|
||||||
expect(repo.head.name, 'refs/heads/master');
|
expect(repo.head.name, 'refs/heads/master');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue