Skip to content

Commit 055611c

Browse files
committed
Add a test to assure we can detect conflicts
1 parent 27471e7 commit 055611c

File tree

7 files changed

+66
-39
lines changed

7 files changed

+66
-39
lines changed

gix-worktree/src/index/status/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ pub enum Change<T = ()> {
3232
/// changed than this is `None`.
3333
content_change: Option<T>,
3434
},
35-
/// An index entry that correspond to an untracked worktree file marked with `git add`.
35+
/// An index entry that correspond to an untracked worktree file marked with `git add --intent-to-add`.
3636
///
37-
/// This means it's not available in the git tree yet that the index was created from,
37+
/// This means it's not available in the object database yet or the index was created from,
3838
/// even though now an entry exists that represents the worktree file.
39-
Added,
39+
IntentToAdd,
4040
}
4141

4242
/// Observe changes by comparing an index entry to the worktree or another index.

gix-worktree/src/index/status/worktree.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ pub struct Options {
4646
/// observable in `collector`, along with information produced by `compare` which gets to see blobs that may have changes.
4747
/// `options` are used to configure the operation.
4848
///
49+
/// Note that `index` is updated with the latest seen stat information from the worktree, and its timestamp is adjusted to
50+
/// the current time for which it will be considered fresh.
51+
///
4952
/// Note that this isn't technically quite what this function does as this also provides some additional information,
5053
/// like whether a file has conflicts, and files that were added with `git add` are shown as a special
5154
/// changes despite not technically requiring a change to the index since `git add` already added the file to the index.
@@ -222,7 +225,7 @@ impl<'index> State<'_, 'index> {
222225
}
223226
};
224227
if entry.flags.contains(index::entry::Flags::INTENT_TO_ADD) {
225-
return Ok(Some(Change::Added));
228+
return Ok(Some(Change::IntentToAdd));
226229
}
227230
let new_stat = index::entry::Stat::from_fs(&metadata)?;
228231
let executable_bit_changed =
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:cd6d32ab7a1e372d80a617926cac2463f6620baedf74642d78fe7f8c956fd031
3+
size 11036
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:876670d74c01249d361aa73d83ab20d846db7c922a3ca825f778b5f9d746c401
3+
size 9304
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
set -eu -o pipefail
3+
4+
git init -q
5+
6+
echo base > content
7+
git add -A
8+
git commit -m "base"
9+
10+
git checkout -b feat
11+
echo feat > content
12+
git commit -am "feat"
13+
14+
git checkout main
15+
echo base-change > content
16+
git commit -am "new base"
17+
18+
git merge feat || :
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
set -eu -o pipefail
3+
4+
git init -q
5+
6+
touch content
7+
echo -n "content" > content
8+
9+
git add --intent-to-add -A

gix-worktree/tests/worktree/index/status.rs

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use bstr::BStr;
22
use filetime::{set_file_mtime, FileTime};
3-
use gix_features::threading::OwnShared;
43
use gix_index as index;
54
use gix_index::Entry;
65
use gix_utils::FilesystemCapabilities;
76
use gix_worktree::index::status::content::{FastEq, ReadDataOnce};
87
use gix_worktree::index::status::worktree::{self, Options};
98
use gix_worktree::index::status::{Change, CompareBlobs, Recorder};
109
use std::sync::atomic::{AtomicUsize, Ordering};
10+
use std::sync::Arc;
1111

1212
use crate::fixture_path;
1313

@@ -57,45 +57,36 @@ fn removed() {
5757
);
5858
}
5959

60+
#[test]
61+
fn intent_to_add() {
62+
fixture(
63+
"status_intent_to_add",
64+
&[(BStr::new(b"content"), Some(Change::IntentToAdd), false)],
65+
);
66+
}
67+
68+
#[test]
69+
fn conflict() {
70+
fixture(
71+
"status_conflict",
72+
&[(
73+
BStr::new(b"content"),
74+
Some(Change::Modification {
75+
executable_bit_changed: false,
76+
content_change: Some(()),
77+
}),
78+
true,
79+
)],
80+
);
81+
}
82+
6083
#[test]
6184
fn unchanged() {
6285
fixture("status_unchanged", &[]);
6386
}
6487

6588
#[test]
6689
fn modified() {
67-
// run the same status check twice to ensure that racy detection
68-
// doesn't change the result of the status check
69-
fixture(
70-
"status_changed",
71-
&[
72-
(
73-
BStr::new(b"dir/content"),
74-
Some(Change::Modification {
75-
executable_bit_changed: true,
76-
content_change: None,
77-
}),
78-
false,
79-
),
80-
(
81-
BStr::new(b"dir/content2"),
82-
Some(Change::Modification {
83-
executable_bit_changed: false,
84-
content_change: Some(()),
85-
}),
86-
false,
87-
),
88-
(BStr::new(b"empty"), Some(Change::Type), false),
89-
(
90-
BStr::new(b"executable"),
91-
Some(Change::Modification {
92-
executable_bit_changed: true,
93-
content_change: Some(()),
94-
}),
95-
false,
96-
),
97-
],
98-
);
9990
fixture(
10091
"status_changed",
10192
&[
@@ -141,7 +132,7 @@ fn racy_git() {
141132
let mut index = gix_index::File::at(git_dir.join("index"), gix_hash::Kind::Sha1, Default::default()).unwrap();
142133

143134
#[derive(Clone)]
144-
struct CountCalls(OwnShared<AtomicUsize>, FastEq);
135+
struct CountCalls(Arc<AtomicUsize>, FastEq);
145136
impl CompareBlobs for CountCalls {
146137
type Output = ();
147138

@@ -169,7 +160,7 @@ fn racy_git() {
169160
.expect("changing filetime works");
170161
let mut recorder = Recorder::default();
171162

172-
let count = OwnShared::new(AtomicUsize::new(0));
163+
let count = Arc::new(AtomicUsize::new(0));
173164
let counter = CountCalls(count.clone(), FastEq);
174165
worktree::changes_to_obtain(
175166
&mut index,

0 commit comments

Comments
 (0)