Skip to content

Commit 518fbbc

Browse files
committed
feat: add Repository::workdir() as replacement for Repository::work_dir().
Keep the latter as deprecated though.
1 parent 28080ae commit 518fbbc

File tree

33 files changed

+79
-73
lines changed

33 files changed

+79
-73
lines changed

gix/examples/clone.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ fn main() -> anyhow::Result<()> {
2727

2828
println!(
2929
"Checking out into {:?} ...",
30-
prepare_checkout.repo().work_dir().expect("should be there")
30+
prepare_checkout.repo().workdir().expect("should be there")
3131
);
3232

3333
let (repo, _) = prepare_checkout.main_worktree(gix::progress::Discard, &gix::interrupt::IS_INTERRUPTED)?;
34-
println!("Repo cloned into {:?}", repo.work_dir().expect("directory pre-created"));
34+
println!("Repo cloned into {:?}", repo.workdir().expect("directory pre-created"));
3535

3636
let remote = repo
3737
.find_default_remote(gix::remote::Direction::Fetch)

gix/examples/stats.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use gix::{prelude::ObjectIdExt, Reference};
44

55
fn main() -> Result<(), Box<dyn std::error::Error>> {
66
let mut repo = gix::discover(".")?;
7-
println!("Repo: {}", repo.work_dir().unwrap_or_else(|| repo.git_dir()).display());
7+
println!("Repo: {}", repo.workdir().unwrap_or_else(|| repo.git_dir()).display());
88
let mut max_parents = 0;
99
let mut avg_parents = 0;
1010
repo.object_cache_size(32 * 1024);

gix/src/clone/access.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl PrepareFetch {
6868
impl Drop for PrepareFetch {
6969
fn drop(&mut self) {
7070
if let Some(repo) = self.repo.take() {
71-
std::fs::remove_dir_all(repo.work_dir().unwrap_or_else(|| repo.path())).ok();
71+
std::fs::remove_dir_all(repo.workdir().unwrap_or_else(|| repo.path())).ok();
7272
}
7373
}
7474
}

gix/src/clone/checkout.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub mod main_worktree {
9292
.repo
9393
.as_ref()
9494
.expect("BUG: this method may only be called until it is successful");
95-
let workdir = repo.work_dir().ok_or_else(|| Error::BareRepository {
95+
let workdir = repo.workdir().ok_or_else(|| Error::BareRepository {
9696
git_dir: repo.git_dir().to_owned(),
9797
})?;
9898

@@ -173,7 +173,7 @@ impl PrepareCheckout {
173173
impl Drop for PrepareCheckout {
174174
fn drop(&mut self) {
175175
if let Some(repo) = self.repo.take() {
176-
std::fs::remove_dir_all(repo.work_dir().unwrap_or_else(|| repo.path())).ok();
176+
std::fs::remove_dir_all(repo.workdir().unwrap_or_else(|| repo.path())).ok();
177177
}
178178
}
179179
}

gix/src/config/cache/init.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ impl crate::Repository {
303303
}
304304

305305
fn apply_changed_values(&mut self) {
306-
self.refs.write_reflog = util::reflog_or_default(self.config.reflog, self.work_dir().is_some());
306+
self.refs.write_reflog = util::reflog_or_default(self.config.reflog, self.workdir().is_some());
307307
self.refs.namespace.clone_from(&self.config.refs_namespace);
308308
}
309309
}

gix/src/dirwalk/iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub struct Outcome {
3434
/// The pathspecs used to guide the operation,
3535
pub pathspec: PathspecDetached,
3636
/// The root actually being used for the traversal, and useful to transform the paths returned for the user.
37-
/// It's always within the [`work-dir`](Repository::work_dir).
37+
/// It's always within the [`work-dir`](Repository::workdir).
3838
pub traversal_root: PathBuf,
3939
/// The actual result of the dirwalk.
4040
pub dirwalk: gix_dir::walk::Outcome,

gix/src/dirwalk/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub struct Outcome<'repo> {
6464
/// The pathspecs used to guide the operation,
6565
pub pathspec: Pathspec<'repo>,
6666
/// The root actually being used for the traversal, and useful to transform the paths returned for the user.
67-
/// It's always within the [`work-dir`](crate::Repository::work_dir).
67+
/// It's always within the [`work-dir`](crate::Repository::workdir).
6868
pub traversal_root: PathBuf,
6969
/// The actual result of the dirwalk.
7070
pub dirwalk: gix_dir::walk::Outcome,

gix/src/filter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ impl Pipeline<'_> {
228228

229229
let rela_path_as_path = gix_path::from_bstr(rela_path);
230230
let repo = self.repo;
231-
let worktree_dir = repo.work_dir().ok_or(Error::MissingWorktree)?;
231+
let worktree_dir = repo.workdir().ok_or(Error::MissingWorktree)?;
232232
let path = worktree_dir.join(&rela_path_as_path);
233233
let md = match std::fs::symlink_metadata(&path) {
234234
Ok(md) => md,

gix/src/pathspec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl<'repo> Pathspec<'repo> {
6060
patterns,
6161
prefix,
6262
&gix_path::realpath_opts(
63-
repo.work_dir().unwrap_or_else(|| repo.git_dir()),
63+
repo.workdir().unwrap_or_else(|| repo.git_dir()),
6464
repo.options.current_dir_or_empty(),
6565
gix_path::realpath::MAX_SYMLINKS,
6666
)?,

gix/src/remote/connection/fetch/update_refs/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ fn insert_head(
444444
head: Option<crate::Head<'_>>,
445445
out: &mut BTreeMap<gix_ref::FullName, Vec<PathBuf>>,
446446
) -> Result<(), update::Error> {
447-
if let Some((head, wd)) = head.and_then(|head| head.repo.work_dir().map(|wd| (head, wd))) {
447+
if let Some((head, wd)) = head.and_then(|head| head.repo.workdir().map(|wd| (head, wd))) {
448448
out.entry("HEAD".try_into().expect("valid"))
449449
.or_default()
450450
.push(wd.to_owned());

gix/src/remote/connection/fetch/update_refs/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ mod update {
126126
(
127127
"+refs/remotes/origin/g:refs/heads/main",
128128
fetch::refs::update::Mode::RejectedCurrentlyCheckedOut {
129-
worktree_dirs: vec![repo.work_dir().expect("present").to_owned()],
129+
worktree_dirs: vec![repo.workdir().expect("present").to_owned()],
130130
},
131131
None,
132132
"checked out branches cannot be written, as it requires a merge of sorts which isn't done here",
@@ -498,7 +498,7 @@ mod update {
498498
"refs/heads/main",
499499
fetch::refs::Update {
500500
mode: fetch::refs::update::Mode::RejectedCurrentlyCheckedOut {
501-
worktree_dirs: vec![repo.work_dir().expect("present").to_owned()],
501+
worktree_dirs: vec![repo.workdir().expect("present").to_owned()],
502502
},
503503
type_change: None,
504504
edit_index: None,

gix/src/repository/attributes.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl Repository {
5050
Ok(AttributeStack::new(
5151
gix_worktree::Stack::new(
5252
// this is alright as we don't cause mutation of that directory, it's virtual.
53-
self.work_dir().unwrap_or(self.git_dir()),
53+
self.workdir().unwrap_or(self.git_dir()),
5454
state,
5555
case,
5656
buf,
@@ -82,7 +82,7 @@ impl Repository {
8282
Ok(AttributeStack::new(
8383
gix_worktree::Stack::new(
8484
// this is alright as we don't cause mutation of that directory, it's virtual.
85-
self.work_dir().unwrap_or(self.git_dir()),
85+
self.workdir().unwrap_or(self.git_dir()),
8686
state,
8787
case,
8888
buf,
@@ -127,7 +127,7 @@ impl Repository {
127127
Ok(AttributeStack::new(
128128
gix_worktree::Stack::new(
129129
// this is alright as we don't cause mutation of that directory, it's virtual.
130-
self.work_dir().unwrap_or(self.git_dir()),
130+
self.workdir().unwrap_or(self.git_dir()),
131131
state,
132132
case,
133133
buf,

gix/src/repository/config/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl crate::Repository {
107107
.into()
108108
},
109109
git_dir: self.git_dir().to_owned().into(),
110-
worktree_dir: self.work_dir().map(ToOwned::to_owned),
110+
worktree_dir: self.workdir().map(ToOwned::to_owned),
111111
no_replace_objects: config::shared::is_replace_refs_enabled(
112112
&self.config.resolved,
113113
self.config.lenient_config,

gix/src/repository/dirwalk.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl Repository {
3636
delegate: &mut dyn gix_dir::walk::Delegate,
3737
) -> Result<dirwalk::Outcome<'_>, dirwalk::Error> {
3838
let _span = gix_trace::coarse!("gix::dirwalk");
39-
let workdir = self.work_dir().ok_or(dirwalk::Error::MissingWorkDir)?;
39+
let workdir = self.workdir().ok_or(dirwalk::Error::MissingWorkDir)?;
4040
let mut excludes = self.excludes(
4141
index,
4242
None,
@@ -56,7 +56,7 @@ impl Repository {
5656
let accelerate_lookup = fs_caps.ignore_case.then(|| index.prepare_icase_backing());
5757
let mut opts = gix_dir::walk::Options::from(options);
5858
let worktree_relative_worktree_dirs_storage;
59-
if let Some(workdir) = self.work_dir().filter(|_| opts.for_deletion.is_some()) {
59+
if let Some(workdir) = self.workdir().filter(|_| opts.for_deletion.is_some()) {
6060
let linked_worktrees = self.worktrees()?;
6161
if !linked_worktrees.is_empty() {
6262
let real_workdir = gix_path::realpath_opts(

gix/src/repository/impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl std::fmt::Debug for crate::Repository {
3131
f.debug_struct("Repository")
3232
.field("kind", &self.kind())
3333
.field("git_dir", &self.git_dir())
34-
.field("work_dir", &self.work_dir())
34+
.field("workdir", &self.workdir())
3535
.finish()
3636
}
3737
}

gix/src/repository/location.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl crate::Repository {
3939
/// The path to the `.gitmodules` file in the worktree, if a worktree is available.
4040
#[cfg(feature = "attributes")]
4141
pub fn modules_path(&self) -> Option<PathBuf> {
42-
self.work_dir().map(|wtd| wtd.join(crate::submodule::MODULES_FILE))
42+
self.workdir().map(|wtd| wtd.join(crate::submodule::MODULES_FILE))
4343
}
4444

4545
/// The path to the `.git` directory itself, or equivalent if this is a bare repository.
@@ -48,11 +48,17 @@ impl crate::Repository {
4848
}
4949

5050
/// Return the work tree containing all checked out files, if there is one.
51+
#[deprecated = "Use `workdir()` instead"]
5152
#[doc(alias = "workdir", alias = "git2")]
5253
pub fn work_dir(&self) -> Option<&std::path::Path> {
5354
self.work_tree.as_deref()
5455
}
5556

57+
/// Return the work tree containing all checked out files, if there is one.
58+
pub fn workdir(&self) -> Option<&std::path::Path> {
59+
self.work_tree.as_deref()
60+
}
61+
5662
// TODO: tests, respect precomposeUnicode
5763
/// The directory of the binary path of the current process.
5864
pub fn install_dir(&self) -> std::io::Result<PathBuf> {
@@ -65,7 +71,7 @@ impl crate::Repository {
6571
/// Note that the CWD is obtained once upon instantiation of the repository.
6672
// TODO: tests, details - there is a lot about environment variables to change things around.
6773
pub fn prefix(&self) -> Result<Option<&Path>, gix_path::realpath::Error> {
68-
let (root, current_dir) = match self.work_dir().zip(self.options.current_dir.as_deref()) {
74+
let (root, current_dir) = match self.workdir().zip(self.options.current_dir.as_deref()) {
6975
Some((work_dir, cwd)) => (work_dir, cwd),
7076
None => return Ok(None),
7177
};

gix/src/repository/mailmap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl crate::Repository {
3333
.map(Id::detach)
3434
.ok()
3535
});
36-
match self.work_dir() {
36+
match self.workdir() {
3737
None => {
3838
blob_id = blob_id.or_else(|| {
3939
self.head().ok().and_then(|mut head| {

gix/src/repository/worktree.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ impl crate::Repository {
4545
/// registered worktree in the current working dir, even if no `.git` file or directory exists.
4646
/// It's merely based on configuration, see [Worktree::dot_git_exists()] for a way to perform more validation.
4747
pub fn worktree(&self) -> Option<Worktree<'_>> {
48-
self.work_dir().map(|path| Worktree { parent: self, path })
48+
self.workdir().map(|path| Worktree { parent: self, path })
4949
}
5050

5151
/// Return true if this repository is bare, and has no main work tree.
5252
///
5353
/// This is not to be confused with the [`worktree()`][crate::Repository::worktree()] worktree, which may exists if this instance
5454
/// was opened in a worktree that was created separately.
5555
pub fn is_bare(&self) -> bool {
56-
self.config.is_bare && self.work_dir().is_none()
56+
self.config.is_bare && self.workdir().is_none()
5757
}
5858

5959
/// If `id` points to a tree, produce a stream that yields one worktree entry after the other. The index of the tree at `id`

gix/src/revision/spec/parse/delegate/navigate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ impl delegate::Navigate for Delegate<'_> {
334334
.find_map(|stage| index.entry_index_by_path_and_stage(path, *stage).map(|_| *stage));
335335
let exists = self
336336
.repo
337-
.work_dir()
337+
.workdir()
338338
.is_some_and(|root| root.join(gix_path::from_bstr(path)).exists());
339339
self.err.push(Error::IndexLookup {
340340
desired_path: path.into(),

gix/src/status/index_worktree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ impl Repository {
103103
E: std::error::Error + Send + Sync + 'static,
104104
{
105105
let _span = gix_trace::coarse!("gix::index_worktree_status");
106-
let workdir = self.work_dir().ok_or(Error::MissingWorkDir)?;
106+
let workdir = self.workdir().ok_or(Error::MissingWorkDir)?;
107107
let attrs_and_excludes = self.attributes(
108108
index,
109109
crate::worktree::stack::state::attributes::Source::WorktreeThenIdMapping,

gix/src/submodule/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ impl Submodule<'_> {
209209
/// doesn't have a working dir set.
210210
pub fn work_dir(&self) -> Result<PathBuf, config::path::Error> {
211211
let worktree_git = gix_path::from_bstr(self.path()?);
212-
Ok(match self.state.repo.work_dir() {
212+
Ok(match self.state.repo.workdir() {
213213
None => worktree_git.into_owned(),
214214
Some(prefix) => prefix.join(worktree_git),
215215
})

gix/tests/gix/clone.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ mod blocking_io {
503503
let index = repo.index()?;
504504
assert_eq!(index.entries().len(), 1, "All entries are known as per HEAD tree");
505505

506-
assure_index_entries_on_disk(&index, repo.work_dir().expect("non-bare"));
506+
assure_index_entries_on_disk(&index, repo.workdir().expect("non-bare"));
507507
Ok(())
508508
}
509509
#[test]
@@ -550,7 +550,7 @@ mod blocking_io {
550550
let index = repo.index()?;
551551
assert_eq!(index.entries().len(), 1, "All entries are known as per HEAD tree");
552552

553-
assure_index_entries_on_disk(&index, repo.work_dir().expect("non-bare"));
553+
assure_index_entries_on_disk(&index, repo.workdir().expect("non-bare"));
554554
Ok(())
555555
}
556556

gix/tests/gix/id.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn hex_to_id(hex: &str) -> gix_hash::ObjectId {
1414
#[test]
1515
fn prefix() -> crate::Result {
1616
let repo = crate::repo("make_repo_with_fork_and_dates.sh")?.to_thread_local();
17-
let work_dir = repo.work_dir().expect("non-bare");
17+
let work_dir = repo.workdir().expect("non-bare");
1818
let id = hex_to_id("288e509293165cb5630d08f4185bdf2445bf6170").attach(&repo);
1919
let prefix = id.shorten()?;
2020
assert_eq!(prefix.cmp_oid(&id), Ordering::Equal);

gix/tests/gix/init.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ mod bare {
88
let repo = gix::init_bare(&git_dir)?;
99
assert_eq!(repo.kind(), gix::repository::Kind::Bare);
1010
assert!(
11-
repo.work_dir().is_none(),
11+
repo.workdir().is_none(),
1212
"a worktree isn't present in bare repositories"
1313
);
1414
assert_eq!(
@@ -26,7 +26,7 @@ mod bare {
2626
let repo = gix::init_bare(tmp.path())?;
2727
assert_eq!(repo.kind(), gix::repository::Kind::Bare);
2828
assert!(
29-
repo.work_dir().is_none(),
29+
repo.workdir().is_none(),
3030
"a worktree isn't present in bare repositories"
3131
);
3232
assert_eq!(
@@ -79,14 +79,14 @@ mod non_bare {
7979
let tmp = tempfile::tempdir()?;
8080
let repo = gix::init(tmp.path())?;
8181
assert_eq!(repo.kind(), gix::repository::Kind::WorkTree { is_linked: false });
82-
assert_eq!(repo.work_dir(), Some(tmp.path()), "there is a work tree by default");
82+
assert_eq!(repo.workdir(), Some(tmp.path()), "there is a work tree by default");
8383
assert_eq!(
8484
repo.git_dir(),
8585
tmp.path().join(".git"),
8686
"there is a work tree by default"
8787
);
8888
assert_eq!(gix::open(repo.git_dir())?, repo);
89-
assert_eq!(gix::open(repo.work_dir().as_ref().expect("non-bare repo"))?, repo);
89+
assert_eq!(gix::open(repo.workdir().as_ref().expect("non-bare repo"))?, repo);
9090
Ok(())
9191
}
9292

@@ -117,7 +117,7 @@ mod non_bare {
117117
std::fs::write(tmp.path().join("existing.txt"), b"I was here before you")?;
118118

119119
let repo = gix::init(tmp.path())?;
120-
assert_eq!(repo.work_dir().expect("present"), tmp.path());
120+
assert_eq!(repo.workdir().expect("present"), tmp.path());
121121
assert_eq!(
122122
repo.git_dir(),
123123
tmp.path().join(".git"),

gix/tests/gix/remote/fetch.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ mod blocking_and_async_io {
243243
] {
244244
let (mut client_repo, _tmp) = {
245245
let client_repo = remote::repo("multi_round/client");
246-
let daemon = spawn_git_daemon_if_async(client_repo.work_dir().expect("non-bare"))?;
246+
let daemon = spawn_git_daemon_if_async(client_repo.workdir().expect("non-bare"))?;
247247
let tmp = TempDir::new()?;
248248
let repo = gix::prepare_clone_bare(
249249
daemon.as_ref().map_or_else(
@@ -270,9 +270,9 @@ mod blocking_and_async_io {
270270
)?;
271271
}
272272
let server_repo = remote::repo("multi_round/server");
273-
let daemon = spawn_git_daemon_if_async(server_repo.work_dir().expect("non-bare"))?;
273+
let daemon = spawn_git_daemon_if_async(server_repo.workdir().expect("non-bare"))?;
274274
let remote = into_daemon_remote_if_async(
275-
client_repo.remote_at(server_repo.work_dir().expect("non-bare"))?,
275+
client_repo.remote_at(server_repo.workdir().expect("non-bare"))?,
276276
daemon.as_ref(),
277277
None,
278278
);
@@ -433,7 +433,7 @@ mod blocking_and_async_io {
433433
},
434434
)?;
435435
let daemon = spawn_git_daemon_if_async(
436-
repo.work_dir()
436+
repo.workdir()
437437
.expect("non-bare")
438438
.ancestors()
439439
.nth(1)

gix/tests/gix/repository/config/identity.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn author_included_by_hasconfig() -> crate::Result {
2525
fn author_and_committer_and_fallback() -> crate::Result {
2626
for trust in [gix_sec::Trust::Full, gix_sec::Trust::Reduced] {
2727
let repo = named_repo("make_config_repo.sh")?;
28-
let work_dir = repo.work_dir().expect("present").canonicalize()?;
28+
let work_dir = repo.workdir().expect("present").canonicalize()?;
2929
let _env = Env::new()
3030
.set(
3131
"GIT_CONFIG_SYSTEM",
@@ -140,7 +140,7 @@ fn author_and_committer_and_fallback() -> crate::Result {
140140
#[serial]
141141
fn author_from_different_config_sections() -> crate::Result {
142142
let repo = named_repo("make_signatures_repo.sh")?;
143-
let work_dir = repo.work_dir().unwrap().canonicalize()?;
143+
let work_dir = repo.workdir().unwrap().canonicalize()?;
144144

145145
let _env = Env::new()
146146
.set("GIT_CONFIG_GLOBAL", work_dir.join("global.config").to_str().unwrap())

0 commit comments

Comments
 (0)