Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for #33 #34 #35 #36

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.11.3
sbt.version=0.12.2
66 changes: 56 additions & 10 deletions src/main/scala/ReleaseExtra.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,23 @@ object ReleaseStateTransformations {
newSt
}


lazy val inquireVersions: ReleaseStep = { st: State =>
lazy val inquireVersions = ReleaseStep(inquireVersionsAction, homogeneousVersionsCheck)
private lazy val homogeneousVersionsCheck = { st: State =>
// as we set one global version for all projects (version in ThisBuild)
// we have to make sure versions are homogeneous across aggregated projects
// so that we don't publish aggregates with incorrect versions (for instance a SNAPSHOT)
val extracted = st.extract
val rootVersion = extracted.get(version)
for(aggregate <- extracted.currentProject.aggregate) {
val aggregateVersion = extracted.get(version.in(aggregate))
if( aggregateVersion != rootVersion ) {
sys.error("Aggregated project '%s' has version '%s' which differs from its root : '%s'" format (aggregate.project, aggregateVersion, rootVersion))
sys.error("You probably have multiple 'version.sbt' files. sbt-release only support one identical version for all aggregated projects.")
}
}
st
}
private lazy val inquireVersionsAction = { st: State =>
val extracted = Project.extract(st)

val useDefs = st.get(useDefaults).getOrElse(false)
Expand Down Expand Up @@ -68,16 +83,33 @@ object ReleaseStateTransformations {
lazy val setNextVersion: ReleaseStep = setVersion(_._2)
private[sbtrelease] def setVersion(selectVersion: Versions => String): ReleaseStep = { st: State =>
val vs = st.get(versions).getOrElse(sys.error("No versions are set! Was this release part executed before inquireVersions?"))
val selected = selectVersion(vs)
val newVersion = selectVersion(vs)

val currentVersion = st.extract.get(version)
if (newVersion == currentVersion) {
st.log.info("No version update needed, version remains '%s'" format currentVersion)
st
} else {
st.log.info("Setting version to '%s'." format newVersion)

st.log.info("Setting version to '%s'." format selected)
writeVersionToFile(newVersion, st)

val versionString = "%sversion in ThisBuild := \"%s\"%s" format (lineSep, selected, lineSep)
IO.write(new File("version.sbt"), versionString)
val newSt = reapply(Seq(
version in ThisBuild := newVersion,
version := newVersion // in case the previous version.sbt file had its version defined this way
// it would override 'version in ThisBuild' so we could be releasing a
// SNAPSHOT instead
), st)

reapply(Seq(
version in ThisBuild := selected
), st)
homogeneousVersionsCheck(newSt)
}
}

private def writeVersionToFile(version: String, st: State) {
val versionString = "%sversion in ThisBuild := \"%s\"%s" format (lineSep, version, lineSep)
val file = new File("version.sbt")
st.log.info("Updating " + file.getAbsolutePath)
IO.write(file, versionString)
}

private def vcs(st: State): Vcs = {
Expand All @@ -87,7 +119,21 @@ object ReleaseStateTransformations {
private[sbtrelease] lazy val initialVcsChecks = { st: State =>
val status = (vcs(st).status !!).trim
if (status.nonEmpty) {
sys.error("Aborting release. Working directory is dirty.")
if( st.get(interactiveCommit).getOrElse(true) ) {
st.log.info("Working directory is dirty:")
st.log.info("\n\t" + status.replaceAll("\\n","\n\t"))

SimpleReader.readLine("\nEnter a message to add everything and commit: ") match {
case Some(message) =>
vcs(st).addAll !! st.log
vcs(st).commit(message) !! st.log

case None =>
sys.error("No message entered. Aborting release!")
}
} else {
sys.error("Aborting release. Working directory is dirty.")
}
}

st.log.info("Starting release process off commit: " + vcs(st).currentHash)
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/ReleasePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ object ReleasePlugin extends Plugin {

lazy val versions = AttributeKey[Versions]("release-versions")
lazy val useDefaults = AttributeKey[Boolean]("release-use-defaults")
lazy val interactiveCommit = AttributeKey[Boolean]("release-interactive-commit", "If the repository is dirty, allow the user to commit within the SBT shell")
lazy val skipTests = AttributeKey[Boolean]("release-skip-tests")
lazy val crossBuild = AttributeKey[Boolean]("release-cross-build")

Expand Down
5 changes: 5 additions & 0 deletions src/main/scala/Vcs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ trait Vcs {
def status: ProcessBuilder
def currentHash: String
def add(files: String*): ProcessBuilder
def addAll: ProcessBuilder
def commit(message: String): ProcessBuilder
def existsTag(name: String): Boolean
def checkRemote(remote: String): ProcessBuilder
Expand Down Expand Up @@ -60,6 +61,8 @@ object Mercurial extends Vcs with GitLike {

protected val markerDirectory = ".hg"

def addAll = cmd("add")

def status = cmd("status")

def currentHash = (cmd("identify", "-i") !!) trim
Expand Down Expand Up @@ -93,6 +96,8 @@ object Git extends Vcs with GitLike {
private lazy val trackingRemoteCmd: ProcessBuilder = cmd("config", "branch.%s.remote" format currentBranch)
def trackingRemote: String = (trackingRemoteCmd !!) trim

def addAll = cmd("add","-A",".")

def hasUpstream = trackingRemoteCmd ! devnull == 0 && trackingBranchCmd ! devnull == 0

def currentBranch = (cmd("symbolic-ref", "HEAD") !!).trim.stripPrefix("refs/heads/")
Expand Down