2

I'm trying to set this up for this first time on a project of mine, and I'm curious as to why some items are still considered un-staged after I do a grgit.add().

My build.gradle

task gitCommit {
    group = "Custom"
    description = "Commits the version build number changes to Git"

    doLast{
        VersionTracker.setPropertiesFile(versionPropertiesFilePath)
        def appBuildVersion = VersionTracker.getBuild()
        def commitMessage= "Incremented build number; " + appBuildVersion
        try
        {
            logger.lifecycle("Commiting to Git")
            logger.lifecycle("Before add:\n${grgit.status()}\n")

            // Adds all tracked files to staging for commit
            grgit.add(patterns: ["AndroidManifest.xml", "assets/version.properties"], update: true)
            logger.lifecycle("After add:\n${grgit.status()}\n")

            // Commits the tracked changes to the local repo
            grgit.commit(message: commitMessage)
            logger.lifecycle("After commit:\n${grgit.status()}")

            // Pushes the changes to the remote repo
            grgit.push()
        }
        catch (Exception e)
        {
            logger.error("Failed...", e)
        }
        finally
        {
            logger.lifecycle("Git connection closed")
            // grgit.close()
        }
    }
}

Process

Before running the script, I run the following:

$ git status
On branch master
Your branch is up-to-date with 'origin/master'.

nothing to commit, working tree clean

Then I run a gradle script to bump the version and I get this:

$ git status
On branch master
Your branch is up-to-date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   AndroidManifest.xml
    modified:   assets/version.properties

no changes added to commit (use "git add" and/or "git commit -a")

Then I run gradle gitCommit to run the script above, which outputs the following:

Commiting to Git
Before add:
org.ajoberstar.grgit.Status(staged:org.ajoberstar.grgit.Status$Changes(added:[],modified:[], removed:[]), unstaged:org.ajoberstar.grgit.Status$Changes(added:[], modified: [Development/Android/AndroidManifest.xml, Development/Android/build.gradle, Development/Android/assets/version.properties, Development/Android/build.gradle, Development/Android/build.gradle], removed:[]), conflicts:[])

After add:
org.ajoberstar.grgit.Status(staged:org.ajoberstar.grgit.Status$Changes(added:[],modified:[], removed:[]), unstaged:org.ajoberstar.grgit.Status$Changes(added:[], modified: [Development/Android/AndroidManifest.xml, Development/Android/build.gradle, Development/Android/assets/version.properties, Development/Android/build.gradle, Development/Android/build.gradle], removed:[]), conflicts:[])

After commit:
org.ajoberstar.grgit.Status(staged:org.ajoberstar.grgit.Status$Changes(added:[],modified:[], removed:[]), unstaged:org.ajoberstar.grgit.Status$Changes(added:[], modified: [Development/Android/AndroidManifest.xml, Development/Android/build.gradle, Development/Android/assets/version.properties, Development/Android/build.gradle, Development/Android/build.gradle], removed:[]), conflicts:[])

BUILD SUCCESSFUL in 9s
1 actionable task: 1 executed

But then, I try git status again and get this:

$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   AndroidManifest.xml
    modified:   assets/version.properties

no changes added to commit (use "git add" and/or "git commit -a")

I see that I'm ahead of master by 1 commit (which is an empty commit after some testing), and there are still changes not staged for commit. Any ideas how to fix this and get grgit to actually commit to the repo, or even add changes to be staged for commit?

TriskalJM
  • 2,393
  • 1
  • 19
  • 20
Cheabs
  • 37
  • 6

0 Answers0