1 // extensions: doc;docx;docm
3 // TortoiseSVN Merge script for Word Doc files
5 // Copyright (C) 2004-2008, 2011 the TortoiseSVN team
6 // This file is distributed under the same license as TortoiseSVN
15 // Davide Orlandi and Hans-Emil Skogh, 2005
16 // Richard Horton, 2011
19 var objArgs, num, sTheirDoc, sMyDoc, sBaseDoc, sMergedDoc,
20 objScript, word, baseDoc, myDoc, theirDoc, WSHShell;
22 // Microsoft Office versions for Microsoft Windows OS
25 //var vOffice2003 = 11;
29 var wdCompareTargetSelected = 0;
30 //var wdCompareTargetCurrent = 1;
31 var wdCompareTargetNew = 2;
32 var wdMergeTargetCurrent = 1;
34 objArgs = WScript.Arguments;
38 WScript.Echo("Usage: [CScript | WScript] merge-doc.js merged.doc theirs.doc mine.doc base.doc");
42 sMergedDoc = objArgs(0);
43 sTheirDoc = objArgs(1);
45 sBaseDoc = objArgs(3);
47 objScript = new ActiveXObject("Scripting.FileSystemObject");
49 if (!objScript.FileExists(sTheirDoc))
51 WScript.Echo("File " + sTheirDoc + " does not exist. Cannot compare the documents.", vbExclamation, "File not found");
55 if (!objScript.FileExists(sMergedDoc))
57 WScript.Echo("File " + sMergedDoc + " does not exist. Cannot compare the documents.", vbExclamation, "File not found");
65 word = WScript.CreateObject("Word.Application");
69 WScript.Echo("You must have Microsoft Word installed to perform this operation.");
75 // Open the base document
76 baseDoc = word.Documents.Open(sTheirDoc);
78 // Merge into the "My" document
79 if (parseInt(word.Version) < vOffice2000)
81 baseDoc.Compare(sMergedDoc);
83 else if (parseInt(word.Version) < vOffice2007)
85 baseDoc.Compare(sMergedDoc, "Comparison", wdCompareTargetNew, true, true);
87 else if (parseInt(word.Version) < vOffice2010)
89 baseDoc.Merge(sMergedDoc);
93 //2010 - handle slightly differently as the basic merge isn't that good
94 //note this is designed specifically for svn 3 way merges, during the commit conflict resolution process
96 baseDoc = word.Documents.Open(sBaseDoc);
97 myDoc = word.Documents.Open(sMyDoc);
99 baseDoc.Activate(); //required otherwise it compares the wrong docs !!!
100 baseDoc.Compare(sTheirDoc, "theirs", wdCompareTargetSelected, true, true);
102 baseDoc.Activate(); //required otherwise it compares the wrong docs !!!
103 baseDoc.Compare(sMyDoc, "mine", wdCompareTargetSelected, true, true);
107 myDoc.Activate(); //required? just in case
108 myDoc.Merge(sTheirDoc, wdMergeTargetCurrent);
111 // Show the merge result
112 if (parseInt(word.Version) < vOffice2007)
114 word.ActiveDocument.Windows(1).Visible = 1;
117 // Close the first document
118 if ((parseInt(word.Version) >= vOffice2002) && (parseInt(word.Version) < vOffice2010))
123 // Show usage hint message
124 WSHShell = WScript.CreateObject("WScript.Shell");
125 if (WSHShell.Popup("You have to accept or reject the changes before\nsaving the document to prevent future problems.\n\nWould you like to see a help page on how to do this?", 0, "TSVN Word Merge", 4 + 64) === 6)
127 WSHShell.Run("http://office.microsoft.com/en-us/assistance/HP030823691033.aspx");