@@ -102,10 +102,12 @@ func downloadFile(filename, url string) error {
102
102
103
103
// upstream describes the upstream repo we are about to package.
104
104
type upstream struct {
105
+ rr * vcs.RepoRoot
105
106
tarPath string // path to the downloaded or generated orig tarball tempfile
106
107
compression string // compression method, either "gz" or "xz"
107
108
version string // Debian package upstream version number, e.g. 0.0~git20180204.1d24609
108
109
commitIsh string // commit-ish corresponding to upstream version to be packaged
110
+ remote string // git remote, set to short hostname if upstream git history is included
109
111
firstMain string // import path of the first main package within repo, if any
110
112
vendorDirs []string // all vendor sub directories, relative to the repo directory
111
113
repoDeps []string // the repository paths of all dependencies (e.g. github.com/zyedidia/glob)
@@ -123,6 +125,7 @@ func (u *upstream) get(gopath, repo, rev string) error {
123
125
if err != nil {
124
126
return err
125
127
}
128
+ u .rr = rr
126
129
dir := filepath .Join (gopath , "src" , rr .Root )
127
130
if rev != "" {
128
131
return rr .VCS .CreateAtRev (dir , rr .Repo , rev )
@@ -371,7 +374,8 @@ func runGitCommandIn(dir string, arg ...string) error {
371
374
return cmd .Run ()
372
375
}
373
376
374
- func createGitRepository (debsrc , gopkg , orig string , dep14 , pristineTar bool ) (string , error ) {
377
+ func createGitRepository (debsrc , gopkg , orig string , u * upstream ,
378
+ includeUpstreamHistory , allowUnknownHoster , dep14 , pristineTar bool ) (string , error ) {
375
379
wd , err := os .Getwd ()
376
380
if err != nil {
377
381
return "" , err
@@ -413,6 +417,21 @@ func createGitRepository(debsrc, gopkg, orig string, dep14, pristineTar bool) (s
413
417
return dir , err
414
418
}
415
419
420
+ if includeUpstreamHistory {
421
+ u .remote , err = shortHostName (gopkg , allowUnknownHoster )
422
+ if err != nil {
423
+ return dir , fmt .Errorf ("Unable to fetch upstream history: %q" , err )
424
+ }
425
+ log .Printf ("Adding %q as remote %q\n " , u .rr .Repo , u .remote )
426
+ if err := runGitCommandIn (dir , "remote" , "add" , u .remote , u .rr .Repo ); err != nil {
427
+ return dir , err
428
+ }
429
+ log .Printf ("Running \" git fetch %s\" \n " , u .remote )
430
+ if err := runGitCommandIn (dir , "fetch" , u .remote ); err != nil {
431
+ return dir , err
432
+ }
433
+ }
434
+
416
435
// Import upstream orig tarball
417
436
418
437
arg := []string {"import-orig" , "--no-interactive" }
@@ -422,6 +441,9 @@ func createGitRepository(debsrc, gopkg, orig string, dep14, pristineTar bool) (s
422
441
if pristineTar {
423
442
arg = append (arg , "--pristine-tar" )
424
443
}
444
+ if includeUpstreamHistory {
445
+ arg = append (arg , "--upstream-vcs-tag=" + u .commitIsh )
446
+ }
425
447
arg = append (arg , filepath .Join (wd , orig ))
426
448
cmd := exec .Command ("gbp" , arg ... )
427
449
cmd .Dir = dir
@@ -530,7 +552,7 @@ func shortHostName(gopkg string, allowUnknownHoster bool) (host string, err erro
530
552
return host , err
531
553
}
532
554
533
- // debianNameFromGopkg converts a Go package repo path to a Debian package name,
555
+ // debianNameFromGopkg maps a Go package repo path to a Debian package name,
534
556
// e.g. "golang.org/x/text" → "golang-golang-x-text".
535
557
// This follows https://fedoraproject.org/wiki/PackagingDrafts/Go#Package_Names
536
558
func debianNameFromGopkg (gopkg string , t packageType , allowUnknownHoster bool ) string {
@@ -720,6 +742,13 @@ func execMake(args []string, usage func()) {
720
742
` * "library+program" (aliases: "lib+prog", "l+p", "both")` + "\n " +
721
743
` * "program+library" (aliases: "prog+lib", "p+l", "combined")` )
722
744
745
+ var includeUpstreamHistory bool
746
+ fs .BoolVar (& includeUpstreamHistory ,
747
+ "upstream-git-history" ,
748
+ true ,
749
+ "Include upstream git history (Debian pkg-go team new workflow).\n " +
750
+ "New in dh-make-golang 0.3.0, currently experimental." )
751
+
723
752
fs .StringVar (& wrapAndSort ,
724
753
"wrap-and-sort" ,
725
754
"a" ,
@@ -862,7 +891,7 @@ func execMake(args []string, usage func()) {
862
891
863
892
debversion := u .version + "-1"
864
893
865
- dir , err := createGitRepository (debsrc , gopkg , orig , dep14 , pristineTar )
894
+ dir , err := createGitRepository (debsrc , gopkg , orig , u , includeUpstreamHistory , allowUnknownHoster , dep14 , pristineTar )
866
895
if err != nil {
867
896
log .Fatalf ("Could not create git repository: %v\n " , err )
868
897
}
@@ -927,4 +956,18 @@ func execMake(args []string, usage func()) {
927
956
fmt .
Printf (
" git remote set-url origin [email protected] :go-team/packages/%s.git\n " ,
debsrc )
928
957
fmt .Printf (" gbp push\n " )
929
958
fmt .Printf ("\n " )
959
+
960
+ if includeUpstreamHistory {
961
+ fmt .Printf ("NOTE: Full upstream git history has been included as per pkg-go team's\n " )
962
+ fmt .Printf (" new workflow. This feature is new and somewhat experimental,\n " )
963
+ fmt .Printf (" and all feedback are welcome!\n " )
964
+ fmt .Printf (" (For old behavior, use --include-upstream-history=false)\n " )
965
+ fmt .Printf ("\n " )
966
+ fmt .Printf ("The upstream git history is being tracked with the remote named %q.\n " , u .remote )
967
+ fmt .Printf ("To upgrade to the latest upstream version, you may use something like:\n " )
968
+ fmt .Printf (" git fetch %-15v # note the latest tag or commit-ish\n " , u .remote )
969
+ fmt .Printf (" uscan --report-status # check we get the same tag or commit-ish\n " )
970
+ fmt .Printf (" gbp import-orig --sign-tags --uscan --upstream-vcs-tag=<commit-ish>\n " )
971
+ fmt .Printf ("\n " )
972
+ }
930
973
}
0 commit comments