# File lib/fastcst/command/finish.rb, line 22
22:         def run
23:             repo = Repository.new @repo_dir
24:             
25:             # check that a revision is in progress
26:             if not repo['Current Revision']
27:                 UI.failure :constraint, "You have not used begin to start a revision yet."
28:                 return
29:             end
30:             
31:             parent_id = repo['Path'].pop
32:             md_file = File.join(repo.work_dir, "meta-data.yaml")
33:             md = MetaData.load_metadata(md_file)
34:             cs_name = repo['Project'] + '-' + md['Revision']
35:             
36:             Dir.chdir repo.work_dir do
37:                 originals = File.join("..","originals")
38:                 sources = File.join("..","..")
39:                 
40:                 data_file = cs_name + ".fcs"
41:                 journal_file = cs_name + ".yaml"
42:                 
43:                 changes = ChangeSet.make_changeset(cs_name, originals, sources)
44: 
45:                 # abort if there were no changes
46:                 if not changes.has_changes?
47:                     return
48:                 end
49:                 
50:                 # create the undo
51:                 if not File.exist? "undo.yaml"
52:                     # the undo changeset has to go in the reverse direction
53:                     UI.start_finish("Creating 'undo' revision") do
54:                         changes = ChangeSet.make_changeset("undo", sources, originals)
55:                     end
56:                 end
57:                 
58:                 # sync the originals directory
59:                 journal_in = Zlib::GzipReader.new(File.open(journal_file))
60:                 data_in = Zlib::GzipReader.new(File.open(data_file))
61:                 
62:                 # apply closes the files for us
63:                 ChangeSet.apply_changeset(journal_in, data_in, originals)
64: 
65:                 # create the meta-data
66:                 MetaData.finish_metadata(md_file, parent_id, data_file, journal_file)
67:             end
68:         
69:             # store the newly created changeset, doing a move instead of a copy
70:             md = repo.store_changeset repo.work_dir, "meta-data.yaml", move=true
71:             
72:             # get the new location and move the undo there
73:             cs_path, md = repo.find_changeset(md['ID'])
74:             FileUtils.mv(File.join(repo.work_dir, "undo.yaml"), cs_path)
75:             FileUtils.mv(File.join(repo.work_dir, "undo.fcs"), cs_path)
76:             
77:             # and update the environment to reflect our new revision path
78:             repo["Path"] = repo["Path"] << md['ID']
79:             
80:             UI.event :finished, "New revision: #{repo.build_readable_name md['ID']}"
81:             
82:             # and remove the current revision
83:             repo.delete 'Current Revision'
84:         end