0

Our organisation is migrating from BitBucket to GitHub. We need to perform post-migration validation. Can someone please help with git commands for below:

  1. Get count of commits per repository. I have already tried below ones but they are not giving correct output:

    git rev-list --count [revision]
    
    git rev-list --all --count
    
  2. Get count of open/merged/declined/ total PRs per repository.

  3. Get count of number of lines in a git repository. (Tried this SO accepted answer but it's not giving correct output in my case https://stackoverflow.com/questions/4822471/count-number-of-lines-in-a-git-repository#:~:text=Blank%20lines%20are%20counted.&text=This%20searches%20all%20files%20versioned,the%20total%20number%20of%20lines!&text=this%20works%20if%20you%20count,as%20the%20files%20of%20interest.)

Rahul
  • 637
  • 5
  • 16
  • 4
    Why do you distrust the output of `git rev-list --all --count`? ("they're not giving *correct* output") – Romain Valeri Apr 27 '21 at 07:46
  • 3
    Keep in mind that open/merged/declined/total PRs are **not** a property of the git repository itself. So whatever tool you use to migrate stuff needs to use BitBucket- and GitHub-specific APIs to transfer those. – Joachim Sauer Apr 27 '21 at 07:48
  • 1
    doubling up on comment : can you explain what makes you say that `git rev-list --count` doesn't give the correct output ? more precisely : can you give more details on what actions you took (running it on your local working repository / on a fresh clone / on a colleague's clone / ... ) and what you expect (it looks like you expect to see a known number : is it a number that is displayed in bitbucket ? github ? your local repo ? ) – LeGEC Apr 27 '21 at 07:55
  • 1
    @RomainValeri I created a new repo to test the command. I created 3-4 branches and did few commits in each branch. I merged some PRs as well. I counted the commits for this repo manually and compared with the command output, it didn't match. – Rahul Apr 27 '21 at 08:05
  • Can you show such a concrete example? I mean the commands you executed to create the sample repository as well as the output of those commands, the output of the count command, how/what you counted, what you expected, and what you got? Just saying "didn't get the expected output" doesn't tell us what you expected, why you expected it, what you got, and how it differs. For all we know it's your expectation that is wrong, and we'd like to help you figure out what the discrepancy is and why it is there. – Lasse V. Karlsen Apr 27 '21 at 08:10
  • 3
    Additionally, try to write just 1 question in one post here. This question: "Get count of number of lines in a git repository" might be completely handled by "Get count of lines in files in a folder", but it depends on whether you think it might be different for a git repository, but it will warrant a completely set of answers and comments compared to counting commits. – Lasse V. Karlsen Apr 27 '21 at 08:13
  • @Lasse V. Karlsen I couldn't share further details as the newly created repo is internal to my organisation. I will try to create a public repo and share the issue details. – Rahul Apr 27 '21 at 08:45

1 Answers1

1

Rather than figuring out the commits count between two clones, you will be better off writing a script that compares branches and commit hashes.

You can run :

git ls-remote [url to any git repo]

to get a list of branches and references from a remote repository, and the current hash for each reference.

So you can run :

git ls-remote [url of bitbucket repo] > bitbucket.txt
git ls-remote [url of github repo] > github.txt

and compare these two files, to see if all the commits you expect have been moved from one repo to the other.

As noted in the comment : data like "Issues" or "Merge Requests" are not stored in the git repo directly, and must be checked using some other tools -- probably tools that rely on github and bitbucket APIs to get that data.

LeGEC
  • 46,477
  • 5
  • 57
  • 104