Skip to content
Closed
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
23 changes: 8 additions & 15 deletions src/main/scala/ReleaseExtra.scala
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,6 @@ object ReleaseStateTransformations {

lazy val pushChanges: ReleaseStep = ReleaseStep(pushChangesAction, checkUpstream)
private[sbtrelease] lazy val checkUpstream = { st: State =>
if (!vcs(st).hasUpstream) {
sys.error("No tracking branch is set up. Either configure a remote tracking branch, or remove the pushChanges release part.")
}
val defaultChoice = extractDefault(st, "n")

st.log.info("Checking remote [%s] ..." format vcs(st).trackingRemote)
Expand All @@ -240,18 +237,14 @@ object ReleaseStateTransformations {
val defaultChoice = extractDefault(st, "y")

val vc = vcs(st)
if (vc.hasUpstream) {
defaultChoice orElse SimpleReader.readLine("Push changes to the remote repository (y/n)? [y] ") match {
case Yes() | Some("") =>
val processLogger: ProcessLogger = if (vc.isInstanceOf[Git]) {
// Git outputs to standard error, so use a logger that redirects stderr to info
vc.stdErrorToStdOut(st.log)
} else st.log
vc.pushChanges !! processLogger
case _ => st.log.warn("Remember to push the changes yourself!")
}
} else {
st.log.info("Changes were NOT pushed, because no upstream branch is configured for the local branch [%s]" format vcs(st).currentBranch)
defaultChoice orElse SimpleReader.readLine("Push changes to the remote repository (y/n)? [y] ") match {
case Yes() | Some("") =>
val processLogger: ProcessLogger = if (vc.isInstanceOf[Git]) {
// Git outputs to standard error, so use a logger that redirects stderr to info
vc.stdErrorToStdOut(st.log)
} else st.log
vc.pushChanges !! processLogger
case _ => st.log.warn("Remember to push the changes yourself!")
}
st
}
Expand Down
27 changes: 16 additions & 11 deletions src/main/scala/Vcs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ trait Vcs {
def existsTag(name: String): Boolean
def checkRemote(remote: String): ProcessBuilder
def tag(name: String, comment: String, sign: Boolean): ProcessBuilder
def hasUpstream: Boolean
def trackingRemote: String
def isBehindRemote: Boolean
def pushChanges: ProcessBuilder
Expand Down Expand Up @@ -96,8 +95,6 @@ class Mercurial(val baseDir: File) extends Vcs with GitLike {
def tag(name: String, comment: String, sign: Boolean) =
andSign(sign, cmd("tag", "-f", "-m", comment, name))

def hasUpstream = cmd("paths", "default") ! devnull == 0

def trackingRemote = "default"

def isBehindRemote = cmd("incoming", "-b", ".", "-q") ! devnull == 0
Expand Down Expand Up @@ -125,20 +122,30 @@ class Git(val baseDir: File) extends Vcs with GitLike {


private lazy val trackingBranchCmd = cmd("config", "branch.%s.merge" format currentBranch)
private def trackingBranch: String = (trackingBranchCmd !!).trim.stripPrefix("refs/heads/")
private def trackingBranch: String = try {
(trackingBranchCmd !!).trim.stripPrefix("refs/heads/")
} catch {
case _: Throwable => currentBranch
}

private lazy val trackingRemoteCmd: ProcessBuilder = cmd("config", "branch.%s.remote" format currentBranch)
def trackingRemote: String = (trackingRemoteCmd !!) trim

def hasUpstream = trackingRemoteCmd ! devnull == 0 && trackingBranchCmd ! devnull == 0
def trackingRemote: String = try {
(trackingRemoteCmd !!).trim
} catch {
case _: Throwable => "origin"
}

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

def currentHash = revParse("HEAD")

private def revParse(name: String) = (cmd("rev-parse", name) !!) trim

def isBehindRemote = (cmd("rev-list", "%s..%s/%s".format(currentBranch, trackingRemote, trackingBranch)) !! devnull).trim.nonEmpty
def isBehindRemote = try {
(cmd("rev-list", "%s..%s/%s".format(currentBranch, trackingRemote, trackingBranch)) !! devnull).trim.nonEmpty
} catch {
case _: Throwable => false
}

private def withSignFlag(sign: Boolean, flag: String)(args: String*) =
if (sign)
Expand Down Expand Up @@ -207,8 +214,6 @@ class Subversion(val baseDir: File) extends Vcs {

override def trackingRemote: String = ""

override def hasUpstream: Boolean = true

override def tag(name: String, comment: String, sign: Boolean): ProcessBuilder = {
require(!sign, "Signing not supported in Subversion.")
val tagUrl = getSvnTagUrl(name)
Expand Down Expand Up @@ -256,4 +261,4 @@ class Subversion(val baseDir: File) extends Vcs {

private[sbtrelease] object Try {
def apply[A](f: => A): Option[A] = scala.util.control.Exception.allCatch.opt(f)
}
}