Skip to content

Commit a913105

Browse files
authored
Fix bug introduced in previous commit (#83)
1 parent 1b5f94d commit a913105

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

backup.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,18 @@ func setupBackupDir(backupDir, service, githostURL *string) string {
7575
var gitHost, backupPath string
7676
var err error
7777

78-
if githostURL != nil {
78+
if len(*githostURL) != 0 {
7979
u, err := url.Parse(*githostURL)
8080
if err != nil {
8181
panic(err)
8282
}
8383
gitHost = u.Host
8484
} else {
8585
gitHost = knownServices[*service]
86+
log.Println("knownservices", gitHost)
8687
}
8788

88-
if backupDir == nil {
89+
if len(*backupDir) == 0 {
8990
homeDir, err := homedir.Dir()
9091
if err == nil {
9192
backupPath = path.Join(homeDir, ".gitbackup", gitHost)
@@ -95,9 +96,10 @@ func setupBackupDir(backupDir, service, githostURL *string) string {
9596
} else {
9697
backupPath = path.Join(*backupDir, gitHost)
9798
}
99+
98100
err = createBackupRootDirIfRequired(backupPath)
99101
if err != nil {
100-
log.Fatal(err)
102+
log.Fatalf("Error creating backup directory: %s %v", backupPath, err)
101103
}
102104
return backupPath
103105
}

backup_test.go

+19-19
Original file line numberDiff line numberDiff line change
@@ -158,64 +158,64 @@ func TestSetupBackupDir(t *testing.T) {
158158
serviceGitlabCustomUrl := "https://company.gitlab.com"
159159

160160
var testConfigs = []struct {
161-
backupRootDir *string
161+
backupRootDir string
162162
gitService string
163-
gitServiceUrl *string
163+
gitServiceUrl string
164164
wantBackupPath string
165165
}{
166166
{
167-
nil,
167+
"",
168168
"github",
169-
nil,
169+
"",
170170
"/home/fakeuser/.gitbackup/github.com",
171171
},
172172
{
173-
&backupRoot,
173+
backupRoot,
174174
"github",
175-
nil,
175+
"",
176176
"/my/backup/root/github.com",
177177
},
178178
{
179-
&backupRoot,
179+
backupRoot,
180180
"github",
181-
&serviceGithubCustomUrl,
181+
serviceGithubCustomUrl,
182182
"/my/backup/root/company.github.com",
183183
},
184184
{
185-
nil,
185+
"",
186186
"gitlab",
187-
nil,
187+
"",
188188
"/home/fakeuser/.gitbackup/gitlab.com",
189189
},
190190

191191
{
192-
&backupRoot,
192+
backupRoot,
193193
"gitlab",
194-
nil,
194+
"",
195195
"/my/backup/root/gitlab.com",
196196
},
197197
{
198-
&backupRoot,
198+
backupRoot,
199199
"gitlab",
200-
&serviceGitlabCustomUrl,
200+
serviceGitlabCustomUrl,
201201
"/my/backup/root/company.gitlab.com",
202202
},
203203
{
204-
&backupRoot,
204+
backupRoot,
205205
"bitbucket",
206-
nil,
206+
"",
207207
"/my/backup/root/bitbucket.org",
208208
},
209209
{
210-
nil,
210+
"",
211211
"bitbucket",
212-
nil,
212+
"",
213213
"/home/fakeuser/.gitbackup/bitbucket.org",
214214
},
215215
}
216216

217217
for _, tc := range testConfigs {
218-
backupdir := setupBackupDir(tc.backupRootDir, &tc.gitService, tc.gitServiceUrl)
218+
backupdir := setupBackupDir(&tc.backupRootDir, &tc.gitService, &tc.gitServiceUrl)
219219
if backupdir != tc.wantBackupPath {
220220
t.Errorf("Expected %s, Got %s", tc.wantBackupPath, backupdir)
221221
}

0 commit comments

Comments
 (0)