Fossil

Artifact [7a35517172]
Login

Artifact [7a35517172]

Artifact 7a35517172d73ae364b8be44060d50e0737059b9:


#
# Tests for the "amend" command.
#

# Make sure we are not in an open repository and initialize new repository
repo_init

########################################
# Setup: Add file and commit           #
########################################
write_file datafile "data"
write_file commitmsg "committed"

fossil add datafile
fossil commit -m "c1"
write_file datafile "data.file"
fossil commit -m "c2"
if {![regexp {^New_Version: ([0-9a-f]{40})$} $RESULT m UUID]} {
  test amend-setup-failure false
  return
}

########################################
# Test: -branch                        #
########################################
fossil amend $UUID -branch amended-branch
test amend-branch-1.1 {[regexp {tags:\s+amended-branch} $RESULT]}
fossil branch ls
test amend-branch-1.2 {[string first "* amended-branch" $RESULT] != -1}
fossil tag list
test amend-branch-1.3 {[string first amended-branch $RESULT] != -1}
fossil tag list --raw $UUID
test amend-branch-1.4 {[string first "branch=amended-branch" $RESULT] != -1}
test amend-branch-1.5 {[string first "sym-amended-branch" $RESULT] != -1}
fossil timeline -n 1
test amend-branch-1.6 {[string match {*Move*to*branch*amended-branch*} $RESULT]}

########################################
# Test: -bgcolor                       #
########################################
set tc 0
foreach {color result} {
  0 0
  a a
  abcdef #abcdef
  abc123 #abc123
  123efg 123efg
  abcdefg abcdefg
  abcdeg abcdeg
  blue blue
  acf #acf
  123 #123
  #1234 #1234
  1234 1234
  123456 #123456
} {
  incr tc
  fossil amend $UUID -bgcolor $color
  test amend-bgcolor-$tc.1 {[string match "*uuid:*$UUID*" $RESULT]}
  fossil tag list --raw $UUID
  test amend-bgcolor-$tc.2 {[string first "bgcolor=$result" $RESULT] != -1}
  fossil timeline -n 1
  test amend-bgcolor-$tc.3 {
    [string match "*Change*background*color*to*\"$result\"*" $RESULT]
  }
  if {[regexp {(?x)[0-9]{2}(?::[0-9]{2}){2}\s+\[([0-9a-f]+)]} $RESULT m artid]}\
  {
    fossil artifact $artid
    test amend-bgcolor-$tc.4 {
      [string match "*T +bgcolor $UUID $result*" $RESULT]
    }
  } else {
    if {$VERBOSE} { protOut "No artifact found in timeline output" }
    test amend-bgcolor-$tc.4 false
  }
}

########################################
# Test: -branchcolor                   #
########################################
fossil amend $UUID -branchcolor yellow
test amend-branchcolor-1.1 {[string match "*uuid:*$UUID*" $RESULT]}
fossil tag ls --raw $UUID
test amend-branchcolor-1.2 {[string first "bgcolor=yellow" $RESULT] != -1}
fossil timeline -n 1
test amend-branchcolor-1.3 {
  [string match {*Change*branch*background*color*to*"yellow".*} $RESULT]
}
if {[regexp {(?x)[0-9]{2}(?::[0-9]{2}){2}\s+\[([0-9a-f]+)]} $RESULT m artid]} {
  fossil artifact $artid
  test amend-branchcolor-1.4 {
    [string match "*T \*bgcolor $UUID yellow*" $RESULT]
  }
} else {
  if {$VERBOSE} { protOut "No artifact found in timeline output" }
  test amend-branchcolor-1.4 false
}

########################################
# Test: -author                        #
########################################
fossil amend $UUID -author author-test
test amend-author-1.1 {[string match {*comment:*(user:*author-test)*} $RESULT]}
fossil tag ls --raw $UUID
test amend-author-1.2 {[string first "user=author-test" $RESULT] != -1}
fossil timeline -n 1
test amend-author-1.3 {[string match {*Change*user*to*"author-test".*} $RESULT]}

########################################
# Test: -date                          #
########################################
set timestamp [clock scan yesterday]
set date [clock format $timestamp -format "%Y-%m-%d" -gmt 1]
set time [clock format $timestamp -format "%H:%M:%S" -gmt 1]
set datetime "$date $time"
fossil amend $UUID -date $datetime
test amend-date-1.1 {[string match "*uuid:*$UUID*$datetime*" $RESULT]}
fossil tag ls --raw $UUID
test amend-date-1.2 {[string first "date=$datetime" $RESULT] != -1}
fossil timeline -n 1
test amend-date-1.3 {[string match "*Timestamp*$date*$time*" $RESULT]}
set badformats {
  "%+"
  "%Y-%m-%d %H:%M%:%S %Z"
  "%d/%m/%Y %H:%M%:%S %Z"
  "%d/%m/%Y %H:%M%:%S"
  "%d/%m/%Y"
}
set sc 0
foreach badformat $badformats {
  incr sc
  set datetime [clock format $timestamp -format $badformat -gmt 1]
  fossil amend $UUID -date $datetime
  test amend-date-2.$sc {[string first "YYYY-MM-DD HH:MM:SS" $RESULT] != -1}
}

########################################
# Test: -hide                          #
########################################
fossil amend $UUID -hide
test amend-hide-1.1 {[string match "*uuid:*$UUID*" $RESULT]}
fossil tag ls --raw $UUID
test amend-hide-1.2 {[string first "hidden" $RESULT] != -1}
fossil timeline -n 1
test amend-hide-1.3 {[string match {*Add*propagating*"hidden".*} $RESULT]}

########################################
# Test: -close                          #
########################################
fossil amend $UUID -close
test amend-close-1.1 {[string match "*uuid:*$UUID*" $RESULT]}
fossil tag ls --raw $UUID
test amend-close-1.2 {[string first "closed" $RESULT] != -1}
fossil timeline -n 1
test amend-close-1.3 {[string match {*Marked*"Closed".*} $RESULT]}
write_file datafile "changed"
fossil commit -m "should fail"
test amend-close-2 {[string first "closed leaf" $RESULT] != -1}

fossil revert
fossil update trunk
write_file datafile "cb"
fossil commit -m "closed-branch" --branch "closebranch"
if {![regexp {^New_Version: ([0-9a-f]{40})$} $RESULT m UUID3]} {
  test amend-close-3.all false
} else {
  write_file datafile "b1"
  fossil commit -m "m1"
  write_file datafile "b2"
  fossil commit -m "m2"
  fossil amend $UUID3 --close
  test amend-close-3.1 {[string match "*uuid:*$UUID3*" $RESULT]}
  fossil tag ls --raw current
  test amend-close-3.2 {[string first "closed" $RESULT] != -1}
  fossil timeline -n 1
  test amend-close-3.3 {
    [string match "*Add*propagating*\"closed\".*" $RESULT]
  }
  write_file datafile "changed"
  fossil commit -m "should fail"
  test amend-close-3.4 {[string first "closed leaf" $RESULT] != -1}
}