<commit_before>// Copyright (c) 2014, Google Inc. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

library git.commands.fetch;

import 'dart:async';
import 'dart:typed_data';

import 'package:chrome/chrome_app.dart' as chrome;

import '../constants.dart';
import '../exception.dart';
import '../fast_sha.dart';
import '../file_operations.dart';
import '../http_fetcher.dart';
import '../object.dart';
import '../objectstore.dart';
import '../options.dart';
import '../pack.dart';
import '../pack_index.dart';
import '../upload_pack_parser.dart';
import '../utils.dart';
import 'status.dart';

/**
 * A git fetch command implementation.
 *
 * TODO(grv): Add unittests.
*/

class Fetch {

  GitOptions options;
  chrome.DirectoryEntry root;
  ObjectStore store;
  Function progress;
  String branchName;

  Fetch(this.options) {
    root = options.root;
    store = options.store;
    progress = options.progressCallback;
    branchName = options.branchName == null ? 'master' : options.branchName;

    if (progress == null) progress = nopFunction;
  }

   Future fetch() {
    String username = options.username;
    String password = options.password;

    Function fetchProgress;
    // TODO(grv): Add fetchProgress chunker.

    return Status.isWorkingTreeClean(store).then((_) {
      String url = store.config.url;

      HttpFetcher fetcher = new HttpFetcher(
          store, 'origin', url, username, password);

      // get current branch.
      String headRefName = 'refs/heads/' + branchName;
      return fetcher.fetchUploadRefs().then((List<GitRef> refs) {
        GitRef branchRef = refs.firstWhere(
            (GitRef ref) => ref.name == headRefName);

        if (branchRef == null) {<commit_msg>Fix fetch when remote branch doesn't exist.<commit_after>// Copyright (c) 2014, Google Inc. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

library git.commands.fetch;

import 'dart:async';
import 'dart:typed_data';

import 'package:chrome/chrome_app.dart' as chrome;

import '../constants.dart';
import '../exception.dart';
import '../fast_sha.dart';
import '../file_operations.dart';
import '../http_fetcher.dart';
import '../object.dart';
import '../objectstore.dart';
import '../options.dart';
import '../pack.dart';
import '../pack_index.dart';
import '../upload_pack_parser.dart';
import '../utils.dart';
import 'status.dart';

/**
 * A git fetch command implementation.
 *
 * TODO(grv): Add unittests.
*/

class Fetch {

  GitOptions options;
  chrome.DirectoryEntry root;
  ObjectStore store;
  Function progress;
  String branchName;

  Fetch(this.options) {
    root = options.root;
    store = options.store;
    progress = options.progressCallback;
    branchName = options.branchName == null ? 'master' : options.branchName;

    if (progress == null) progress = nopFunction;
  }

   Future fetch() {
    String username = options.username;
    String password = options.password;

    Function fetchProgress;
    // TODO(grv): Add fetchProgress chunker.

    return Status.isWorkingTreeClean(store).then((_) {
      String url = store.config.url;

      HttpFetcher fetcher = new HttpFetcher(
          store, 'origin', url, username, password);

      // get current branch.
      String headRefName = 'refs/heads/' + branchName;
      return fetcher.fetchUploadRefs().then((List<GitRef> refs) {
        GitRef branchRef = refs.firstWhere(
            (GitRef ref) => ref.name == headRefName, orElse: () => null);

        if (branchRef == null) {
{'fraction_non_alphanumeric': 0.13523706896551724, 'fraction_numerical': 0.0021551724137931034, 'mean_word_length': 3.2974537037037037, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6521734', 'n_tokens_mistral': 1137, 'n_tokens_neox': 1100, 'n_words': 320}