@@ -271,6 +271,38 @@ class GitRepositoryTests: XCTestCase {
271
271
}
272
272
}
273
273
274
+ func testHasUnpushedCommits( ) throws {
275
+ mktmpdir { path in
276
+ // Create a repo.
277
+ let testRepoPath = path. appending ( component: " test-repo " )
278
+ try makeDirectories ( testRepoPath)
279
+ initGitRepo ( testRepoPath)
280
+
281
+ // Clone it somewhere.
282
+ let testClonePath = path. appending ( component: " clone " )
283
+ let provider = GitRepositoryProvider ( )
284
+ let repoSpec = RepositorySpecifier ( url: testRepoPath. asString)
285
+ try provider. fetch ( repository: repoSpec, to: testClonePath)
286
+
287
+ // Clone off a checkout.
288
+ let checkoutPath = path. appending ( component: " checkout " )
289
+ try provider. cloneCheckout ( repository: repoSpec, at: testClonePath, to: checkoutPath)
290
+ let checkoutRepo = try provider. openCheckout ( at: checkoutPath)
291
+
292
+ XCTAssertFalse ( try checkoutRepo. hasUnpushedCommits ( ) )
293
+ // Add a new file to checkout.
294
+ try localFileSystem. writeFileContents ( checkoutPath. appending ( component: " test.txt " ) , bytes: " Hi " )
295
+ try systemQuietly ( [ Git . tool, " -C " , checkoutPath. asString, " add " , " test.txt " ] )
296
+ try systemQuietly ( [ Git . tool, " -C " , checkoutPath. asString, " commit " , " -m " , " Add some files. " ] )
297
+
298
+ // We should have commits which are not pushed.
299
+ XCTAssert ( try checkoutRepo. hasUnpushedCommits ( ) )
300
+ // Push the changes and check again.
301
+ try systemQuietly ( [ Git . tool, " -C " , checkoutPath. asString, " push " ] )
302
+ XCTAssertFalse ( try checkoutRepo. hasUnpushedCommits ( ) )
303
+ }
304
+ }
305
+
274
306
static var allTests = [
275
307
( " testFetch " , testFetch) ,
276
308
( " testRepositorySpecifier " , testRepositorySpecifier) ,
@@ -279,5 +311,6 @@ class GitRepositoryTests: XCTestCase {
279
311
( " testRawRepository " , testRawRepository) ,
280
312
( " testGitFileView " , testGitFileView) ,
281
313
( " testCheckouts " , testCheckouts) ,
314
+ ( " testHasUnpushedCommits " , testHasUnpushedCommits) ,
282
315
]
283
316
}
0 commit comments