fetcher git: Fix crash when no ID file in existing repo

This commit is contained in:
Hylke Bons 2017-03-01 19:59:44 +00:00
parent 0a7fcb1834
commit a04a4df3ad
2 changed files with 11 additions and 7 deletions

View file

@ -134,8 +134,10 @@ namespace Sparkles {
string id_path = Path.Combine (LocalPath, ".sparkleshare");
if (File.Exists (id_path))
if (File.Exists (id_path)) {
File.SetAttributes (id_path, FileAttributes.Hidden);
this.identifier = File.ReadAllText (id_path).Trim ();
}
if (!string.IsNullOrEmpty (this.identifier)) {
return this.identifier;

View file

@ -176,18 +176,19 @@ namespace Sparkles.Git {
if (IsFetchedRepoEmpty) {
File.WriteAllText (identifier_path, identifier);
File.SetAttributes (identifier_path, FileAttributes.Hidden);
// We can't do the "commit --all" shortcut because it doesn't add untracked files
var git_add = new GitCommand (TargetFolder, "add .sparkleshare");
var git_commit = new GitCommand (TargetFolder,
string.Format ("commit --message=\"{0}\" --author=\"{1}\"",
"Set up SparkleShare project",
"SparkleShare <info@sparkleshare.org>"));
// We can't do the "commit --all" shortcut because it doesn't add untracked files
git_add.StartAndWaitForExit ();
git_commit.StartAndWaitForExit ();
// These branches will be pushed later by "git push --all"
// These branches will be pushed later by "git push --all"
if (selected_storage_type == StorageType.LargeFiles) {
var git_branch = new GitCommand (TargetFolder, "branch x-sparkleshare-lfs", auth_info);
git_branch.StartAndWaitForExit ();
@ -201,9 +202,6 @@ namespace Sparkles.Git {
}
} else {
if (File.Exists (identifier_path))
identifier = File.ReadAllText (identifier_path).Trim ();
string branch = "HEAD";
string prefered_branch = "SparkleShare";
@ -218,6 +216,11 @@ namespace Sparkles.Git {
var git_checkout = new GitCommand (TargetFolder, string.Format ("checkout --quiet --force {0}", branch));
git_checkout.StartAndWaitForExit ();
if (File.Exists (identifier_path)) {
File.SetAttributes (identifier_path, FileAttributes.Hidden);
identifier = File.ReadAllText (identifier_path).Trim ();
}
}
// git-lfs may leave junk behind
@ -226,7 +229,6 @@ namespace Sparkles.Git {
if (Directory.Exists (git_lfs_tmp_path))
Directory.Delete (git_lfs_tmp_path, true);
File.SetAttributes (identifier_path, FileAttributes.Hidden);
return identifier;
}