--- Begin Message ---
Package: git-buildpackage
Version: 0.6.31
Severity: normal
Tags: patch
Hello,
After reading the documentation in
file:///usr/share/doc/git-buildpackage/manual-html/gbp.import.html#GBP.IMPORT.CONVERT,
I've been trying to work out why it's necessary to create orphaned branches
with an empty commit, in order to import into an existing git repository,
when no empty commit is necessary in order to import into a newly initialised
repository.
In doing so, I chanced upon this bug. If you create a new orphaned branch
and empty its contents without performing a commit, gbp-import-orig will
allow you to import into the existing repository, since it considers it to
be empty. The side effect is that it clobbers your existing master branch.
See the attached typescript.txt file. gbp-import-orig should prevent this
from occurring, and I've attached a patch which fixes this.
Anyway, couldn't this 'feature' be exploited to implement an easy way of
importing into existing repositories?
Carlos
-- System Information:
Debian Release: stretch/sid
APT prefers unstable
APT policy: (990, 'unstable'), (500, 'testing'), (1, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386
Kernel: Linux 4.0.0-2-amd64 (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)
Versions of packages git-buildpackage depends on:
ii devscripts 2.15.5
ii git 1:2.1.4-2.1
ii man-db 2.7.0.2-5
ii python 2.7.9-1
ii python-dateutil 2.2-2
ii python-pkg-resources 17.0-1
ii python-six 1.9.0-3
Versions of packages git-buildpackage recommends:
ii cowbuilder 0.73
ii pristine-tar 1.33
ii python-requests 2.7.0-3
Versions of packages git-buildpackage suggests:
ii python-notify 0.1.1-4
ii unzip 6.0-17
-- no debconf information
Script started on Sun 05 Jul 2015 19:58:01 AEST
carlos@devnull:/tmp$ mkdir mytest
carlos@devnull:/tmp$ cd mytest
carlos@devnull:/tmp/mytest$ git init
Initialized empty Git repository in /tmp/mytest/.git/
carlos@devnull:/tmp/mytest$ git status
On branch master
Initial commit
nothing to commit (create/copy files and use "git add" to track)
carlos@devnull:/tmp/mytest$ touch foo
carlos@devnull:/tmp/mytest$ git add foo
carlos@devnull:/tmp/mytest$ git commit -m "Added foo"
[master (root-commit) d86664f] Added foo
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 foo
carlos@devnull:/tmp/mytest$ git log
commit d86664f4b55c717bf49ee2f913adba1085474fc3
Author: Carlos Maddela <[email protected]>
Date: Sun Jul 5 19:58:37 2015 +1000
Added foo
carlos@devnull:/tmp/mytest$ git checkout --orphan newbranch
Switched to a new branch 'newbranch'
carlos@devnull:/tmp/mytest$ git rm -rf .
rm 'foo'
carlos@devnull:/tmp/mytest$ git status
On branch newbranch
Initial commit
nothing to commit (create/copy files and use "git add" to track)
carlos@devnull:/tmp/mytest$ gbp import-orig --verbose --debian-branch=unstable
--upstream-branch=upstream/unstable --pristine-tar /tmp/gvfs_1.24.1.orig.tar.xz
gbp:debug: ['git', 'rev-parse', '--show-cdup']
gbp:debug: ['git', 'rev-parse', '--is-bare-repository']
gbp:debug: ['git', 'symbolic-ref', 'HEAD']
gbp:debug: ['git', 'show-ref', 'refs/heads/newbranch']
gbp:debug: ['git', 'show-ref', 'refs/heads/upstream/unstable']
gbp:debug: ['git', 'rev-parse', '--quiet', '--verify',
'unstable:debian/changelog']
What will be the source package name? [gvfs]
What is the upstream version? [1.24.1]
gbp:debug: ['git', 'status', '--porcelain']
gbp:debug: tar ['-C', '../tmpnY2lzI', '-a', '-xf',
'/tmp/gvfs_1.24.1.orig.tar.xz'] []
gbp:debug: Unpacked '/tmp/gvfs_1.24.1.orig.tar.xz' to '../tmpnY2lzI/gvfs-1.24.1'
gbp:info: Importing '/tmp/gvfs_1.24.1.orig.tar.xz' to branch 'master'...
gbp:info: Source package is gvfs
gbp:info: Upstream version is 1.24.1
gbp:debug: ['git', 'add', '-f', '.']
gbp:debug: ['git', 'write-tree']
gbp:debug: ['git', 'commit-tree', '608e1962113d450925143062397d04263d10ecdc']
gbp:debug: ['git', 'update-ref', 'refs/heads/master',
'cf7c32e204b82083830969bacc0838098ad94c46']
gbp:debug: /usr/bin/pristine-tar [] ['commit', '/tmp/gvfs_1.24.1.orig.tar.xz',
'master']
gbp:debug: ['git', 'tag', '-m', 'Upstream version 1.24.1', 'upstream/1.24.1',
'cf7c32e204b82083830969bacc0838098ad94c46']
gbp:debug: ['git', 'branch', 'upstream/unstable',
'cf7c32e204b82083830969bacc0838098ad94c46']
gbp:debug: ['git', 'rev-parse', '--quiet', '--verify', 'upstream/unstable']
gbp:debug: ['git', 'reset', '--quiet', '--hard',
'cf7c32e204b82083830969bacc0838098ad94c46', '--']
gbp:debug: ['git', 'symbolic-ref', 'HEAD']
gbp:debug: ['git', 'show-ref', 'refs/heads/newbranch']
gbp:debug: rm ['-rf', '../tmpnY2lzI'] []
gbp:info: Successfully imported version 1.24.1 of /tmp/gvfs_1.24.1.orig.tar.xz
carlos@devnull:/tmp/mytest$ git branch
master
* newbranch
pristine-tar
upstream/unstable
carlos@devnull:/tmp/mytest$ git status
On branch newbranch
nothing to commit, working directory clean
carlos@devnull:/tmp/mytest$ git log master
commit cf7c32e204b82083830969bacc0838098ad94c46
Author: Carlos Maddela <[email protected]>
Date: Sun Jul 5 19:59:12 2015 +1000
Imported Upstream version 1.24.1
carlos@devnull:/tmp/mytest$ git reflog
cf7c32e HEAD@{0}: reset: moving to cf7c32e204b82083830969bacc0838098ad94c46
carlos@devnull:/tmp/mytest$ git reflog --all
60bfce7 refs/heads/pristine-tar@{0}:
cf7c32e refs/heads/master@{0}:
d86664f refs/heads/master@{1}: commit (initial): Added foo
carlos@devnull:/tmp/mytest$ exit
exit
Script done on Sun 05 Jul 2015 20:01:37 AEST
>From 9ee158818cfe3447e1a74415e6be0daa92ff21ce Mon Sep 17 00:00:00 2001
From: Carlos Maddela <[email protected]>
Date: Sun, 5 Jul 2015 03:45:13 +1000
Subject: [PATCH] Improved test for empty repo to prevent clobbering 'master'
branch.
---
gbp/scripts/import_orig.py | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/gbp/scripts/import_orig.py b/gbp/scripts/import_orig.py
index 3bafd41..a7493ad 100644
--- a/gbp/scripts/import_orig.py
+++ b/gbp/scripts/import_orig.py
@@ -306,9 +306,8 @@ def main(argv):
except GitRepositoryError:
raise GbpError("%s is not a git repository" % (os.path.abspath('.')))
- # an empty repo has now branches:
- initial_branch = repo.get_branch()
- is_empty = False if initial_branch else True
+ # an empty repo has no branches:
+ is_empty = (len(repo.get_local_branches()) == 0)
if not repo.has_branch(options.upstream_branch) and not is_empty:
raise GbpError(no_upstream_branch_msg % options.upstream_branch)
--
2.1.4
--- End Message ---