@@ -236,7 +236,7 @@ class GitManager(private val context: Context, private val settingsManager: Sett
236236 return null
237237 }
238238
239- if (repo.isBare || repo. resolve(Constants .HEAD ) == null ) return false
239+ if (repo.resolve(Constants .HEAD ) == null ) return false
240240
241241 val localHead: ObjectId = repo.resolve(Constants .HEAD )
242242 val remoteHead: ObjectId = repo.resolve(Constants .FETCH_HEAD )
@@ -399,52 +399,56 @@ class GitManager(private val context: Context, private val settingsManager: Sett
399399 logStatus(git)
400400 val uncommitted = filePaths ? : getUncommittedFilePaths(userStorageUri, git)
401401
402- if (uncommitted.isNotEmpty()) {
403- onSync.invoke()
404-
405- log(LogType .PushToRepo , " Adding Files to Stage" )
402+ if (uncommitted.isEmpty()) {
403+ log(LogType .PushToRepo , " Closing repository" )
404+ closeRepo(repo)
405+ return false
406+ }
406407
407- // Adds all uncommitted and untracked files to the index for staging.
408- git.add().apply {
409- uncommitted.forEach { addFilepattern(it) }
410- }.call()
408+ onSync.invoke()
411409
412- // Updates the index to reflect changes in already tracked files, removing deleted files without adding untracked files.
413- git.add().apply {
414- uncommitted.forEach { addFilepattern(it) }
415- isUpdate = true
416- }.call()
410+ log(LogType .PushToRepo , " Adding Files to Stage" )
417411
418- log(LogType .PushToRepo , " Getting current time" )
412+ // Adds all uncommitted and untracked files to the index for staging.
413+ git.add().apply {
414+ uncommitted.forEach { addFilepattern(it) }
415+ }.call()
419416
420- val formattedDate: String = SimpleDateFormat (" yyyy-MM-dd HH:mm:ss" , Locale .US ).apply {
421- timeZone = TimeZone .getTimeZone(" UTC" )
422- }.format(Date ())
417+ // Updates the index to reflect changes in already tracked files, removing deleted files without adding untracked files.
418+ git.add().apply {
419+ uncommitted.forEach { addFilepattern(it) }
420+ isUpdate = true
421+ }.call()
423422
424- log(LogType .PushToRepo , " Committing changes" )
425- val config: StoredConfig = git.repository.config
423+ log(LogType .PushToRepo , " Getting current time" )
426424
427- var committerEmail: String? = settingsManager.getAuthorEmail()
428- if (committerEmail == null || committerEmail == " " ) {
429- committerEmail = config.getString(" user" , null , " email" )
430- }
425+ val formattedDate: String = SimpleDateFormat (" yyyy-MM-dd HH:mm:ss" , Locale .US ).apply {
426+ timeZone = TimeZone .getTimeZone(" UTC" )
427+ }.format(Date ())
431428
432- var committerName: String? = settingsManager.getAuthorName()
433- if (committerName == null || committerName == " " ) {
434- committerName = config.getString(" user" , null , " name" )
435- }
436- if (committerName == null || committerName == " " ) {
437- committerName = settingsManager.getGitAuthCredentials().first
438- }
429+ log(LogType .PushToRepo , " Committing changes" )
430+ val config: StoredConfig = git.repository.config
439431
440- git.commit(). apply {
441- setCommitter(committerName, committerEmail ? : " " )
442- message = if ( ! syncMessage.isNullOrEmpty()) syncMessage else settingsManager.getSyncMessage().format(formattedDate )
443- }.call()
432+ var committerEmail : String? = settingsManager.getAuthorEmail()
433+ if (committerEmail == null || committerEmail == " " ) {
434+ committerEmail = config.getString( " user " , null , " email " )
435+ }
444436
445- returnResult = true
437+ var committerName: String? = settingsManager.getAuthorName()
438+ if (committerName == null || committerName == " " ) {
439+ committerName = config.getString(" user" , null , " name" )
440+ }
441+ if (committerName == null || committerName == " " ) {
442+ committerName = settingsManager.getGitAuthCredentials().first
446443 }
447444
445+ git.commit().apply {
446+ setCommitter(committerName, committerEmail ? : " " )
447+ message = if (! syncMessage.isNullOrEmpty()) syncMessage else settingsManager.getSyncMessage().format(formattedDate)
448+ }.call()
449+
450+ returnResult = true
451+
448452 if (conditionallyScheduleNetworkSync(scheduleNetworkSync)) {
449453 return null
450454 }
0 commit comments