Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Download zipped branch without root directory in archive

Vladimir Orlov
Contributor
January 2, 2019

Hello.

 

I'm writing a CMake script for repo downloading and building. I've managed to download zip from bitbucket and unpack it, but now I'm facing a huge inconvenience.

 

Say, my zip url is: "https://bitbucket.org/user/repo/get/branch.zip"

But it is downloaded not as branch.zip, but as user-repo-e2b82ab68a7a.zip

I still can set destination filename to something universal like "repo.zip" so it is not very bad.

 

The real problem is that I need to unpack this archive and obtain a snapshot of my branch, but it is not in a zip root but in a directory with the same unpredictable "user-repo-e2b82ab68a7a" name. So trivial unpacking turns into obtaining a name of the root directory, then moving all unpacked files from it to its parent directory and finally deleting empty root dir.

 

May be you could add some http switch like https://bitbucket.org/user/repo/get/branch.zip?root=0 to pack a repository directly into zip without autogenerated root, or at least make this root name completely predictable so we need no scanning unpacked content / somehow detecting zip name as it comes from server?

 

If I'm missing some good approach to do what I want, please point me on it. Thanks in advance.

1 answer

0 votes
Stephen Sifers
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 7, 2019

Hello Vladimir and welcome to the Community!

You exact issue for the filename was referred and answered within a Bitbucket enhancement request. You may find that request at #3486.

In regards to you missing the folders needed is it seems you're downloading the repo instead of cloning the repo. Please note the different between the two:

Cloning a repository copies the source files of a remote repository to your local machine, as well as the repository's Git history (branches, commits, tags, etc.). Cloning also creates a remote connection (usually called origin) pointing back to the cloned repository. You can only clone into a local directory that is a properly initialized Git repository (using the git initcommand).

Downloading a repository archive only copies a repository's source files from a specific point in time, depending on what was chosen to be copied. The biggest difference to downloading an archive is that you are not copying the repository history, or creating a connection to the remote repository. You are only getting the source files, and none of the Git metadata stored in the .git directory.

Source document: Download an archive from Bitbucket Server

There may be a good reason as to why you’re completing a download instead of a clone. If you do have a use case as to why  you need to download instead, please let us know and we will assist to help suit your needs.

I hope this helps to give some clarifications for the file names along with cloning a repo instead of downloading.

Regards,
Stephen Sifers

Vladimir Orlov
Contributor
January 8, 2019

Hello Stephen and thanks for a detailed answer.

 

Definitely I understand the difference between cloning and downloading. I have a mercurial repository which is a fork of third party mercurial repository. It contains dependencies for a git project. What I want is to download these dependencies to user machine and build them without forcing my user to install mercurial client or messing with submodules. Just run small script which downloads zip, unpacks and builds via CMake, and you are all set.

 

Now it works but involves a very fragile part of handling extra folder with unknown name after unzipping. What is described in the last comment at issue 3486 is exactly what I want: a possibility to unzip downloaded repo and get exactly a repo content in the destination directory.

Like Stephen Sifers likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events