diff --git a/cmd/repo_create.go b/cmd/repo_create.go index e04e6b90..9074a8f6 100644 --- a/cmd/repo_create.go +++ b/cmd/repo_create.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "github.com/smira/aptly/deb" "github.com/smira/commander" "github.com/smira/flag" @@ -9,7 +10,7 @@ import ( func aptlyRepoCreate(cmd *commander.Command, args []string) error { var err error - if len(args) != 1 { + if !(len(args) == 1 || (len(args) == 4 && args[1] == "from" && args[2] == "snapshot")) { cmd.Usage() return commander.ErrCommandError } @@ -26,6 +27,22 @@ func aptlyRepoCreate(cmd *commander.Command, args []string) error { } } + if len(args) == 4 { + var snapshot *deb.Snapshot + + snapshot, err = context.CollectionFactory().SnapshotCollection().ByName(args[3]) + if err != nil { + return fmt.Errorf("unable to load source snapshot: %s", err) + } + + err = context.CollectionFactory().SnapshotCollection().LoadComplete(snapshot) + if err != nil { + return fmt.Errorf("unable to load source snapshot: %s", err) + } + + repo.UpdateRefList(snapshot.RefList()) + } + err = context.CollectionFactory().LocalRepoCollection().Add(repo) if err != nil { return fmt.Errorf("unable to add local repo: %s", err) @@ -38,16 +55,21 @@ func aptlyRepoCreate(cmd *commander.Command, args []string) error { func makeCmdRepoCreate() *commander.Command { cmd := &commander.Command{ Run: aptlyRepoCreate, - UsageLine: "create ", + UsageLine: "create [ from snapshot ]", Short: "create local repository", Long: ` Create local package repository. Repository would be empty when created, packages could be added from files, copied or moved from another local repository or imported from the mirror. +If local package repository is created from snapshot, repo initial +contents are copied from snapsot contents. + Example: $ aptly repo create testing + + $ aptly repo create mysql35 from snapshot mysql-35-2017 `, Flag: *flag.NewFlagSet("aptly-repo-create", flag.ExitOnError), } diff --git a/man/aptly.1 b/man/aptly.1 index df488671..a3bb60f2 100644 --- a/man/aptly.1 +++ b/man/aptly.1 @@ -633,18 +633,24 @@ don\(cqt copy, just show what would be copied follow dependencies when processing package\-spec . .SH "CREATE LOCAL REPOSITORY" -\fBaptly\fR \fBrepo\fR \fBcreate\fR \fIname\fR +\fBaptly\fR \fBrepo\fR \fBcreate\fR \fIname\fR [ \fBfrom\fR \fBsnapshot\fR \fIsnapshot\fR ] . .P Create local package repository\. Repository would be empty when created, packages could be added from files, copied or moved from another local repository or imported from the mirror\. . .P +If local package repository is created from snapshot, repo initial contents are copied from snapsot contents\. +. +.P Example: . .P $ aptly repo create testing . .P +$ aptly repo create mysql35 from snapshot mysql\-35\-2017 +. +.P Options: . .TP diff --git a/system/t09_repo/CreateRepo7Test_gold b/system/t09_repo/CreateRepo7Test_gold new file mode 100644 index 00000000..bea2f75a --- /dev/null +++ b/system/t09_repo/CreateRepo7Test_gold @@ -0,0 +1,3 @@ + +Local repo [repo2] successfully added. +You can run 'aptly repo add repo2 ...' to add packages to repository. diff --git a/system/t09_repo/CreateRepo7Test_repo_show b/system/t09_repo/CreateRepo7Test_repo_show new file mode 100644 index 00000000..43ae0cc3 --- /dev/null +++ b/system/t09_repo/CreateRepo7Test_repo_show @@ -0,0 +1,9 @@ +Name: repo2 +Comment: +Default Distribution: +Default Component: main +Number of packages: 3 +Packages: + libboost-program-options-dev_1.49.0.1_i386 + pyspi_0.6.1-1.3_source + pyspi_0.6.1-1.4_source diff --git a/system/t09_repo/CreateRepo8Test_gold b/system/t09_repo/CreateRepo8Test_gold new file mode 100644 index 00000000..c12f7262 --- /dev/null +++ b/system/t09_repo/CreateRepo8Test_gold @@ -0,0 +1 @@ +ERROR: unable to load source snapshot: snapshot with name snap-missing not found diff --git a/system/t09_repo/create.py b/system/t09_repo/create.py index 3112dc58..dbb87409 100644 --- a/system/t09_repo/create.py +++ b/system/t09_repo/create.py @@ -63,3 +63,27 @@ class CreateRepo6Test(BaseTest): runCmd = "aptly repo create -uploaders-file=${changes}/uploaders-not-found.json repo6" expectedCode = 1 outputMatchPrepare = changesRemove + + +class CreateRepo7Test(BaseTest): + """ + create local repo: from snapshot + """ + fixtureCmds = [ + "aptly repo create repo1", + "aptly repo add repo1 ${files}", + "aptly snapshot create snap1 from repo repo1", + ] + runCmd = "aptly repo create repo2 from snapshot snap1" + + def check(self): + self.check_output() + self.check_cmd_output("aptly repo show -with-packages repo2", "repo_show") + + +class CreateRepo8Test(BaseTest): + """ + create local repo: from missing snapshot + """ + runCmd = "aptly repo create repo2 from snapshot snap-missing" + expectedCode = 1