Skip to content

Commit 1d7d949

Browse files
committed
[annex] Function reordering
1 parent 25230d0 commit 1d7d949

File tree

1 file changed

+73
-73
lines changed

1 file changed

+73
-73
lines changed

git/annex.go

Lines changed: 73 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,6 @@ func AnnexInit(description string) error {
146146
return nil
147147
}
148148

149-
// parseSyncErrors should be used by all annex sync commands to check the
150-
// output for common error messages and return the appropriate gin message.
151-
func parseSyncErrors(messages string) error {
152-
if strings.Contains(messages, "Permission denied") {
153-
return fmt.Errorf("permission denied")
154-
} else if strings.Contains(messages, "Host key verification failed") {
155-
// Bad host key configured
156-
return fmt.Errorf("server key does not match known host key")
157-
}
158-
return nil
159-
}
160-
161149
// AnnexPull downloads all annexed files. Optionally also downloads all file content.
162150
// (git annex sync --no-push [--content])
163151
func AnnexPull(remote string) error {
@@ -193,23 +181,6 @@ func AnnexPull(remote string) error {
193181
return nil
194182
}
195183

196-
func checkMergeErrors(stdout, stderr string) error {
197-
messages := strings.ToLower(stdout + stderr)
198-
if strings.Contains(messages, "would be overwritten by merge") {
199-
// Untracked local file conflicts with file being pulled
200-
return fmt.Errorf("local modified or untracked files would be overwritten by download:\n %s", strings.Join(parseFilesOverwrite(messages), ", "))
201-
} else if strings.Contains(messages, "unresolved conflict") {
202-
// Merge conflict in git files
203-
return fmt.Errorf("files changed locally and remotely and cannot be automatically merged (merge conflict):\n %s", strings.Join(parseFilesConflict(messages), ", "))
204-
// abort merge
205-
} else if strings.Contains(messages, "merge conflict was automatically resolved") {
206-
// Merge conflict in annex files (automatically resolved by keeping both copies)
207-
return fmt.Errorf("files changed locally and remotely. Both files have been kept:\n %s", strings.Join(parseFilesAnnexConflict(stdout), ", "))
208-
// TODO: This should probably instead become a warning or notice, instead of a full error
209-
}
210-
return nil
211-
}
212-
213184
// AnnexSync performs a bidirectional synchronisation between local and remote
214185
// repositories, automatically resolving merge conflicts.
215186
// (git annex sync --resolvemerge)
@@ -248,50 +219,6 @@ func AnnexSync(content bool) error {
248219
return nil
249220
}
250221

251-
func parseFilesConflict(errmsg string) []string {
252-
lines := strings.Split(errmsg, "\n")
253-
var filenames []string
254-
delim := "merge conflict in "
255-
for _, l := range lines {
256-
if idx := strings.Index(l, delim); idx > -1 {
257-
filenames = append(filenames, l[idx+len(delim):])
258-
}
259-
}
260-
return filenames
261-
}
262-
263-
func parseFilesAnnexConflict(errmsg string) []string {
264-
lines := strings.Split(errmsg, "\n")
265-
var filenames []string
266-
delim := ": needs merge"
267-
for _, l := range lines {
268-
if idx := strings.Index(l, delim); idx > -1 {
269-
filenames = append(filenames, l[0:idx])
270-
}
271-
}
272-
return filenames
273-
}
274-
275-
func parseFilesOverwrite(errmsg string) []string {
276-
lines := strings.Split(errmsg, "\n")
277-
var filenames []string
278-
start := false
279-
for _, l := range lines {
280-
if strings.Contains(l, "error: the following") || strings.Contains(l, "error: your local") {
281-
start = true
282-
continue
283-
}
284-
if strings.Contains(l, "please move or remove") || strings.Contains(l, "please commit your changes") {
285-
break
286-
}
287-
if start {
288-
filenames = append(filenames, strings.TrimSpace(l))
289-
}
290-
}
291-
return filenames
292-
293-
}
294-
295222
// AnnexPush uploads all changes and new content to the default remote.
296223
// The status channel 'pushchan' is closed when this function returns.
297224
// (git annex sync --no-pull; git annex copy --to=<defaultremote>)
@@ -1140,3 +1067,76 @@ func AnnexCommand(args ...string) shell.Cmd {
11401067
log.Write("Running shell command (Dir: %s): %s", workingdir, strings.Join(cmd.Args, " "))
11411068
return cmd
11421069
}
1070+
1071+
// parseSyncErrors is used by all annex sync commands to check the
1072+
// output for common error messages and return the appropriate gin message.
1073+
func parseSyncErrors(messages string) error {
1074+
if strings.Contains(messages, "Permission denied") {
1075+
return fmt.Errorf("permission denied")
1076+
} else if strings.Contains(messages, "Host key verification failed") {
1077+
// Bad host key configured
1078+
return fmt.Errorf("server key does not match known host key")
1079+
}
1080+
return nil
1081+
}
1082+
1083+
func checkMergeErrors(stdout, stderr string) error {
1084+
messages := strings.ToLower(stdout + stderr)
1085+
if strings.Contains(messages, "would be overwritten by merge") {
1086+
// Untracked local file conflicts with file being pulled
1087+
return fmt.Errorf("local modified or untracked files would be overwritten by download:\n %s", strings.Join(parseFilesOverwrite(messages), ", "))
1088+
} else if strings.Contains(messages, "unresolved conflict") {
1089+
// Merge conflict in git files
1090+
return fmt.Errorf("files changed locally and remotely and cannot be automatically merged (merge conflict):\n %s", strings.Join(parseFilesConflict(messages), ", "))
1091+
// abort merge
1092+
} else if strings.Contains(messages, "merge conflict was automatically resolved") {
1093+
// Merge conflict in annex files (automatically resolved by keeping both copies)
1094+
return fmt.Errorf("files changed locally and remotely. Both files have been kept:\n %s", strings.Join(parseFilesAnnexConflict(stdout), ", "))
1095+
// TODO: This should probably instead become a warning or notice, instead of a full error
1096+
}
1097+
return nil
1098+
}
1099+
1100+
func parseFilesConflict(errmsg string) []string {
1101+
lines := strings.Split(errmsg, "\n")
1102+
var filenames []string
1103+
delim := "merge conflict in "
1104+
for _, l := range lines {
1105+
if idx := strings.Index(l, delim); idx > -1 {
1106+
filenames = append(filenames, l[idx+len(delim):])
1107+
}
1108+
}
1109+
return filenames
1110+
}
1111+
1112+
func parseFilesAnnexConflict(errmsg string) []string {
1113+
lines := strings.Split(errmsg, "\n")
1114+
var filenames []string
1115+
delim := ": needs merge"
1116+
for _, l := range lines {
1117+
if idx := strings.Index(l, delim); idx > -1 {
1118+
filenames = append(filenames, l[0:idx])
1119+
}
1120+
}
1121+
return filenames
1122+
}
1123+
1124+
func parseFilesOverwrite(errmsg string) []string {
1125+
lines := strings.Split(errmsg, "\n")
1126+
var filenames []string
1127+
start := false
1128+
for _, l := range lines {
1129+
if strings.Contains(l, "error: the following") || strings.Contains(l, "error: your local") {
1130+
start = true
1131+
continue
1132+
}
1133+
if strings.Contains(l, "please move or remove") || strings.Contains(l, "please commit your changes") {
1134+
break
1135+
}
1136+
if start {
1137+
filenames = append(filenames, strings.TrimSpace(l))
1138+
}
1139+
}
1140+
return filenames
1141+
1142+
}

0 commit comments

Comments
 (0)