repo_editor.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. // Copyright 2016 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package database
  5. import (
  6. "fmt"
  7. "io"
  8. "mime/multipart"
  9. "os"
  10. "os/exec"
  11. "path"
  12. "path/filepath"
  13. "strings"
  14. "time"
  15. "github.com/pkg/errors"
  16. gouuid "github.com/satori/go.uuid"
  17. "github.com/unknwon/com"
  18. "github.com/gogs/git-module"
  19. "gogs.io/gogs/internal/conf"
  20. "gogs.io/gogs/internal/cryptoutil"
  21. dberrors "gogs.io/gogs/internal/database/errors"
  22. "gogs.io/gogs/internal/gitutil"
  23. "gogs.io/gogs/internal/osutil"
  24. "gogs.io/gogs/internal/pathutil"
  25. "gogs.io/gogs/internal/process"
  26. "gogs.io/gogs/internal/tool"
  27. )
  28. const (
  29. ENV_AUTH_USER_ID = "GOGS_AUTH_USER_ID"
  30. ENV_AUTH_USER_NAME = "GOGS_AUTH_USER_NAME"
  31. ENV_AUTH_USER_EMAIL = "GOGS_AUTH_USER_EMAIL"
  32. ENV_REPO_OWNER_NAME = "GOGS_REPO_OWNER_NAME"
  33. ENV_REPO_OWNER_SALT_MD5 = "GOGS_REPO_OWNER_SALT_MD5"
  34. ENV_REPO_ID = "GOGS_REPO_ID"
  35. ENV_REPO_NAME = "GOGS_REPO_NAME"
  36. ENV_REPO_CUSTOM_HOOKS_PATH = "GOGS_REPO_CUSTOM_HOOKS_PATH"
  37. )
  38. type ComposeHookEnvsOptions struct {
  39. AuthUser *User
  40. OwnerName string
  41. OwnerSalt string
  42. RepoID int64
  43. RepoName string
  44. RepoPath string
  45. }
  46. func ComposeHookEnvs(opts ComposeHookEnvsOptions) []string {
  47. envs := []string{
  48. "SSH_ORIGINAL_COMMAND=1",
  49. ENV_AUTH_USER_ID + "=" + com.ToStr(opts.AuthUser.ID),
  50. ENV_AUTH_USER_NAME + "=" + opts.AuthUser.Name,
  51. ENV_AUTH_USER_EMAIL + "=" + opts.AuthUser.Email,
  52. ENV_REPO_OWNER_NAME + "=" + opts.OwnerName,
  53. ENV_REPO_OWNER_SALT_MD5 + "=" + cryptoutil.MD5(opts.OwnerSalt),
  54. ENV_REPO_ID + "=" + com.ToStr(opts.RepoID),
  55. ENV_REPO_NAME + "=" + opts.RepoName,
  56. ENV_REPO_CUSTOM_HOOKS_PATH + "=" + filepath.Join(opts.RepoPath, "custom_hooks"),
  57. }
  58. return envs
  59. }
  60. // ___________ .___.__ __ ___________.__.__
  61. // \_ _____/ __| _/|__|/ |_ \_ _____/|__| | ____
  62. // | __)_ / __ | | \ __\ | __) | | | _/ __ \
  63. // | \/ /_/ | | || | | \ | | |_\ ___/
  64. // /_______ /\____ | |__||__| \___ / |__|____/\___ >
  65. // \/ \/ \/ \/
  66. // discardLocalRepoBranchChanges discards local commits/changes of
  67. // given branch to make sure it is even to remote branch.
  68. func discardLocalRepoBranchChanges(localPath, branch string) error {
  69. if !com.IsExist(localPath) {
  70. return nil
  71. }
  72. // No need to check if nothing in the repository.
  73. if !git.RepoHasBranch(localPath, branch) {
  74. return nil
  75. }
  76. rev := "origin/" + branch
  77. if err := git.Reset(localPath, rev, git.ResetOptions{Hard: true}); err != nil {
  78. return fmt.Errorf("reset [revision: %s]: %v", rev, err)
  79. }
  80. return nil
  81. }
  82. func (repo *Repository) DiscardLocalRepoBranchChanges(branch string) error {
  83. return discardLocalRepoBranchChanges(repo.LocalCopyPath(), branch)
  84. }
  85. // CheckoutNewBranch checks out to a new branch from the a branch name.
  86. func (repo *Repository) CheckoutNewBranch(oldBranch, newBranch string) error {
  87. if err := git.Checkout(repo.LocalCopyPath(), newBranch, git.CheckoutOptions{
  88. BaseBranch: oldBranch,
  89. Timeout: time.Duration(conf.Git.Timeout.Pull) * time.Second,
  90. }); err != nil {
  91. return fmt.Errorf("checkout [base: %s, new: %s]: %v", oldBranch, newBranch, err)
  92. }
  93. return nil
  94. }
  95. type UpdateRepoFileOptions struct {
  96. OldBranch string
  97. NewBranch string
  98. OldTreeName string
  99. NewTreeName string
  100. Message string
  101. Content string
  102. IsNewFile bool
  103. }
  104. // UpdateRepoFile adds or updates a file in repository.
  105. func (repo *Repository) UpdateRepoFile(doer *User, opts UpdateRepoFileOptions) (err error) {
  106. // 🚨 SECURITY: Prevent uploading files into the ".git" directory.
  107. if isRepositoryGitPath(opts.NewTreeName) {
  108. return errors.Errorf("bad tree path %q", opts.NewTreeName)
  109. }
  110. repoWorkingPool.CheckIn(com.ToStr(repo.ID))
  111. defer repoWorkingPool.CheckOut(com.ToStr(repo.ID))
  112. if err = repo.DiscardLocalRepoBranchChanges(opts.OldBranch); err != nil {
  113. return fmt.Errorf("discard local repo branch[%s] changes: %v", opts.OldBranch, err)
  114. } else if err = repo.UpdateLocalCopyBranch(opts.OldBranch); err != nil {
  115. return fmt.Errorf("update local copy branch[%s]: %v", opts.OldBranch, err)
  116. }
  117. repoPath := repo.RepoPath()
  118. localPath := repo.LocalCopyPath()
  119. if opts.OldBranch != opts.NewBranch {
  120. // Directly return error if new branch already exists in the server
  121. if git.RepoHasBranch(repoPath, opts.NewBranch) {
  122. return dberrors.BranchAlreadyExists{Name: opts.NewBranch}
  123. }
  124. // Otherwise, delete branch from local copy in case out of sync
  125. if git.RepoHasBranch(localPath, opts.NewBranch) {
  126. if err = git.DeleteBranch(localPath, opts.NewBranch, git.DeleteBranchOptions{
  127. Force: true,
  128. }); err != nil {
  129. return fmt.Errorf("delete branch %q: %v", opts.NewBranch, err)
  130. }
  131. }
  132. if err := repo.CheckoutNewBranch(opts.OldBranch, opts.NewBranch); err != nil {
  133. return fmt.Errorf("checkout new branch[%s] from old branch[%s]: %v", opts.NewBranch, opts.OldBranch, err)
  134. }
  135. }
  136. oldFilePath := path.Join(localPath, opts.OldTreeName)
  137. filePath := path.Join(localPath, opts.NewTreeName)
  138. if err = os.MkdirAll(path.Dir(filePath), os.ModePerm); err != nil {
  139. return err
  140. }
  141. // If it's meant to be a new file, make sure it doesn't exist.
  142. if opts.IsNewFile {
  143. if com.IsExist(filePath) {
  144. return ErrRepoFileAlreadyExist{filePath}
  145. }
  146. }
  147. // Ignore move step if it's a new file under a directory.
  148. // Otherwise, move the file when name changed.
  149. if osutil.IsFile(oldFilePath) && opts.OldTreeName != opts.NewTreeName {
  150. if err = git.Move(localPath, opts.OldTreeName, opts.NewTreeName); err != nil {
  151. return fmt.Errorf("git mv %q %q: %v", opts.OldTreeName, opts.NewTreeName, err)
  152. }
  153. }
  154. if err = os.WriteFile(filePath, []byte(opts.Content), 0600); err != nil {
  155. return fmt.Errorf("write file: %v", err)
  156. }
  157. if err = git.Add(localPath, git.AddOptions{All: true}); err != nil {
  158. return fmt.Errorf("git add --all: %v", err)
  159. }
  160. err = git.CreateCommit(
  161. localPath,
  162. &git.Signature{
  163. Name: doer.DisplayName(),
  164. Email: doer.Email,
  165. When: time.Now(),
  166. },
  167. opts.Message,
  168. )
  169. if err != nil {
  170. return fmt.Errorf("commit changes on %q: %v", localPath, err)
  171. }
  172. err = git.Push(localPath, "origin", opts.NewBranch,
  173. git.PushOptions{
  174. CommandOptions: git.CommandOptions{
  175. Envs: ComposeHookEnvs(ComposeHookEnvsOptions{
  176. AuthUser: doer,
  177. OwnerName: repo.MustOwner().Name,
  178. OwnerSalt: repo.MustOwner().Salt,
  179. RepoID: repo.ID,
  180. RepoName: repo.Name,
  181. RepoPath: repo.RepoPath(),
  182. }),
  183. },
  184. },
  185. )
  186. if err != nil {
  187. return fmt.Errorf("git push origin %s: %v", opts.NewBranch, err)
  188. }
  189. return nil
  190. }
  191. // GetDiffPreview produces and returns diff result of a file which is not yet committed.
  192. func (repo *Repository) GetDiffPreview(branch, treePath, content string) (diff *gitutil.Diff, err error) {
  193. // 🚨 SECURITY: Prevent uploading files into the ".git" directory.
  194. if isRepositoryGitPath(treePath) {
  195. return nil, errors.Errorf("bad tree path %q", treePath)
  196. }
  197. repoWorkingPool.CheckIn(com.ToStr(repo.ID))
  198. defer repoWorkingPool.CheckOut(com.ToStr(repo.ID))
  199. if err = repo.DiscardLocalRepoBranchChanges(branch); err != nil {
  200. return nil, fmt.Errorf("discard local repo branch[%s] changes: %v", branch, err)
  201. } else if err = repo.UpdateLocalCopyBranch(branch); err != nil {
  202. return nil, fmt.Errorf("update local copy branch[%s]: %v", branch, err)
  203. }
  204. localPath := repo.LocalCopyPath()
  205. filePath := path.Join(localPath, treePath)
  206. if err = os.MkdirAll(filepath.Dir(filePath), os.ModePerm); err != nil {
  207. return nil, err
  208. }
  209. if err = os.WriteFile(filePath, []byte(content), 0600); err != nil {
  210. return nil, fmt.Errorf("write file: %v", err)
  211. }
  212. // 🚨 SECURITY: Prevent including unintended options in the path to the git command.
  213. cmd := exec.Command("git", "diff", "--end-of-options", treePath)
  214. cmd.Dir = localPath
  215. cmd.Stderr = os.Stderr
  216. stdout, err := cmd.StdoutPipe()
  217. if err != nil {
  218. return nil, fmt.Errorf("get stdout pipe: %v", err)
  219. }
  220. if err = cmd.Start(); err != nil {
  221. return nil, fmt.Errorf("start: %v", err)
  222. }
  223. pid := process.Add(fmt.Sprintf("GetDiffPreview [repo_path: %s]", repo.RepoPath()), cmd)
  224. defer process.Remove(pid)
  225. diff, err = gitutil.ParseDiff(stdout, conf.Git.MaxDiffFiles, conf.Git.MaxDiffLines, conf.Git.MaxDiffLineChars)
  226. if err != nil {
  227. return nil, fmt.Errorf("parse diff: %v", err)
  228. }
  229. if err = cmd.Wait(); err != nil {
  230. return nil, fmt.Errorf("wait: %v", err)
  231. }
  232. return diff, nil
  233. }
  234. // ________ .__ __ ___________.__.__
  235. // \______ \ ____ | | _____/ |_ ____ \_ _____/|__| | ____
  236. // | | \_/ __ \| | _/ __ \ __\/ __ \ | __) | | | _/ __ \
  237. // | ` \ ___/| |_\ ___/| | \ ___/ | \ | | |_\ ___/
  238. // /_______ /\___ >____/\___ >__| \___ > \___ / |__|____/\___ >
  239. // \/ \/ \/ \/ \/ \/
  240. //
  241. type DeleteRepoFileOptions struct {
  242. LastCommitID string
  243. OldBranch string
  244. NewBranch string
  245. TreePath string
  246. Message string
  247. }
  248. func (repo *Repository) DeleteRepoFile(doer *User, opts DeleteRepoFileOptions) (err error) {
  249. // 🚨 SECURITY: Prevent uploading files into the ".git" directory.
  250. if isRepositoryGitPath(opts.TreePath) {
  251. return errors.Errorf("bad tree path %q", opts.TreePath)
  252. }
  253. repoWorkingPool.CheckIn(com.ToStr(repo.ID))
  254. defer repoWorkingPool.CheckOut(com.ToStr(repo.ID))
  255. if err = repo.DiscardLocalRepoBranchChanges(opts.OldBranch); err != nil {
  256. return fmt.Errorf("discard local repo branch[%s] changes: %v", opts.OldBranch, err)
  257. } else if err = repo.UpdateLocalCopyBranch(opts.OldBranch); err != nil {
  258. return fmt.Errorf("update local copy branch[%s]: %v", opts.OldBranch, err)
  259. }
  260. if opts.OldBranch != opts.NewBranch {
  261. if err := repo.CheckoutNewBranch(opts.OldBranch, opts.NewBranch); err != nil {
  262. return fmt.Errorf("checkout new branch[%s] from old branch[%s]: %v", opts.NewBranch, opts.OldBranch, err)
  263. }
  264. }
  265. localPath := repo.LocalCopyPath()
  266. if err = os.Remove(path.Join(localPath, opts.TreePath)); err != nil {
  267. return fmt.Errorf("remove file %q: %v", opts.TreePath, err)
  268. }
  269. if err = git.Add(localPath, git.AddOptions{All: true}); err != nil {
  270. return fmt.Errorf("git add --all: %v", err)
  271. }
  272. err = git.CreateCommit(
  273. localPath,
  274. &git.Signature{
  275. Name: doer.DisplayName(),
  276. Email: doer.Email,
  277. When: time.Now(),
  278. },
  279. opts.Message,
  280. )
  281. if err != nil {
  282. return fmt.Errorf("commit changes to %q: %v", localPath, err)
  283. }
  284. err = git.Push(localPath, "origin", opts.NewBranch,
  285. git.PushOptions{
  286. CommandOptions: git.CommandOptions{
  287. Envs: ComposeHookEnvs(ComposeHookEnvsOptions{
  288. AuthUser: doer,
  289. OwnerName: repo.MustOwner().Name,
  290. OwnerSalt: repo.MustOwner().Salt,
  291. RepoID: repo.ID,
  292. RepoName: repo.Name,
  293. RepoPath: repo.RepoPath(),
  294. }),
  295. },
  296. },
  297. )
  298. if err != nil {
  299. return fmt.Errorf("git push origin %s: %v", opts.NewBranch, err)
  300. }
  301. return nil
  302. }
  303. // ____ ___ .__ .___ ___________.___.__
  304. // | | \______ | | _________ __| _/ \_ _____/| | | ____ ______
  305. // | | /\____ \| | / _ \__ \ / __ | | __) | | | _/ __ \ / ___/
  306. // | | / | |_> > |_( <_> ) __ \_/ /_/ | | \ | | |_\ ___/ \___ \
  307. // |______/ | __/|____/\____(____ /\____ | \___ / |___|____/\___ >____ >
  308. // |__| \/ \/ \/ \/ \/
  309. //
  310. // Upload represent a uploaded file to a repo to be deleted when moved
  311. type Upload struct {
  312. ID int64
  313. UUID string `xorm:"uuid UNIQUE"`
  314. Name string
  315. }
  316. // UploadLocalPath returns where uploads is stored in local file system based on given UUID.
  317. func UploadLocalPath(uuid string) string {
  318. return path.Join(conf.Repository.Upload.TempPath, uuid[0:1], uuid[1:2], uuid)
  319. }
  320. // LocalPath returns where uploads are temporarily stored in local file system.
  321. func (upload *Upload) LocalPath() string {
  322. return UploadLocalPath(upload.UUID)
  323. }
  324. // NewUpload creates a new upload object.
  325. func NewUpload(name string, buf []byte, file multipart.File) (_ *Upload, err error) {
  326. if tool.IsMaliciousPath(name) {
  327. return nil, fmt.Errorf("malicious path detected: %s", name)
  328. }
  329. upload := &Upload{
  330. UUID: gouuid.NewV4().String(),
  331. Name: name,
  332. }
  333. localPath := upload.LocalPath()
  334. if err = os.MkdirAll(path.Dir(localPath), os.ModePerm); err != nil {
  335. return nil, fmt.Errorf("mkdir all: %v", err)
  336. }
  337. fw, err := os.Create(localPath)
  338. if err != nil {
  339. return nil, fmt.Errorf("create: %v", err)
  340. }
  341. defer func() { _ = fw.Close() }()
  342. if _, err = fw.Write(buf); err != nil {
  343. return nil, fmt.Errorf("write: %v", err)
  344. } else if _, err = io.Copy(fw, file); err != nil {
  345. return nil, fmt.Errorf("copy: %v", err)
  346. }
  347. if _, err := x.Insert(upload); err != nil {
  348. return nil, err
  349. }
  350. return upload, nil
  351. }
  352. func GetUploadByUUID(uuid string) (*Upload, error) {
  353. upload := &Upload{UUID: uuid}
  354. has, err := x.Get(upload)
  355. if err != nil {
  356. return nil, err
  357. } else if !has {
  358. return nil, ErrUploadNotExist{0, uuid}
  359. }
  360. return upload, nil
  361. }
  362. func GetUploadsByUUIDs(uuids []string) ([]*Upload, error) {
  363. if len(uuids) == 0 {
  364. return []*Upload{}, nil
  365. }
  366. // Silently drop invalid uuids.
  367. uploads := make([]*Upload, 0, len(uuids))
  368. return uploads, x.In("uuid", uuids).Find(&uploads)
  369. }
  370. func DeleteUploads(uploads ...*Upload) (err error) {
  371. if len(uploads) == 0 {
  372. return nil
  373. }
  374. sess := x.NewSession()
  375. defer sess.Close()
  376. if err = sess.Begin(); err != nil {
  377. return err
  378. }
  379. ids := make([]int64, len(uploads))
  380. for i := 0; i < len(uploads); i++ {
  381. ids[i] = uploads[i].ID
  382. }
  383. if _, err = sess.In("id", ids).Delete(new(Upload)); err != nil {
  384. return fmt.Errorf("delete uploads: %v", err)
  385. }
  386. for _, upload := range uploads {
  387. localPath := upload.LocalPath()
  388. if !osutil.IsFile(localPath) {
  389. continue
  390. }
  391. if err := os.Remove(localPath); err != nil {
  392. return fmt.Errorf("remove upload: %v", err)
  393. }
  394. }
  395. return sess.Commit()
  396. }
  397. func DeleteUpload(u *Upload) error {
  398. return DeleteUploads(u)
  399. }
  400. func DeleteUploadByUUID(uuid string) error {
  401. upload, err := GetUploadByUUID(uuid)
  402. if err != nil {
  403. if IsErrUploadNotExist(err) {
  404. return nil
  405. }
  406. return fmt.Errorf("get upload by UUID[%s]: %v", uuid, err)
  407. }
  408. if err := DeleteUpload(upload); err != nil {
  409. return fmt.Errorf("delete upload: %v", err)
  410. }
  411. return nil
  412. }
  413. type UploadRepoFileOptions struct {
  414. LastCommitID string
  415. OldBranch string
  416. NewBranch string
  417. TreePath string
  418. Message string
  419. Files []string // In UUID format
  420. }
  421. // isRepositoryGitPath returns true if given path is or resides inside ".git"
  422. // path of the repository.
  423. //
  424. // TODO(unknwon): Move to repoutil during refactoring for this file.
  425. func isRepositoryGitPath(path string) bool {
  426. path = strings.ToLower(path)
  427. return strings.HasSuffix(path, ".git") ||
  428. strings.Contains(path, ".git/") ||
  429. strings.Contains(path, `.git\`) ||
  430. // Windows treats ".git." the same as ".git"
  431. strings.HasSuffix(path, ".git.") ||
  432. strings.Contains(path, ".git./") ||
  433. strings.Contains(path, `.git.\`)
  434. }
  435. func (repo *Repository) UploadRepoFiles(doer *User, opts UploadRepoFileOptions) error {
  436. if len(opts.Files) == 0 {
  437. return nil
  438. }
  439. // 🚨 SECURITY: Prevent uploading files into the ".git" directory.
  440. if isRepositoryGitPath(opts.TreePath) {
  441. return errors.Errorf("bad tree path %q", opts.TreePath)
  442. }
  443. uploads, err := GetUploadsByUUIDs(opts.Files)
  444. if err != nil {
  445. return fmt.Errorf("get uploads by UUIDs[%v]: %v", opts.Files, err)
  446. }
  447. repoWorkingPool.CheckIn(com.ToStr(repo.ID))
  448. defer repoWorkingPool.CheckOut(com.ToStr(repo.ID))
  449. if err = repo.DiscardLocalRepoBranchChanges(opts.OldBranch); err != nil {
  450. return fmt.Errorf("discard local repo branch[%s] changes: %v", opts.OldBranch, err)
  451. } else if err = repo.UpdateLocalCopyBranch(opts.OldBranch); err != nil {
  452. return fmt.Errorf("update local copy branch[%s]: %v", opts.OldBranch, err)
  453. }
  454. if opts.OldBranch != opts.NewBranch {
  455. if err = repo.CheckoutNewBranch(opts.OldBranch, opts.NewBranch); err != nil {
  456. return fmt.Errorf("checkout new branch[%s] from old branch[%s]: %v", opts.NewBranch, opts.OldBranch, err)
  457. }
  458. }
  459. localPath := repo.LocalCopyPath()
  460. dirPath := path.Join(localPath, opts.TreePath)
  461. if err = os.MkdirAll(dirPath, os.ModePerm); err != nil {
  462. return err
  463. }
  464. // Copy uploaded files into repository
  465. for _, upload := range uploads {
  466. tmpPath := upload.LocalPath()
  467. if !osutil.IsFile(tmpPath) {
  468. continue
  469. }
  470. // 🚨 SECURITY: Prevent path traversal.
  471. upload.Name = pathutil.Clean(upload.Name)
  472. // 🚨 SECURITY: Prevent uploading files into the ".git" directory.
  473. if isRepositoryGitPath(upload.Name) {
  474. continue
  475. }
  476. targetPath := path.Join(dirPath, upload.Name)
  477. if err = com.Copy(tmpPath, targetPath); err != nil {
  478. return fmt.Errorf("copy: %v", err)
  479. }
  480. }
  481. if err = git.Add(localPath, git.AddOptions{All: true}); err != nil {
  482. return fmt.Errorf("git add --all: %v", err)
  483. }
  484. err = git.CreateCommit(
  485. localPath,
  486. &git.Signature{
  487. Name: doer.DisplayName(),
  488. Email: doer.Email,
  489. When: time.Now(),
  490. },
  491. opts.Message,
  492. )
  493. if err != nil {
  494. return fmt.Errorf("commit changes on %q: %v", localPath, err)
  495. }
  496. err = git.Push(localPath, "origin", opts.NewBranch,
  497. git.PushOptions{
  498. CommandOptions: git.CommandOptions{
  499. Envs: ComposeHookEnvs(ComposeHookEnvsOptions{
  500. AuthUser: doer,
  501. OwnerName: repo.MustOwner().Name,
  502. OwnerSalt: repo.MustOwner().Salt,
  503. RepoID: repo.ID,
  504. RepoName: repo.Name,
  505. RepoPath: repo.RepoPath(),
  506. }),
  507. },
  508. },
  509. )
  510. if err != nil {
  511. return fmt.Errorf("git push origin %s: %v", opts.NewBranch, err)
  512. }
  513. return DeleteUploads(uploads...)
  514. }