Skip to content

Commit ca923f7

Browse files
committed
Merge branch 'nd/worktree-prune'
The way "git worktree prune" worked internally has been simplified, by assuming how "git worktree move" moves an existing worktree to a different place. * nd/worktree-prune: worktree prune: improve prune logic when worktree is moved worktree: delete dead code gc.txt: more details about what gc does
2 parents a5bbc29 + 327864a commit ca923f7

File tree

4 files changed

+24
-27
lines changed

4 files changed

+24
-27
lines changed

Documentation/git-gc.txt

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ DESCRIPTION
1515
-----------
1616
Runs a number of housekeeping tasks within the current repository,
1717
such as compressing file revisions (to reduce disk space and increase
18-
performance) and removing unreachable objects which may have been
19-
created from prior invocations of 'git add'.
18+
performance), removing unreachable objects which may have been
19+
created from prior invocations of 'git add', packing refs, pruning
20+
reflog, rerere metadata or stale working trees.
2021

2122
Users are encouraged to run this task on a regular basis within
2223
each repository to maintain good disk space utilization and good
@@ -45,20 +46,25 @@ OPTIONS
4546
With this option, 'git gc' checks whether any housekeeping is
4647
required; if not, it exits without performing any work.
4748
Some git commands run `git gc --auto` after performing
48-
operations that could create many loose objects.
49+
operations that could create many loose objects. Housekeeping
50+
is required if there are too many loose objects or too many
51+
packs in the repository.
4952
+
50-
Housekeeping is required if there are too many loose objects or
51-
too many packs in the repository. If the number of loose objects
52-
exceeds the value of the `gc.auto` configuration variable, then
53-
all loose objects are combined into a single pack using
54-
`git repack -d -l`. Setting the value of `gc.auto` to 0
55-
disables automatic packing of loose objects.
53+
If the number of loose objects exceeds the value of the `gc.auto`
54+
configuration variable, then all loose objects are combined into a
55+
single pack using `git repack -d -l`. Setting the value of `gc.auto`
56+
to 0 disables automatic packing of loose objects.
5657
+
5758
If the number of packs exceeds the value of `gc.autoPackLimit`,
5859
then existing packs (except those marked with a `.keep` file)
5960
are consolidated into a single pack by using the `-A` option of
6061
'git repack'. Setting `gc.autoPackLimit` to 0 disables
6162
automatic consolidation of packs.
63+
+
64+
If houskeeping is required due to many loose objects or packs, all
65+
other housekeeping tasks (e.g. rerere, working trees, reflog...) will
66+
be performed as well.
67+
6268

6369
--prune=<date>::
6470
Prune loose objects older than date (default is 2 weeks ago,
@@ -133,6 +139,10 @@ The optional configuration variable `gc.pruneExpire` controls how old
133139
the unreferenced loose objects have to be before they are pruned. The
134140
default is "2 weeks ago".
135141

142+
Optional configuration variable `gc.worktreePruneExpire` controls how
143+
old a stale working tree should be before `git worktree prune` deletes
144+
it. Default is "3 months ago".
145+
136146

137147
Notes
138148
-----

Documentation/gitrepository-layout.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,6 @@ worktrees/<id>/locked::
275275
or manually by `git worktree prune`. The file may contain a string
276276
explaining why the repository is locked.
277277

278-
worktrees/<id>/link::
279-
If this file exists, it is a hard link to the linked .git
280-
file. It is used to detect if the linked repository is
281-
manually removed.
282-
283278
SEE ALSO
284279
--------
285280
linkgit:git-init[1],

builtin/worktree.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,9 @@ static int prune_worktree(const char *id, struct strbuf *reason)
101101
}
102102
path[len] = '\0';
103103
if (!file_exists(path)) {
104-
struct stat st_link;
105104
free(path);
106-
/*
107-
* the repo is moved manually and has not been
108-
* accessed since?
109-
*/
110-
if (!stat(git_path("worktrees/%s/link", id), &st_link) &&
111-
st_link.st_nlink > 1)
112-
return 0;
113-
if (st.st_mtime <= expire) {
105+
if (stat(git_path("worktrees/%s/index", id), &st) ||
106+
st.st_mtime <= expire) {
114107
strbuf_addf(reason, _("Removing worktrees/%s: gitdir file points to non-existent location"), id);
115108
return 1;
116109
} else {

t/t2026-worktree-prune.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,9 @@ test_expect_success 'not prune locked checkout' '
7878

7979
test_expect_success 'not prune recent checkouts' '
8080
test_when_finished rm -r .git/worktrees &&
81-
mkdir zz &&
82-
mkdir -p .git/worktrees/jlm &&
83-
echo "$(pwd)"/zz >.git/worktrees/jlm/gitdir &&
84-
rmdir zz &&
81+
git worktree add jlm HEAD &&
82+
test -d .git/worktrees/jlm &&
83+
rm -rf jlm &&
8584
git worktree prune --verbose --expire=2.days.ago &&
8685
test -d .git/worktrees/jlm
8786
'

0 commit comments

Comments
 (0)