File tree Expand file tree Collapse file tree 3 files changed +39
-6
lines changed Expand file tree Collapse file tree 3 files changed +39
-6
lines changed Original file line number Diff line number Diff line change @@ -30,11 +30,11 @@ public void Setup()
30
30
bool gitRepoExists = Directory . Exists ( Constants . TestRepoWithWorkingDirPath ) ;
31
31
bool dotGitDirExists = Directory . Exists ( tempDotGit ) ;
32
32
33
- if ( gitRepoExists )
33
+ if ( gitRepoExists )
34
34
{
35
35
if ( dotGitDirExists )
36
36
{
37
- DirectoryHelper . DeleteDirectory ( tempDotGit ) ;
37
+ DirectoryHelper . DeleteDirectory ( tempDotGit ) ;
38
38
}
39
39
40
40
return ;
@@ -118,6 +118,28 @@ public void CanStageANewFile()
118
118
}
119
119
}
120
120
121
+ [ Test ]
122
+ public void CanStageANewFileInAPersistentManner ( )
123
+ {
124
+ using ( var path = new TemporaryCloneOfTestRepo ( Constants . TestRepoWithWorkingDirPath ) )
125
+ {
126
+ using ( var repo = new Repository ( path . RepositoryPath ) )
127
+ {
128
+ const string filename = "unit_test.txt" ;
129
+ File . WriteAllText ( Path . Combine ( repo . Info . WorkingDirectory , filename ) , "some contents" ) ;
130
+
131
+ repo . Index . Stage ( filename ) ;
132
+ repo . Index [ filename ] . ShouldNotBeNull ( ) ;
133
+ }
134
+
135
+ using ( var repo = new Repository ( path . RepositoryPath ) )
136
+ {
137
+ const string filename = "unit_test.txt" ;
138
+ repo . Index [ filename ] . ShouldNotBeNull ( ) ;
139
+ }
140
+ }
141
+ }
142
+
121
143
[ Test ]
122
144
public void CanStageANewFileWithAFullPath ( )
123
145
{
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ namespace LibGit2Sharp.Core
6
6
internal static class NativeMethods
7
7
{
8
8
private const string libgit2 = "git2" ;
9
-
9
+
10
10
[ DllImport ( libgit2 ) ]
11
11
public static extern IntPtr git_blob_rawcontent ( IntPtr blob ) ;
12
12
@@ -60,7 +60,10 @@ internal static class NativeMethods
60
60
61
61
[ DllImport ( libgit2 ) ]
62
62
public static extern int git_index_open_inrepo ( out IndexSafeHandle index , RepositorySafeHandle repo ) ;
63
-
63
+
64
+ [ DllImport ( libgit2 ) ]
65
+ public static extern int git_index_write ( IndexSafeHandle index ) ;
66
+
64
67
[ DllImport ( libgit2 ) ]
65
68
public static extern IntPtr git_lasterror ( ) ;
66
69
Original file line number Diff line number Diff line change @@ -110,14 +110,14 @@ IEnumerator IEnumerable.GetEnumerator()
110
110
111
111
#endregion
112
112
113
-
114
-
115
113
public void Stage ( string path )
116
114
{
117
115
Ensure . ArgumentNotNullOrEmptyString ( path , "path" ) ;
118
116
119
117
var res = NativeMethods . git_index_add ( handle , BuildRelativePathFrom ( path ) ) ;
120
118
Ensure . Success ( res ) ;
119
+
120
+ UpdatePhysicalIndex ( ) ;
121
121
}
122
122
123
123
public void Unstage ( string path )
@@ -129,6 +129,14 @@ public void Unstage(string path)
129
129
130
130
res = NativeMethods . git_index_remove ( handle , res ) ;
131
131
Ensure . Success ( res ) ;
132
+
133
+ UpdatePhysicalIndex ( ) ;
134
+ }
135
+
136
+ private void UpdatePhysicalIndex ( )
137
+ {
138
+ int res = NativeMethods . git_index_write ( handle ) ;
139
+ Ensure . Success ( res ) ;
132
140
}
133
141
134
142
private string BuildRelativePathFrom ( string path ) //TODO: To be removed when libgit2 natively implements this
You can’t perform that action at this time.
0 commit comments