File tree Expand file tree Collapse file tree 4 files changed +39
-4
lines changed Expand file tree Collapse file tree 4 files changed +39
-4
lines changed Original file line number Diff line number Diff line change @@ -164,7 +164,11 @@ impl<'repo> Submodule<'repo> {
164
164
/// If `Some()`, but `None` when calling [`Self::head_id()`], then the submodule was just added without having committed the change.
165
165
pub fn index_id ( & self ) -> Result < Option < gix_hash:: ObjectId > , index_id:: Error > {
166
166
let path = self . path ( ) ?;
167
- Ok ( self . state . index ( ) ?. entry_by_path ( & path) . map ( |entry| entry. id ) )
167
+ Ok ( self
168
+ . state
169
+ . index ( ) ?
170
+ . entry_by_path ( & path)
171
+ . and_then ( |entry| ( entry. mode == gix_index:: entry:: Mode :: COMMIT ) . then_some ( entry. id ) ) )
168
172
}
169
173
170
174
/// Return the object id of the submodule as stored in `HEAD^{tree}` of the superproject, or `None` if it wasn't yet committed.
@@ -180,7 +184,7 @@ impl<'repo> Submodule<'repo> {
180
184
. head_commit ( ) ?
181
185
. tree ( ) ?
182
186
. peel_to_entry_by_path ( gix_path:: from_bstr ( path. as_ref ( ) ) ) ?
183
- . map ( |entry| entry. inner . oid ) )
187
+ . and_then ( |entry| ( entry. mode ( ) == gix_object :: tree :: EntryMode :: Commit ) . then_some ( entry . inner . oid ) ) )
184
188
}
185
189
186
190
/// Return the path at which the repository of the submodule should be located.
Original file line number Diff line number Diff line change 1
1
version https://git-lfs.github.com/spec/v1
2
- oid sha256:0c0437e6ee0730c0ffcea0368777daec45e75f0d0ef6e7464d6b5de19f822b83
3
- size 21428
2
+ oid sha256:78fe07f2f55b0f90ed2b2b70cab81ba11bacaa71943990d4206b6fef04152110
3
+ size 23128
Original file line number Diff line number Diff line change @@ -62,3 +62,12 @@ git clone --bare with-submodules with-submodules-after-clone.git
62
62
git clone --bare ../module1 modules/m1
63
63
)
64
64
65
+ git clone with-submodules not-a-submodule
66
+ (cd not-a-submodule
67
+ git submodule update --init
68
+ cp .gitmodules modules.bak
69
+ git rm m1
70
+ echo fake > m1
71
+ mv modules.bak .gitmodules
72
+ git add m1 && git commit -m " no submodule in index and commit, but in configuration"
73
+ )
Original file line number Diff line number Diff line change @@ -46,6 +46,18 @@ mod open {
46
46
} ,
47
47
) ] ,
48
48
) ,
49
+ (
50
+ "not-a-submodule" ,
51
+ & [ (
52
+ "m1" ,
53
+ gix:: submodule:: State {
54
+ repository_exists : true ,
55
+ is_old_form : false ,
56
+ worktree_checkout : false ,
57
+ superproject_configuration : true ,
58
+ } ,
59
+ ) ] ,
60
+ ) ,
49
61
] {
50
62
let repo = repo ( name) ?;
51
63
for ( sm, ( name, expected) ) in repo. submodules ( ) ?. expect ( "modules present" ) . zip ( expected) {
@@ -81,6 +93,16 @@ mod open {
81
93
Ok ( ( ) )
82
94
}
83
95
96
+ #[ test]
97
+ fn not_a_submodule ( ) -> crate :: Result {
98
+ let repo = repo ( "not-a-submodule" ) ?;
99
+ let sm = repo. submodules ( ) ?. into_iter ( ) . flatten ( ) . next ( ) . expect ( "one submodule" ) ;
100
+ assert ! ( sm. open( ) ?. is_some( ) , "repo available as it was cloned" ) ;
101
+ assert ! ( sm. index_id( ) ?. is_none( ) , "no actual submodule" ) ;
102
+ assert ! ( sm. head_id( ) ?. is_none( ) , "no actual submodule" ) ;
103
+ Ok ( ( ) )
104
+ }
105
+
84
106
#[ test]
85
107
fn old_form ( ) -> crate :: Result {
86
108
for name in [ "old-form-invalid-worktree-path" , "old-form" ] {
You can’t perform that action at this time.
0 commit comments