@@ -40,9 +40,21 @@ func init() {
4040
4141func pull (args []string ) error {
4242 // Ensure a database file was given
43+ var db , defDB string
44+ var err error
4345 if len (args ) == 0 {
44- return errors .New ("No database file specified" )
46+ db , err = getDefaultDatabase ()
47+ if err != nil {
48+ return err
49+ }
50+ if db == "" {
51+ // No database name was given on the command line, and we don't have a default database selected
52+ return errors .New ("No database file specified" )
53+ }
54+ } else {
55+ db = args [0 ]
4556 }
57+
4658 // TODO: Allow giving multiple database files on the command line. Hopefully just needs turning this
4759 // TODO into a for loop
4860 if len (args ) > 1 {
@@ -59,23 +71,24 @@ func pull(args []string) error {
5971
6072 // Retrieve metadata for the database
6173 var meta metaData
62- var err error
63- db := args [0 ]
6474 meta , err = updateMetadata (db , false ) // Don't store the metadata to disk yet, in case the download fails
6575 if err != nil {
6676 return err
6777 }
6878
69- // Unless --force is specified, check whether the file has changed since the last commit, and let the user know
70- if * pullForce == false {
71- changed , err := dbChanged (db , meta )
72- if err != nil {
73- return err
74- }
75- if changed {
76- _ , err = fmt .Fprintf (fOut , "%s has been changed since the last commit. Use --force if you " +
77- "really want to overwrite it\n " , db )
78- return err
79+ // If the database file already exists locally, check whether the file has changed since the last commit, and let
80+ // the user know. The --force option on the command line overrides this
81+ if _ , err = os .Stat (db ); err == nil {
82+ if * pullForce == false {
83+ changed , err := dbChanged (db , meta )
84+ if err != nil {
85+ return err
86+ }
87+ if changed {
88+ _ , err = fmt .Fprintf (fOut , "%s has been changed since the last commit. Use --force if you " +
89+ "really want to overwrite it\n " , db )
90+ return err
91+ }
7992 }
8093 }
8194
@@ -182,6 +195,18 @@ func pull(args []string) error {
182195 if err != nil {
183196 return err
184197 }
198+
199+ // If a default database isn't already selected, we use this one as the default
200+ defDB , err = getDefaultDatabase ()
201+ if err != nil {
202+ return err
203+ }
204+ if defDB == "" {
205+ err = saveDefaultDatabase (db )
206+ if err != nil {
207+ return err
208+ }
209+ }
185210 return nil
186211 }
187212 }
@@ -254,6 +279,18 @@ func pull(args []string) error {
254279 return err
255280 }
256281
282+ // If a default database isn't already selected, we use this one as the default
283+ defDB , err = getDefaultDatabase ()
284+ if err != nil {
285+ return err
286+ }
287+ if defDB == "" {
288+ err = saveDefaultDatabase (db )
289+ if err != nil {
290+ return err
291+ }
292+ }
293+
257294 // Display success message to the user
258295 comID := resp .Header .Get ("Commit-Id" )
259296 _ , err = fmt .Fprintln (fOut , "Downloaded complete" )
0 commit comments