forked from gitextensions/gitextensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge-doc.js
126 lines (110 loc) · 3.56 KB
/
merge-doc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// extensions: doc;docx;docm
//
// TortoiseSVN Merge script for Word Doc files
//
// Copyright (C) 2004-2008, 2011 the TortoiseSVN team
// This file is distributed under the same license as TortoiseSVN
//
// Last commit by:
// $Author: tortoisesvn $
// $Date: 2011-11-08 19:59:14 +0100 (Di, 08. Nov 2011) $
// $Rev: 22250 $
//
// Authors:
// Dan Sheridan, 2008
// Davide Orlandi and Hans-Emil Skogh, 2005
// Richard Horton, 2011
//
// Modified by Henk Westhuis for Git Extensions (2010)
//
var objArgs,num,sTheirDoc,sMyDoc,sBaseDoc,sMergedDoc,objScript,word,baseDoc,myDoc,theirDoc,WSHShell;
// Microsoft Office versions for Microsoft Windows OS
var vOffice2000 = 9;
var vOffice2002 = 10;
var vOffice2003 = 11;
var vOffice2007 = 12;
var vOffice2010 = 14;
// WdCompareTarget
var wdCompareTargetSelected = 0;
var wdCompareTargetCurrent = 1;
var wdCompareTargetNew = 2;
var wdMergeTargetCurrent = 1;
objArgs = WScript.Arguments;
num = objArgs.length;
if (num < 4)
{
WScript.Echo("Usage: [CScript | WScript] merge-doc.js merged.doc theirs.doc mine.doc base.doc");
WScript.Quit(1);
}
sMergedDoc=objArgs(0);
sTheirDoc=objArgs(1);
sMyDoc=objArgs(2);
sBaseDoc=objArgs(3);
objScript = new ActiveXObject("Scripting.FileSystemObject")
if ( ! objScript.FileExists(sTheirDoc))
{
WScript.Echo("File " + sTheirDoc +" does not exist. Cannot compare the documents.", vbExclamation, "File not found");
WScript.Quit(1);
}
if ( ! objScript.FileExists(sMergedDoc))
{
WScript.Echo("File " + sMergedDoc +" does not exist. Cannot compare the documents.", vbExclamation, "File not found");
WScript.Quit(1);
}
objScript = null
try
{
word = WScript.CreateObject("Word.Application");
}
catch(e)
{
WScript.Echo("You must have Microsoft Word installed to perform this operation.");
WScript.Quit(1);
}
word.visible = true
// Open the base document
baseDoc = word.Documents.Open(sTheirDoc);
// Merge into the "My" document
if (parseInt(word.Version) < vOffice2000)
{
baseDoc.Compare(sMergedDoc);
}
else if (parseInt(word.Version) < vOffice2007)
{
baseDoc.Compare(sMergedDoc, "Comparison", wdCompareTargetNew, true, true);
}
else if (parseInt(word.Version) < vOffice2010)
{
baseDoc.Merge(sMergedDoc);
}
else //2010 - handle slightly differently as the basic merge isn't that good
//note this is designed specifically for svn 3 way merges, during the commit conflict resolution process
{
theirDoc = baseDoc;
baseDoc = word.Documents.Open(sBaseDoc);
myDoc = word.Documents.Open(sMyDoc);
baseDoc.Activate(); //required otherwise it compares the wrong docs !!!
baseDoc.Compare(sTheirDoc, "theirs", wdCompareTargetSelected, true, true);
baseDoc.Activate(); //required otherwise it compares the wrong docs !!!
baseDoc.Compare(sMyDoc, "mine", wdCompareTargetSelected, true, true);
//theirDoc.Save();
//myDoc.Save();
myDoc.Activate(); //required? just in case
myDoc.Merge(sTheirDoc, wdMergeTargetCurrent);
}
// Show the merge result
if (parseInt(word.Version) < vOffice2007)
{
word.ActiveDocument.Windows(1).Visible = 1;
}
// Close the first document
if ((parseInt(word.Version) >= vOffice2002)&&(parseInt(word.Version) < vOffice2010))
{
baseDoc.Close();
}
// Show usage hint message
WSHShell = WScript.CreateObject("WScript.Shell");
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, "Word Merge", 4 + 64) == 6)
{
WSHShell.Run("http://office.microsoft.com/en-us/assistance/HP030823691033.aspx");
}